browser.history and log file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am very beginner with PHP. I have an Apache PHP enabled
webserver and want to know from where users are coming from.
Understand I want the last surfer's browser visited url.
I imagine I can do this with some kind of interraction
between 2 scripts : one client side, one server side.
The client one send the URL and the server one write it
in the right log file.
I have no idea of how to do this nor with principle nor
with syntax ...
Can somebody help with a few lines *working* example?
Any idea appreciated!

Re: browser.history and log file

Quoted text here. Click to load it

First you need to set up a little JavaScript to get the variable of the URL
you're looking for (my JavaScript is a little rusty so I can't tell you the
exact code to get it). Suppose you name the variable "url". So put this
script in some page that the visitor will see:

<script language="javascript">
url    =    (however you get the URL);
document.write( "<img src='log.php?url=" + url + "' width='1'
height='1'>" );

Then in log.php, use $_GET['url'] to access the URL and insert it into a
database (or whatever you wanted to do with it).

- JP

Re: browser.history and log file

Quoted text here. Click to load it

2 solution without javascript

(1) you can use $_SERVER['HTTP_REFERER']. that contains the previous
url. note that not all browser sent this and that some browsers allow
the user to fake it.

(2) use a session in each of your pages to first read the previous url
and then store the present url (which then becomes the previous url on
the next page). this works obviuosly only if you want to monitor
movement inside your site).

you could also combine the 2 solution, i.e. use session if a previous
url in the session is set and $_SERVER['HTTP_REFERER'] as fallback.


Site Timeline