Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Writing link on HTML page

by Deanimal (Acolyte)
on Nov 04, 2002 at 05:18 UTC ( [id://210125]=perlquestion: print w/replies, xml ) Need Help??

Deanimal has asked for the wisdom of the Perl Monks concerning the following question:

I'm working with a script for a survey that someone else wrote. It works fine except for IE6 (according to a friend), when it doesn't write the correct URL for a link onto an html page that it creates. It works for me on IE5.5, and for everyone else as far as I know; but not for IE6.

The script creates an HTML page and on that page is a link which is written like this:
<a href="$JUMP_URL">Continue</a>

$JUMP_URL was earlier declared like this:
$JUMP_URL="$ENV{'HTTP_REFERER'}";

That is supposed to link back to the previous html page which contains the survey. The problem is that in IE6, it instead shows up as empty quotes: <a href="">Continue</a> and so it links to the .cgi file. Any ideas how to fix this?

Here's a copy of the script as a text file:
http://www.webmonkeydean.com/et-toi/survey.txt
The survey is here:
http://www.webmonkeydean.com/et-toi/

Thanks,
Dean

Replies are listed 'Best First'.
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

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:

    1. use http referer header in the script (server side); if that fails:
    2. use hidden form field, updated from Javascript (client side; this works around a filtering proxy); if that fails:
    3. 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

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>
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'
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

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)?

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>

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!

      That didn't work either. Oh well.

        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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://210125]
Approved by smitz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-25 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found