Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTP_REFERER in html page

Status
Not open for further replies.

fortwilliam

Programmer
Mar 5, 2008
7
GB
Hi, I am trying to record what people are searching for before they come to the html pages on my site.

The following is the code I have tried on the html pages and then the main parts of the perl script. The perl script just takes the referrer value and if it is from google|bing|yahoo it then removes all but the search term and prints to a text file. I have also just printed the referred value to screen to see what is going on.

Trouble is all I get as the reffering page is the page the code is on. So, if I have the code on mysite.com/this-page.html, that is what I get as the reffering page in the javascript, image and iframe.

Thanks

<script language="JavaScript" type="text/javascript" src="\\\perl///script.pl"></script>

<img src="\\\perl///script.pl" border=0 height=0 width=0>

<iframe src ="\\\perl///script.pl"width="1" height="1">


\\\\\ part of perl script:-
&parse_form;

$ref=$ENV{'HTTP_REFERER'};

print"$ref";#added so I can see what is being reffered:: remove

if ($ref =~ /\.google\.|\.bing\.|\.yahoo\./i){
$ref =~ s/.*[\&|\?][q|p]=([\w*\+?(%20)? ?]*)/$1/;
$ref =~ s/\+|%20/ /g;

open (LOG, ">>\\my\\path\\seng.txt");
flock(LOG, 2);
print LOG "$ref\n";
flock(LOG, 8);
close (LOG);

}

 
Hi

This is not really a Perl-related issue. When requesting the embedded objects, some browsers will send the original referrer, others the page itself. The Perl script can do nothing against it.

What you could do, is to put somebody who knows the referrer to send it to the Perl script :
Code:
[b]<script[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/javascript"[/i][/green] [maroon]src[/maroon][teal]=[/teal][green][i]"whatever.js"[/i][/green][b]></script>[/b]
Code:
[b]new[/b] [COLOR=darkgoldenrod]Image[/color][teal]().[/teal]src[teal]=[/teal][green][i]'/whatever.pl?pageref='[/i][/green][teal]+[/teal][COLOR=darkgoldenrod]escape[/color][teal]([/teal]document[teal].[/teal]referrer[teal])+[/teal][green][i]'&'[/i][/green][teal]+[/teal][b]new[/b] [COLOR=darkgoldenrod]Date[/color][teal]().[/teal][COLOR=darkgoldenrod]getTime[/color][teal]()[/teal]
Code:
[navy]$ref[/navy][teal]=[/teal][navy]$cgi[/navy][teal]->[/teal][COLOR=darkgoldenrod]param[/color][teal]([/teal][green][i]'pageref'[/i][/green][teal]);[/teal]
By the way, if the referrer is logged by the web server, you can extract the information from the log files. Most log analyzers can do it. And not only for 3 search sites.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top