Solved

getting referring page

Posted on 2002-06-01
4
384 Views
Last Modified: 2012-06-27
This isn't REALLY a Perl question.  More of a 'script-calling' question.  I wrote a perl script that gets the $ENV{'HTTP_REFERER'} of the referring page and writes it to a database.  It's to keep track of where my visitors are coming from.  It works fine and dandy as I have written it.  Now the problem is that I'm not sure how to call my script from my web page.  I tried to put it in a cheezie tag like so: <img src="/cgi-bin/track.pl" width=0 height=0 border=0>.

The problem is that the script uses the page (my page) that the <img...> tag is on as the referer and not the page that the user came from in the first place.

To clarify:
Let's say my page is http://mysite.com/mypage.html  and the user comes from http://xyzsite.com/theirpage.html.  The referer variable in my script that I call from mypage.html should contain the string 'http://xyzsite.com/theirpage.html'.  How can I call my script from mypage.html so that it tricks my script into considering xyzsite.com's page as the referring page??
0
Comment
Question by:GorGor1
4 Comments
 
LVL 7

Accepted Solution

by:
yoren earned 50 total points
ID: 7049338
You can't do that directly. I'd suggest making mypage.html a dynamic page (CGI, etc.). You can then set a cookie (or dynamically add a CGI script parameter) equal to the referring site. Your script can then reference the cookie or CGI parameter instead of HTTP_REFERRER.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 7065414
I partially aggree with the previos and differ too.  I would avoid the cookie if you can.

When I have needed to do this or other things, such as show different pages depending on the browser being used, what I have done is ensured that there is no page:

http://www.mySite.com/myPage.html

Then I have created an error404 script that will be invoked when any non-found happens.  In this page I check and see if the requested page was myPage.html.  If it was, then I do the logging, or whatever else and then transmit the page, which us now stored as something like myPage.html.x.
0
 

Expert Comment

by:rrbf
ID: 7069993
Your solution isn't that 'cheezie'. many do use it.
The more classical solution is to setup .html
as an SSI (server side include) to include the script with an <!--#include ... -->
if html extensions are not SSI enabled and you want to stick
to a .html rather than a .cgi or .pl or .shtml
you can do that in .htaccess with this line:
AddHandler server-parsed .shtml .html

check http://httpd.apache.org/docs/mod/mod_include.html
ssi are installed and enabled by default in most apache installs.
0
 
LVL 1

Author Comment

by:GorGor1
ID: 7070145
I can't use .htaccess because I'm not using apache.  I'm using IIS in win2k.  I found a solution and I'm working with it now.  I'll post the solution and accept an answer when I'm done.  Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question