Help with redirect

Discussion in 'PHP' started by neiq, Dec 8, 2008.

  1. #1
    Hello i have this code from what i can see as long as the referrer is blank it will redirect however what i want is for it to also redirect if the referrer is from a certain domain. Not just a site but any link from an entire domain. Also how would i add multiple domains. Thanks


    <?php
    
    	$referer = $_SERVER['HTTP_REFERER'];
    	if($referer =="")
    	{
    
    		echo "<meta http-equiv=\"refresh\" content=\"0;url=http://www.adomain.com\">";
    
    	}
    
    ?>
    Code (markup):

     
    neiq, Dec 8, 2008 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    You can try this one :)

    <?php
    
    // Put the domains here
    $domains = array('yahoo.com', 'google.com', 'fbi.gov');
    
    $referer = $_SERVER['HTTP_REFERER'];
    
    // Loop for each domain
    foreach ($domains as $dom) {
    	if (stristr($referer, $dom)) {// match
    		exit("<meta http-equiv=\"refresh\" content=\"0;url=http://www.adomain.com\">");
    	};
    };
    
    ?>
    PHP:
     
    xrvel, Dec 8, 2008 IP
    neiq likes this.
  3. neiq

    neiq Peon

    Messages:
    464
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks man :D
     
    neiq, Dec 8, 2008 IP