logging referer information

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
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

logging referer information

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

code

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

how come the links are going to a HTML page and not a PHP page?

Mark
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

Post by phpnewbie1985 »

Ok thanks arnie :wink:

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

Chris
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
jigaruu
Forum Newbie
Posts: 21
Joined: Wed Feb 18, 2004 11:46 pm
Contact:

Post 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.
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

Post 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
Post Reply