Page 1 of 1

finding out where the user came from

Posted: Thu Aug 28, 2003 8:17 am
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

Posted: Thu Aug 28, 2003 8:36 am
by phice
$_SERVER['REMOTE_ADDR'];

Posted: Thu Aug 28, 2003 8:41 am
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

Posted: Thu Aug 28, 2003 10:55 am
by volka
but keep in mind that the referer's value is coutesy of the client. It can send any bogus address it likes

Posted: Fri Aug 29, 2003 2:42 am
by Vantuykom
this is indeed what I ment, but it doesn't work :-(

Posted: Fri Aug 29, 2003 5:27 am
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]

Posted: Fri Aug 29, 2003 6:11 am
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