Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How do I link in CGI?

by monkeygirl (Pilgrim)
on Jul 11, 2001 at 23:36 UTC ( [id://95826]=note: print w/replies, xml ) Need Help??


in reply to How do I link in CGI?

There's two different ways to do it. First, the better way (CGI.pm)

# This line loads the CGI.pm module. use CGI; # Print any error messages to the browser use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $im_better = new CGI; # You need to print a content header so you don't end up with Server 5 +00 errors print $im_better->header(); print $im_better->start_html(-title => 'Test Page'); # The coveted link print $im_better->a({href=>"http://www.google.com"}, 'Google'); $im_better->end_html();

Or you can do it quick and dirty:

print "Content-type: text/html\n\n"; # The content header ..... # Put stuff you need here print '<a href="http://www.google.com>Google</a>';

If you're also processing form results, etc., I strongly urge you to use CGI.pm.

Update: Your reply to E-Bitch leads me to believe you might be talking about redirection. In which case:

use CGI; my $im_better = new CGI; # Please note that I didn't print a header this time print $im_better->redirect("http://www.google.com");

And the quick and dirty way:

# I also didn't print a header this time either print "location:http://www.google.com\n\n";

Sarah
If Bill Gates can name a company after his "bedroom" problems, I can have a stupid sig that points it out.

Replies are listed 'Best First'.
Re: Re: How do I link in CGI?
by TeeHSee (Initiate) on Jul 12, 2001 at 01:07 UTC
    Sarah wrote:
    "# I also didn't print a header this time either
    print "location:http://www.google.com\n\n";"

    The formal way to do this would be to use "URI:http://...".
    location: is unoffical. CGI.pm uses both.

    Not that you did this wrong but: You may get incorrect results if you use relative URLs, so always use the absolute http://host/path/file URL. Cheers, Steffen
      Going by my ever handy copy of the HTTP/1.1 RFC, "Location: <absolute-uri>" is the correct way to do it; other options, such as "URI: <blah>" are not recommended, and support for these options would be hit or miss...

      --
      RatArsed

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-03-28 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found