finding out where the user came from

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
Vantuykom
Forum Newbie
Posts: 19
Joined: Fri Jul 04, 2003 6:22 am

finding out where the user came from

Post by Vantuykom »

hi, I want to find out if my users came from one particular url and keep that info (count the times somebody comes from that url) in a file or database.
can anyone tell me how I can do this in a simple way?

thanx
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

$_SERVER['REMOTE_ADDR'];
Image Image
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

mm......that would get the IP rather than the URL.

get the referrer by:

$_SERVER['HTTP_REFERER'];

then connect to mysql db, check if there's already the URL. if there is, then add a count to there. if not then insert a new row for that URL with the count 1.

i hope that's what you meant...

-Nay
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

but keep in mind that the referer's value is coutesy of the client. It can send any bogus address it likes
Vantuykom
Forum Newbie
Posts: 19
Joined: Fri Jul 04, 2003 6:22 am

Post by Vantuykom »

this is indeed what I ment, but it doesn't work :-(
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

this is indeed what I ment, but it doesn't work
When I was implementing something like this it drove me half mad because outputting $_SERVER['HTTP_REFERER']; always returned empty. Of course I was calling the page directly, thus no referer - stupid me. Maybe you fell into the same pit.[/quote]
Vantuykom
Forum Newbie
Posts: 19
Joined: Fri Jul 04, 2003 6:22 am

Post by Vantuykom »

I've tried it from a link too, but it doesn't work either.
now I've tried someting else: on my page I've put the following:
$_SESSION["address"]="<script language='JavaScript'>document.write(document.referrer);</script>";
when I do echo $_SESSION["address"], it shows me the right url let's say "http://host/file.htm", but when I want to compare the string "http://host/file.htm" with $_SESSION["address"], it allways says false. I really don't know what to do
Post Reply