HTTP_REFERER

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

HTTP_REFERER

Post 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? :?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post 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
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post 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!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

<?php 
if(!strpos("domain.com", $_SERVER&#1111;'HTTP_REFERER'])) &#123;  
        die('error')
      &#125;
?>
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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;
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post by codewarrior »

ok a dumb question, how would I make it work with arrays? :lol:
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

use foreach(), or in_array()
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post by codewarrior »

Ok thanks a million! Lets see what happens. If it works will share the code ;)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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;
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post by codewarrior »

:lol: Thanks again! :wink: wish I could do that ... one day! :oops:
Post Reply