php variable for domain detecting

Discussion in 'PHP' started by Nestrer, Jan 15, 2007.

  1. #1
    I heared that someone made a lot of domain all point(mask forward?) to one, then used a php predefined variable to detect the domain name and output based on it, so which php variable it is? Thanks!
     
    Nestrer, Jan 15, 2007 IP
  2. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    $_SERVER is an array where you will get all information

    user
    <?
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";

    ?>
     
    rays, Jan 15, 2007 IP
  3. West

    West Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    To be more specific it's $_SERVER['REQUEST_URI']
     
    West, Jan 15, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The domain shouldn't be in REQUEST_URI, it'd be HTTP_HOST.

    For the URL http://www.mydomain.com/mydir/page.php

    $_SERVER['HTTP_HOST'] contains www.mydomain.com
    $_SERVER['REQUEST_URI'] contains /mydir/page.html
     
    rodney88, Jan 16, 2007 IP
  5. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #5
    Actually I was trying to same thing.. well.. need the same thing..


    
    function getdomain()
    {
    $HTTP_HOST = $dom;
    
        if(eregi("somedomain",$dom)) $file = "header1.txt";
    include($file);
        if(eregi("otherdomain",$dom)) $file = "header2.txt";
    include($file);
    }
    
    Code (markup):
    this does not work.. what is wrong ?
     
    hasbehas, Jan 16, 2007 IP
  6. West

    West Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I stand corrected, good looking out. :)
     
    West, Jan 16, 2007 IP
  7. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Mainly it'd be because you have the $HTTP_HOST = $dom line the wrong way round. That tries to set $HTTP_HOST to the value of $dom, but there's no such variable as $dom.

    $dom = $_SERVER['HTTP_HOST'];

    You should really use $_SERVER['HTTP_HOST'] instead but you can get away without if you're using register globals on.
     
    rodney88, Jan 16, 2007 IP
  8. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #8
    Damn.. looking to it non-stop makes you blind..
    Thanks..

    final code is

    
    function getdomain()
    {
    $dom = $_SERVER['HTTP_HOST'];
    
        if(eregi("somedomain",$dom))
        {
            $file = "header1.txt";
    include ($file);
    _aheader();
    }
    
        if(eregi("otherdomain",$dom))
        {
             $file = "header2.txt";
    include ($file);
    _nheader();
    }
    }
    
    Code (markup):
     
    hasbehas, Jan 16, 2007 IP
  9. sukantab

    sukantab Well-Known Member

    Messages:
    2,075
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    110
    #9
    $_SERVER['HTTP_HOST'] variable will have the domain name.
    If you need you might remove the www part by str_replace.
     
    sukantab, Jan 16, 2007 IP
  10. Nestrer

    Nestrer Well-Known Member

    Messages:
    1,663
    Likes Received:
    103
    Best Answers:
    0
    Trophy Points:
    135
    #10
    So, it really work with mask forwarded domain?
     
    Nestrer, Jan 16, 2007 IP
  11. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Just use if(eregi("somedomain",$_SERVER['HTTP_HOST'])) for the love of God. Of course I can't blame you for something like this when you use eregi() for something that strpos() would be so much better suited for.
     
    Icheb, Jan 16, 2007 IP
  12. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #12
    Thanks.. stick to this for now..
    But in reality.. Would this actually work for spiders to think its some other domain, mask the parked domain ?
     
    hasbehas, Jan 18, 2007 IP
  13. Nestrer

    Nestrer Well-Known Member

    Messages:
    1,663
    Likes Received:
    103
    Best Answers:
    0
    Trophy Points:
    135
    #13
    I think it's no matter. as parked domain can also have PR, that's by backlink. so it should be index differently in search engine.
    But they may search whois database if PR is also counted on it
     
    Nestrer, Jan 18, 2007 IP
  14. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #14
    Thanks.. I have noticed changes as I have only applied this script to index page. So it works damn well..
     
    hasbehas, Jan 19, 2007 IP
  15. Nestrer

    Nestrer Well-Known Member

    Messages:
    1,663
    Likes Received:
    103
    Best Answers:
    0
    Trophy Points:
    135
    #15
    When apply to sub page, you have to do some extra work, as it should link with right domain url :)
     
    Nestrer, Jan 19, 2007 IP
  16. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #16
    Yeah.. thanks.. ;)
     
    hasbehas, Jan 27, 2007 IP