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

Hi all,

I have a doubt. This's a perl question.

I am keeping a html file in my server. The action for that form is to call a url(different domain). But it should not display the URL in the browser. How can i do that?

I tried like this... but it failed..

Html

<HTML> <HEAD><TITLE>One.... </TITLE></HEAD> <BODY BGCOLOR="#FFFFFF"> <form method="post" action="/cgi-bin/o.pl" > <input type="submit" name="submit" value="submit"> </form> </BODY> </HTML>
o.pl
#!/usr/bin/perl $dest = "http://yahoo.com"; print "Status: 302 Found\n" . "Location: $dest\n\n";

Using this example, My idea is to display the yahoo page, but in the browser yahoo.com will not be displayed. How can i do that?
Please try to give a solution for this...

Thanks
SU

20030526 Edit by Corion: Added formatting

Replies are listed 'Best First'.
Re: Redirected URL will not be displayed in the browser
by Tanalis (Curate) on May 26, 2003 at 13:17 UTC
    The easiest way to do this isn't (really) a Perl solution at all: use HTML frames to mask the URI within your index page.

    Something like the following (HTML) would do the trick:

    <FRAMESET ROWS="0, *" FRAMEBORDER=0> <FRAME NORESIZE /> <FRAME NAME=CONTENT SRC="http://www.yahoo.com" NORESIZE /> </FRAMESET>
    This will display the www.yahoo.com page, but display the URI of the page that contains the frameset.

    The CGI module supports the output of frames, and hence could be used to do this from within a script.

    Hope that helps.

    -- Foxcub
    #include www.liquidfusion.org.uk

    Update: Clarifications.

Re: Redirected URL will not be displayed in the browser
by dws (Chancellor) on May 26, 2003 at 15:56 UTC
    My idea is to display the yahoo page, but in the browser yahoo.com will not be displayed. How can i do that?

    Foxcub's method of using frames works, but doesn't completely obscure the fact that the page comes from the other domain (the recipient need only View Source to see what's going on).

    Another approach is for your CGI, after it's done whatever processing it needs to, to fetch (using LWP) whatever page you want to feed the browser, and pass that page through to the browser. Something like:

    use LPW::Simple; ... print "Content-type: text/html\n\n"; print get("http://www.yahoo.com/");
Re: Redirected URL will not be displayed in the browser
by gazpacho (Acolyte) on May 26, 2003 at 18:14 UTC
    Another way to do this is to send a GET request to the destination page within your script and write the lines to output as you get them. Something like this would work:

    use LWP::Simple; $destURL = "http://www.yahoo.com"; $doc = get "$destURL"; print "Content-Type: text\html\n\n"; print $doc;

    Basically, it will send the current HTML for $destURL to the browser as if it were yours. It will show up under your domain and URL.

    NOTE: This could be used for some questionable behavior. You're basically taking someone's copyrighted material, copying it, and showing it to someone else as if it were yours. It's an interesting thing to do, but if you don't make it clear to the user that this isn't your page, it's dishonest and possibly illegal. To the extent that either of these things bothers you, please be careful with this technique.

    The downside here is that your script will be hanging in the wind until it gets the response back from $destURL. If you have lots of instances running at the same time, this could create a large memory footprint. Putting a timeout in the script could help, as could running it under mod_perl so only one Perl interpreter gets forked. Then again, if you only need this once in a while, you could probably run it as-is.

    Hope this helps.