Domain Manage

Using include with certain domains

Discussion in 'Mini Sites' started by SecNam, Jul 19, 2013.

Thread Status:
Not open for further replies.
  1. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    Hi, Just wondering if anyone can help. I am using 1 index.php file that has all domains parked on it, i am also using the following code to show what domain name is in the browser header
    <?
    $domainstart = $_SERVER['HTTP_HOST'];
    $domainname = str_replace("www.", "", "$domainstart");
    ?>

    then in the index.php file i have <? echo "$domainname"; ?> where the domain name is shown.

    What i am trying to do is if a certain domain name is shown then it also displays an include file, for example is domainname.co.uk is in the browser address bar i can also include the file contents from a file called domainname.php.

    Is this possible and if so any ideas how to achieve this.

    Thanks in advance.
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
     
  3. Retired_member41

    Retired_member41 Retired Member

    Joined:
    Mar 2010
    Posts:
    3,443
    Likes Received:
    55
    As you know I'm not even a beginner, but can't you just put in another include, but with the echo in it.

    Eg <?php include("your php echo code"); ?>

    Is an echo allowed within, only wrote it as it sounded the simplest :)
     
  4. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    I used something like

    Code:
    	
    $dom = explode('.',substr($_SERVER['HTTP_HOST'], strpos($_SERVER['HTTP_HOST'], '.')+1));
    	include("./" . $dom[0] . ".inc.php");
    
    You should really clean sanitize the server var just to form a habit, but that should work.
     
  5. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    Thank skinner but if the .inc.php file does not exist it shows errors so would need code to work if inc.php exists then show it, if it does not exist then dont show any errors.
     
  6. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    also what do yo mean clean sanitize the server var just to form a habit,? (sorry if sounds a stupid question)
     
  7. Edwin

    Edwin Well-Known Member Exclusive Member

    Joined:
    Apr 2005
    Posts:
    8,460
    Likes Received:
    261
  8. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
  9. AssetDomains United Kingdom

    AssetDomains Well-Known Member

    Joined:
    Feb 2010
    Posts:
    2,951
    Likes Received:
    52
    Pass it through something like this I think to stop injection I think this works

    Code:
    function check_input($data)
    {
        $data = htmlspecialchars($data);
        return $data;
    }
    $dom = check_input(explode('.',substr($_SERVER['HTTP_HOST'], strpos($_SERVER['HTTP_HOST'], '.')+1)));
    
    
     
  10. AssetDomains United Kingdom

    AssetDomains Well-Known Member

    Joined:
    Feb 2010
    Posts:
    2,951
    Likes Received:
    52
    Actually might have to do something like this

    Code:
    function check_input($data)
    {
        $data = htmlspecialchars($data);
        return $data;
    }
    //Get Page URL
    function curPageURL() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return check_input($pageURL);
    }
    dom = curPageURL()
    
     
  11. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    I was a lil bored while waiting for a data migration so worked this lil script out, I've kept it simple and added a bunch of comments, so its should be easy to follow.




    Code:
    <?php 
    function domain($url){
          $obj=parse_url($url); //parse the url.
          $domain=$obj['path']; // extract just the url not subdirs/dirs/files
          if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $reg)) { //test it conforms to common known structure of names.
    		$dom = explode('.',$reg['domain']); // explode it to cut off sld/tld
    		return $dom[0]; //return only domain name,
          }
          return false;
    }
    
    $path = domain($_SERVER['HTTP_HOST']) . ".inc.php"; // take host name and create filename.
    //echo $path; //show file name for debug
    if(file_exists($path)){ // test if filename exists.
    	include("$path"); //yay it does, show it.
    }else{ // rut ro not found.
    	include("./default.inc.php"); //show this instead.
    }
    ?>
     
  12. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    Thank you stephen, really appreciate you taking the time.
     
  13. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    No probs, If you need any tweaks let me know, if you don't wanna include a default, just comment that line out.
     
  14. julian United Kingdom

    julian Banned

    Joined:
    Aug 2007
    Posts:
    2,271
    Likes Received:
    42
    sorry to hijack the thread a tad, off the top of your head, do you know how asp (vbscript/IIS) compares to php on apache for handling super high traffic.

    just popped into my head..

     
  15. Edwin

    Edwin Well-Known Member Exclusive Member

    Joined:
    Apr 2005
    Posts:
    8,460
    Likes Received:
    261
    For super-high traffic, surely you want to use something like nginx rather than Apache?
     
  16. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    IIS is pointless it buckles under very heavy load unless its majorly optimised with near unlimited resources but even then it buckles under stress I'm sure there are ways to solve it but my experience is IIS can't hack it.

    I'm all about litespeed at the moment, but def down to nginx for a free option or litespeed free or paid, if I had dollar in my pocket I'd go litespeed otherwise nginx.

    I've not seen anyone using hiphop on litespeed or nginx but I'd imagine well formed mysql with caching, nginx/litespeed with hiphop would be a pretty mean config for super heavy loads.
     
  17. julian United Kingdom

    julian Banned

    Joined:
    Aug 2007
    Posts:
    2,271
    Likes Received:
    42
    presumably IIS 7+ running .NET would be better - what about all these corp monsters tied up with using MS products. IIS can't be that bad.. can it? :eek:
     
  18. Edwin

    Edwin Well-Known Member Exclusive Member

    Joined:
    Apr 2005
    Posts:
    8,460
    Likes Received:
    261
  19. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    Its like facebook developing hiphop to enable php to run fast enough to handle it. You dont know what these monsters have developed in iis.

    They also could be running a cluster of servers behind load balancers with a bunch of custom extensions / componants, and just keep adding more and more servers to power it.

    im sure with enough money and skill you could do anything.


     
Thread Status:
Not open for further replies.

Share This Page