www.webdeveloper.com
Results 1 to 5 of 5

Thread: Lock script to the domain

  1. #1
    Join Date
    Oct 2012
    Posts
    2

    Lock script to the domain

    I put this piece of code: if ( $_SERVER['HTTP_HOST'] != "ilmiodominio.com" ){ die(); } , I wanted to ask how can I add more than one domain, type: ilmiodominio.com and www.ilmiodominio.com, thank you.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,432
    I might just do something like this if you want to allow any sub-domain:
    PHP Code:
    if( ! preg_match('/(^|\.)ilmiodominio\.com$/i'$_SERVER['HTTP_HOST'])) { 
    If you want to restrict it to specific (or no) sub-domains:
    PHP Code:
    if( ! preg_match('/^((sub1|sub2|sub3|www)\.)?ilmiodominio\.com$/i'$_SERVER['HTTP_HOST'])) { 
    (Caveat, the above are untested, so typos are possible. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    alternatively:

    PHP Code:
    // set an array of allowed hosts.
    $allowed = array("ilmiodominio.com""www.ilmiodominio.com""www2.ilmiodominio.com""sub.ilmiodominio.com");

    // if the current host is not in the array, then kill it.
    if ( !in_array($_SERVER['HTTP_HOST'], $allowed) === TRUE ){ die(); } 

  4. #4
    Join Date
    Oct 2012
    Posts
    2
    ok thanks a lot, works great, thanks again for your courtesy and helpfulness. thank you again. hello, sorry for my English but I am Italian and I am using a translator. hello

  5. #5
    Join Date
    May 2014
    Posts
    1
    I used these codes to secure a page, but the code fails when the page is embedded as iframe in a third party website, can you help me.

    <?php
    $allowed = array("www.domain1.com", "www.domain2.com");
    if ( !in_array($_SERVER['HTTP_HOST'], $allowed) === TRUE ){ die(); }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles