Page 1 of 1

logging referer information

Posted: Fri Feb 27, 2004 6:00 am
by phpnewbie1985
Im confused, im using META refresh to re-direct a site of mine at the moment and i would like to log the users that go to the redirection page (page A) in either a text file or a webpage. the problem is when i have tried to do this it never logs the place where the referer came from (page A) anyone have any ideas?

Many thanks

Chris

Posted: Fri Feb 27, 2004 6:01 am
by JayBird
have you got the code to see how you are trying to do it. Post it here so we can see what you are doing wrong.

Mark

code

Posted: Fri Feb 27, 2004 6:05 am
by phpnewbie1985
Page A (refering site)

Code: Select all

<HTML> 
<HEAD> 
<meta http-equiv="Content-Language" content="en-gb">
 
<META HTTP-EQUIV="refresh" content="1;URL=pageB.htm"> 
<TITLE>Loading...</TITLE> 
</HEAD> 
<BODY>

<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center"><font face="Arial">Loading...</font></p>
<p align="center"><font face="Arial">If the page does not load please
<a href="pageB.htm">click here</a>.</font></p>

</BODY> 
</HTML>
Page B (site it takes you too and meant to store info but only stores it if you click the link)

Code: Select all

<? 

$refer = $HTTP_REFERER; 


$newrefer = "$refer" . "\n"; 
$file_pointer = fopen("refer.txt", "a+"); 
fwrite($file_pointer, $newrefer); 
fclose($file_pointer); 

?>
Hope this helps?

Many thanks
Chris

Posted: Fri Feb 27, 2004 6:08 am
by JayBird
try changing

Code: Select all

$refer = $HTTP_REFERER;
to..

Code: Select all

$refer = $_SERVER["HTTP_REFERER"];
What version of PHP you running?

Mark

Posted: Fri Feb 27, 2004 6:12 am
by phpnewbie1985
nope, still only works if you click on it (really need it to log it on the refresh)... Im running PHP version 4.33

Chris

Posted: Fri Feb 27, 2004 6:17 am
by JayBird
how come the links are going to a HTML page and not a PHP page?

Mark

Posted: Fri Feb 27, 2004 6:18 am
by phpnewbie1985
ok sorry it was a php it goes to, but actually its just going to the domain.. http://www.domain.com/ but the index page is a php page. me being a muppet

Chris

Posted: Fri Feb 27, 2004 6:24 am
by JayBird
hmmmm...im sure i did this the other day nad it worked. I have just tried it on my machine and am getting the same problem.

Ill have to look pack at the scripts i did.

I'll be back

Mark

Posted: Fri Feb 27, 2004 6:26 am
by phpnewbie1985
Ok thanks arnie :wink:

im literally pulling my hair out, i have been trying to do it all morning!

Chris

Posted: Fri Feb 27, 2004 6:56 am
by JayBird
okay, looked at my code, it wasn't anything to do with this problem.

But..

I was just reading that The headers that are sent are dependent on browser and OS.

I have just tried your scirpt on a MAC running OS9 and Netscape 4.7 and it worked perfectly.

The only think i can think you can do is hard code the referer in the mete refresh tag like this

Code: Select all

<META HTTP-EQUIV="refresh" content="1;URL=pageB.htm?referer=pageA.htm">
If you could make pageA a PHP page, you cold generate the URL in the meta refresh

Mark

Posted: Fri Feb 27, 2004 7:05 am
by jigaruu
hey do one thing, just pass session variables also with it, hidden or open so that ur's session remains active and all the directed pages work.

Posted: Fri Feb 27, 2004 7:06 am
by phpnewbie1985
Thanks that worked! and in page B i had to change where it said

Code: Select all

$refer = $_SERVER&#1111;"HTTP_REFERER"];
to

Code: Select all

$refer = $referer;
many thanks for your help

chris