Page 1 of 1

HTTP_REFERER

Posted: Sat Sep 14, 2002 4:09 pm
by codewarrior
I was looking @ PHP Manual but can't seem to find HTTP_REFERER. Did google search still nothing, any other manuals out there? :?

Posted: Sat Sep 14, 2002 4:12 pm
by hob_goblin
didnt look hard enough


http://www.php.net/manual/en/print/rese ... iables.php

'REMOTE_ADDR'
The IP address from which the user is viewing the current page.

Posted: Sat Sep 14, 2002 4:12 pm
by codewarrior
Found it!!

'HTTP_REFERER'
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Any other sites with a bit more details? :D

Posted: Sat Sep 14, 2002 4:13 pm
by codewarrior
hob_goblin wrote:didnt look hard enough


http://www.php.net/manual/en/print/rese ... iables.php

'REMOTE_ADDR'
The IP address from which the user is viewing the current page.
:lol: Thanks!

Posted: Sat Sep 14, 2002 4:14 pm
by hob_goblin
What exactly are you trying to do?

Yes, I would trust it for statistical things, but I wouldnt make it critical to the page loading.

it just returns the URL that linked to the page, (even if it was from the same site)

Posted: Sat Sep 14, 2002 4:16 pm
by hob_goblin
Bah, sorry for putting up remote_addr, i was having a brainfart from the other topic about remote_addr... but http referer is in there as well

Posted: Sat Sep 14, 2002 4:17 pm
by codewarrior
Trying to do this :D

It works fine with:

Code: Select all

<?php
if(!eregi("domain.com",$refr)) { 
        error 
      } else { 
        pass 
      }
?>
But having prob making the above work with arrays.

Posted: Sat Sep 14, 2002 4:22 pm
by hob_goblin

Code: Select all

<?php 
if(!strpos("domain.com", $_SERVER&#1111;'HTTP_REFERER'])) &#123;  
        die('error')
      &#125;
?>

Posted: Sat Sep 14, 2002 4:25 pm
by hob_goblin
well, here is how I do it:

Code: Select all

$block = array('bar.com', 'foo.com');
$ref = $_SERVER&#1111;'HTTP_REFERER'];
$ref = str_replace('http://www.', '', $ref);
$ref = str_replace('http://', '', $ref);
$ref = explode('/', $ref);
$ref = $ref&#1111;0];
function checkblock($block_array, $url)&#123;
foreach($block_array as $key)&#123;
 if($key == $url)
  return TRUE;
&#125;
&#125;
if(!checkblock($block, $ref))&#123;
echo 'they passed';
&#125;

Posted: Sat Sep 14, 2002 4:25 pm
by codewarrior
ok a dumb question, how would I make it work with arrays? :lol:

Posted: Sat Sep 14, 2002 4:26 pm
by hob_goblin
use foreach(), or in_array()

Posted: Sat Sep 14, 2002 4:31 pm
by codewarrior
Ok thanks a million! Lets see what happens. If it works will share the code ;)

Posted: Sat Sep 14, 2002 4:36 pm
by hob_goblin

Code: Select all

function check($array, $url)&#123;
  foreach($array as $val)&#123;
  if(!eregi($url, $val))&#123;
  return FALSE;
  &#125; else &#123;
  return TRUE;
  &#125;
&#125;
$urls = array("foo.com", "bar.com"); // ALLOWED SITES
if(!check($urls, $_SERVER&#1111;'HTTP_REFERER']))&#123;
echo 'you're not from my site';
&#125; else &#123;
echo 'heres what you want';
&#125;

Posted: Sat Sep 14, 2002 4:38 pm
by codewarrior
:lol: Thanks again! :wink: wish I could do that ... one day! :oops: