By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

Can't get HTTP_REFERER

P: 7
I can't seem to get the ENV variable HTTP_REFERER when posting with CGI from one program to another. In my post program I have put in the <HEAD>
Expand|Select|Wrap|Line Numbers
  1. HTTP_REFERER =my host
- ie www.xyz.com (I have also tried removing it entirely in case that was causing problems.

I have tried to extract the HTTP_REFERER in my receiving program with
Expand|Select|Wrap|Line Numbers
  1. $http_ref = $ENV{'HTTP_REFERER'};
That didn't work so I just printed all variables with

Expand|Select|Wrap|Line Numbers
  1. foreach $key (sort keys(%ENV)) {
  2.       print "$key = $ENV{$key}<p>"; }
What I get printed is (and I'll just copy the few before and after where I might have expected to see it:
HTTP_KEEP_ALIVE = 300

HTTP_USER_AGENT = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

HTTP________ = -------------------------------------------------------------------------------------

HTTP________________ = ------------

PATH = /usr/local/bin:/usr/bin:/bin

There was no HTTP_REFERER listed.

Thanks for any help I can get on this.
Jan 7 '08 #1
Share this Question
Share on Google+
6 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
I can't seem to get the ENV variable HTTP_REFERER when posting with CGI from one program to another. In my post program I have put in the <HEAD>
Expand|Select|Wrap|Line Numbers
  1. HTTP_REFERER =my host
- ie www.xyz.com (I have also tried removing it entirely in case that was causing problems.

I have tried to extract the HTTP_REFERER in my receiving program with
Expand|Select|Wrap|Line Numbers
  1. $http_ref = $ENV{'HTTP_REFERER'};
That didn't work so I just printed all variables with

Expand|Select|Wrap|Line Numbers
  1. foreach $key (sort keys(%ENV)) {
  2.       print "$key = $ENV{$key}<p>"; }
What I get printed is (and I'll just copy the few before and after where I might have expected to see it:
HTTP_KEEP_ALIVE = 300

HTTP_USER_AGENT = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

HTTP________ = -------------------------------------------------------------------------------------

HTTP________________ = ------------

PATH = /usr/local/bin:/usr/bin:/bin

There was no HTTP_REFERER listed.

Thanks for any help I can get on this.
Well, the HTTP_REFERER variable would be set to the page that contained the link that got you to this page. If its not set, then I have to ask, did you load the page directly?

Jeff
Jan 7 '08 #2

P: 7
Well, the HTTP_REFERER variable would be set to the page that contained the link that got you to this page. If its not set, then I have to ask, did you load the page directly?

Jeff
I loaded the page through a perl program - here is the start of the html it creates as well as the <form> post section
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.     <HEAD>
  3.     <TITLE>ECOC Registration - OOC</TITLE>
  4.                            here I have had <HTTP_REFERER
  5.     <style  type="text/css">    some style stuff
  6.  </style>
  7.  
  8.     </HEAD>
  9.     <BODY>
  10. <form target='_self' action='http://www.ottawaoc.ca/scgi-bin/COC_confirm.pl' method='post'>
  11. <input type='hidden' name='item_number' value='71'>
  12. <input type='image' src='http://www.ottawaoc.ca/images/marker.gif'
  13.         border='0' name='submit' alt='Pay for all by cheque'>
  14. <input type='hidden' name='lname' value=Forbes>
  15. <input type='hidden' name='fname' value=Mary>
  16. </form>
  17.  
Does that help?
Jan 7 '08 #3

P: 7
I loaded the page through a perl program - here is the start of the html it creates as well as the <form> post section
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.     <HEAD>
  3.     <TITLE>ECOC Registration - OOC</TITLE>
  4.                            here I have had <HTTP_REFERER="www.ottawaoc.ca">
  5.     <style  type="text/css">    some style stuff
  6.  </style>
  7.  
  8.     </HEAD>
  9.     <BODY>
  10. <form target='_self' action='http://www.ottawaoc.ca/scgi-bin/COC_confirm.pl' method='post'>
  11. <input type='hidden' name='item_number' value='71'>
  12. <input type='image' src='http://www.ottawaoc.ca/images/marker.gif'
  13.         border='0' name='submit' alt='Pay for all by cheque'>
  14. <input type='hidden' name='lname' value=Forbes>
  15. <input type='hidden' name='fname' value=Mary>
  16. </form>
  17.  
Does that help?
Sorry - forgot to get in the assignment statement that I have also tried in the <HEAD>
<HTTP_REFERER="www.ottawaoc.ca">
Jan 7 '08 #4

P: 7
I loaded the page through a perl program - here is the start of the html it creates as well as the <form> post section
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.     <HEAD>
  3.     <TITLE>ECOC Registration - OOC</TITLE>
  4.                            here I have had <HTTP_REFERER="www.ottawaoc.ca">
  5.     <style  type="text/css">    some style stuff
  6.  </style>
  7.  
  8.     </HEAD>
  9.     <BODY>
  10. <form target='_self' action='http://www.ottawaoc.ca/scgi-bin/COC_confirm.pl' method='post'>
  11. <input type='hidden' name='item_number' value='71'>
  12. <input type='image' src='http://www.ottawaoc.ca/images/marker.gif'
  13.         border='0' name='submit' alt='Pay for all by cheque'>
  14. <input type='hidden' name='lname' value=Forbes>
  15. <input type='hidden' name='fname' value=Mary>
  16. </form>
  17.  
Does that help?
Sorry - forgot to get in the assignment statement that I have also tried in the <HEAD>
<HTTP_REFERER="www.ottawaoc.ca">
If you want to look at the code online, go to ottawaoca.ca/scgi-bin/COC_2008.pl
put in a name and a phone or email, click 'Enter indiv runners,' then 'enter participants', then put in a yob, then click on 'submit this entry' and finally on the red and white icon. The code behind the red and white icon is what posts info to the final program. (I guess I could post this same information - that should work) Sorry there are so many steps but the editing requires some basic info.
Jan 7 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
Sorry - forgot to get in the assignment statement that I have also tried in the <HEAD>
<HTTP_REFERER="www.ottawaoc.ca">
That I know of, that is not going to work. You cannot just put that in your HTML and expect it to work. "<HTTM_REFERER> is not an HTML element. In fact, I doubt that page would pass any validation with that in there.

Here is a link that will explain to you exactly what HTTP_REFERER is. You should read it. It is an environment variable that gets set, telling you where you just came from. In other words, if I click a link to google.com from my own web page, then clicking on the google.com link will automatically set my web page, where I just came from, as the HTTP_REFERER. Does that clear it up?

You say you called the HTML page from a Perl script. Are you saying that you generated it with a Perl script using CGI? Just curious.


Ok, here is an example that will hopefully show you. Go to this page. Now, take note of what the URL is. Now go to the bottom of the page and click on the link for "Main". The information you are being shown in the grey box is the header information. Look at the line that says "Referer". If you remember, that is the page you were just at, where you clicked the link to come here. Hope that really clears that up.

Regards,

Jeff
Jan 7 '08 #6

P: 7
That I know of, that is not going to work. You cannot just put that in your HTML and expect it to work. "<HTTM_REFERER> is not an HTML element. In fact, I doubt that page would pass any validation with that in there.

Here is a link that will explain to you exactly what HTTP_REFERER is. You should read it. It is an environment variable that gets set, telling you where you just came from. In other words, if I click a link to google.com from my own web page, then clicking on the google.com link will automatically set my web page, where I just came from, as the HTTP_REFERER. Does that clear it up?

You say you called the HTML page from a Perl script. Are you saying that you generated it with a Perl script using CGI? Just curious.


Ok, here is an example that will hopefully show you. Go to this page. Now, take note of what the URL is. Now go to the bottom of the page and click on the link for "Main". The information you are being shown in the grey box is the header information. Look at the line that says "Referer". If you remember, that is the page you were just at, where you clicked the link to come here. Hope that really clears that up.

Regards,

Jeff
Thanks Jeff
No I am not any the wiser - I had read all of that - through other sources. The insert of HTTP_REFERER into the HEAD was just another attempt to make it work - you have confirmed what I thought - that the variable is set (or not set) by the method of getting there - not by a specific setting in the calling program.
Yes I generated it with a Perl script using CGI? and a post rather than a get.
In any case, due to another snag I hit, I have changed my program flow considerably and will not be using one program from 2 different places any longer so do not need this (although I am still curious for future reference)
Many thanks.
Jan 7 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.