lil php question..

Status
Not open for further replies.

stack paper

Dopesmoking Newbtrasher
Dec 20, 2007
1,870
23
0
DTLA
how tough would it be to do the following..
a php script that grabs the site visitors referrer, strips everything but the domain, and displays it?

(i know very, VERY little about php. just toying around with an idea.)

Thanks :O~
 


easy :

Code:
$fp = fopen("your/log/filename","r");
if (!$fp) exit;
while (!feof($fp)) {
      $line=fgets($fp);
      $fields=explode("\t", $line);
      echo $fields[8]; 
}
fclose($fp);
You need to add your correct log file path and filename and in the echo $fields[8]; statement select the correct index. (And maybe in the explode() function change the seperator. (now:"\t") )
 
Or you could start with $_SERVER['HTTP_REFERER'] in the current context, and strip off all of the junk around it.
 
Code:
if ( !empty($_SERVER['HTTP_REFERER']) ) {
    echo @parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST );
}
 
Status
Not open for further replies.