Re: Writing link on HTML page
by BrowserUk (Patriarch) on Nov 04, 2002 at 06:27 UTC
|
Your friend is possibly using a firewall or proxy that blocks the HTTP_REFERER variable.
The Opera browser has a configuration option that turns referrer logging on or off. I don't recall this feature in IE5.5, but maybe it got added in IE6?
Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
| [reply] |
Re: Writing link on HTML page
by joe++ (Friar) on Nov 04, 2002 at 09:29 UTC
|
Hello Deanimal,
The "referer" http header is not compulsory for a web browser to send back to the server. It is merely a convention which is very convenient in many cases. However, there can be nasty side effects (like exposing semi secret urls from a linking intranet). There has been lots of discussion about this subject far beyond your question. What I recall is that IE implements some security mechanism where a transition from scheme (e.g. http to https) suppresses the referer header. Also, some proxy/firewall products can filter referer headers.
When I had the same kind of problems with a web form I implemented the following three staged solution:
- use http referer header in the script (server side); if that fails:
- use hidden form field, updated from Javascript (client side; this works around a filtering proxy); if that fails:
- use some reasonable default url. This can be a link to a help-page if there is no valid default.
Example of the Javascript hack (from memory, not tested):
<form name="myform" ...>
<input type="hidden" name="ref" value="http://my/default"/>
...
</form>
...
<script type="text/javascript">
document.forms.myform.value = window.location.href;
</script>
Update: rephrased the three steps to be more clear (hopefully).
--
Cheers, Joe | [reply] [d/l] |
Re: Writing link on HTML page
by Jaap (Curate) on Nov 04, 2002 at 09:55 UTC
|
One possible solution in this particular case is to use javascript's history.back() function like this:
<a href="javascript:history.back();">Continue</a>
| [reply] [d/l] |
Re: Writing link on HTML page
by smitz (Chaplain) on Nov 04, 2002 at 09:28 UTC
|
It sounds like BrowserUK is right, it could be a firewall issue.
Try acessing this test script from any browser/location that doesn't work:
#!/usr/bin/perl
use strict;
use CGI;
my $q = CGI->new;
print $q->header;
print $q->start_html;
print '<ul>';
foreach my $var (keys %ENV) {
print '<li>', $var, ' => ', $ENV{$var}, '</li><br>';
}
print '</ul>';
print $q->end_html;
This should print out some nice %ENV ironment variables for you, enabling you to eliminate your code as the source of the problem.
SMiTZ Warning: Untested code, possible typos, possibly $author eq 'stupid + tired' | [reply] [d/l] |
Re: (nrd) Writing link on HTML page
by newrisedesigns (Curate) on Nov 04, 2002 at 14:17 UTC
|
Take into account what both Joe++ and Jaap told you. Both have solutions that will work for your users. If you had a user like myself, I'd see the correct link sometimes, when I forgot to turn Javascript and Referrer Logging back off. (I use Opera)
If you want this link to be sure fire, make sure everyone will be able to see it. Use what Joe++ suggested and put in hidden form data (which can transfer more than just captured referrer data) or a default link.
The purpose of having the link is to return the user from a survey, right? Have the survey open in a different window, and allow the user to close it when he/she is done, returning the user to the point of origin.
Good luck,
John J Reiser
newrisedesigns.com
| [reply] |
Re: Writing link on HTML page
by Deanimal (Acolyte) on Nov 04, 2002 at 15:30 UTC
|
Thanks everyone for your ideas; I'm impressed by all of the support here (this was my first time posting a question).
Before posting my question I did try setting the URL in the form rather than in the script, but then it didn't work on my system. The "continue" URL was correct on the "You already voted" page, but on the "Results" page it linked to the .cgi page. I have no idea why, other than that the results page is generated by adding together 3 separate sections.
In the form I added this:
<input type="hidden" name="JUMP_URL" value="http://www.webmonkeydean.com/et-toi/">
And in the script, I commented out the previous value for JUMP_URL like this:
# $JUMP_URL="$ENV{'HTTP_REFERER'}";
and wrote the links like this:
<a href="$fields{'JUMP_URL'}">Continue</a>
As I said, this worked for the "you already voted" page, but not for the "results" page. Would this be a good approach for getting around the referer/firewall problem (and can you see what to do to make it work for both links)?
| [reply] |
Re: Writing link on HTML page
by Deanimal (Acolyte) on Nov 05, 2002 at 10:02 UTC
|
I tried putting the URL in the form instead of using "HTTP_REFERER" in the script, but it isn't working right yet (it still links to the .cgi page). I don't really know much about Perl, and admit that I'm just making a "stab" at this, but if anyone can help I'd really appreciate it.
In the form I put this line:
<input type="hidden" name="continue_url" value="http://www.webmonkeydean.com/et-toi/">
In the script I put this line:
$JUMP_URL="$fields{'continue_url'}";
and wrote the link like this:
<a href="$JUMP_URL">Continue</a>
| [reply] |
Re: Writing link on HTML page
by Deanimal (Acolyte) on Nov 05, 2002 at 22:42 UTC
|
Here's an update in case anyone's interested. I studied another script that does print a link correctly, and applied its approach to this one as follows:
In the form, I name the input "continue" like this:
<input type="hidden" name="continue" value="http://www.webmonkeydean.com/et-toi/">
In the script I assigned a value to "$JUMP_URL" like this:
$JUMP_URL="$fields{'continue'}";
and wrote the links like this:
<a href="$fields{'continue'}">Continue</a>
This works for the "you already voted" html page, which is a simple page to generate. But it does not work for the "results" page, which is printed by the script in 3 or 4 sections. In that page the link for "continue" shows up as empty quotes ("") instead of the URL.
I'm going to try turning off buffering by adding $|=1; to the second line and see it that fixes it. I'll let you know how it goes. Thanks for tuning in!
| [reply] |
|
That didn't work either. Oh well.
| [reply] |
|
I'm assuming you've got something like this going on:
- Page One - hidden input field with JUMP URL in it
- Page Two - reads hidden input field, creates continue link
- Page Three - attempts to read hidden input field, doesn't find it, creates empty continue link
The reason you're not getting the link on page three is that to pass the url value from Two to Three, you'd need a form on Page Two with the same hidden input field, and the 'Continue' link would have to submit the form for the value to be available on the next page.
What I'm trying to say is, the form values are only present on page Two - page Three has no knowledge of them.
I suggest you look at the CGI material in the Tutorials section!
| [reply] |