Forum Moderators: DixonJones

Message Too Old, No Replies

Get referer from user & then run be able to run script in a .html

And then add it to a .txt. file or something similar.

         

lazerzubb

3:59 pm on Aug 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need a script which can be run on any webserver that support .html and then get the referer from the user (where they came from, in asp it's HTTP_REFERER) and then add that info to some sort of file.

Is this possible, i got a tip that you can use Javascript to do this, how i don't know but he worried that you are not able to write the data in to a file with Javascript anyone have a solution?
The script should be able to run on any webserver which support .html files.

c3oc3o

4:17 pm on Aug 22, 2002 (gmt 0)

10+ Year Member



No, of course JS cannot write into files, it's a client-side scripting language (executed in the browser, not on the server) without any rights whatsoever on the server.
So what you want is impossible, except for remotely hosted services (where the actual logging parts reside on a different server and are called/included through an image or by JS).

bobriggs

4:30 pm on Aug 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you're looking for has been done by Fluid Dynamics:

[xav.com...]

It uses SSI includes to exec its script which logs referer, ip, etc in a log file. If you don't have SSI, you can also specify the cgi script call in an image tag - Doesn't work as well because of caching issues.

So basically you write a script that records and writes the info you want, and to an SSI include to that script at the top of each page.

toadhall

7:03 pm on Aug 22, 2002 (gmt 0)

10+ Year Member



If you'd like to write your own, here's how. (It's easier than you might think)

You'll need server side scripting to record the data, there's no getting away from this, but you can get away with using only one instance and consequently avoid turning all your .html pages into scripts.

This is a PHP solution so hopefully you have access to it at your host.

The PHP script would simply gather and record the contents of the environment variables you're interested in; preumably HTTP_REFERER, HTTP_USER_AGENT, REMOTE_ADDR.

You can get all the information you need to do this at php.net. Specific functions are:

fopen() - to open the log file
fwrite() - to write to it
fclose() - to close it
fread() or file() - to read the contents of the log file

Simply point your browser to www.php.net/functionname to access the online manual entry for each "functioname".

Adding this to the <body> of each .html page you wish to track...

<script language="javascript" src="http://www.yourdomain.com/path/to/script.php"> </script>

...willl run the remote script and record the data specific to the page on which the javascript appears.

TIP: Suppress error messages in the server side script by placing an @ symbol before each function call - like this @fopen()

Of course, if you can pick up a pre-written server side script to do the gathering and recording you're laughin'.

Good luck.

andreasfriedrich

7:09 pm on Aug 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why donīt you use the serverīs logfile?