Gossamer Forum
Home : General : Perl Programming :

How can I do this ..???

Quote Reply
How can I do this ..???
I would like to open my home page from within my guestbook cgi script. How can I create a sub to do this ?

like

sub return_home {
open "home.html"
}

Can someone help me, please ...?
( I would then call &return_home after the guestbook entry is written)
Quote Reply
Re: How can I do this ..??? In reply to
What does &header; do?

Alex
Quote Reply
Re: How can I do this ..??? In reply to
Thanks....

I tried that but it doesn't work. Here's the end of the sub that writes the record, where I want to open the home page after, and the return_home sub :-

sub save {
&header;
open ("a","count.txt")| | &CgiDie ("Cannot open Count file");
$num = <a>;
close (a);
$num++;
$line = join('|', $num, $nama, $email, $hp, $urlhp, $lokasi, $komen, $ip, $date, $masa);
$line .= "\n";
open ("data",">>$datafail")&#0124; &#0124; &CgiDie ("Cannot open Guestbook Database");
print data "$line";
close (data);
open ("masuk",">count.txt")&#0124; &#0124; &CgiDie ("Cannot open count file");
print masuk "$num";
close (masuk);
&return_home;
}

# -------------------------------------------------------------------
# RELOAD HOME PAGE INTO FRAME
# -------------------------------------------------------------------

sub return_home {
print "Location: http://xxx.xxx.xxx.xxx/home.shtml";
}
What am I doing wrong...?
Quote Reply
Re: How can I do this ..??? In reply to
Sorry, ...I was in fact using the

sub return_home {
print "Content-type: text/html\n\n";
print "Location: http://url/to/home/page";
}

but had taken out the first line to try it without it.

When I confirm the write, I just get a blank page with Content-type etc... printed out on it...
Quote Reply
Re: How can I do this ..??? In reply to
Code:
sub return_home {
print "Content-type: text/html\n\n";
print "Location: http://url/to/home/page";
}



[This message has been edited by Bobsie (edited March 24, 1999).]
Quote Reply
Re: How can I do this ..??? In reply to
This is &header

# -------------------------------------------------------------------
# PRINTS OUT THE TOP OF PAGE INFO
# -------------------------------------------------------------------
sub header {
print qq |
<head><title>Leave Us Your Comments !!</title></head>
<body background="/graphics/back.gif" VLINK=GRAY ALINK=BLACK LINK=BLACK>
<CENTER>
|;
}

Quote Reply
Re: How can I do this ..??? In reply to
Hi web dog,

Why are you printing the starting HTML when you just want to redirect the user? You're either displaying a page or redirecting, one or the other. If you want to have a simple redirect, like after you've posted here, just print a META REFRESH tag into the page that's delivered after posting. Otherwise, if you want them redirected automatically without any confirmation, use the code that Alex posted, with no other HTML code.

adam
Quote Reply
Re: How can I do this ..??? In reply to
Thanks...

The META REFRESH works fine for me !

(However, I'm still curious as to how to get Alex's code to work..)
Quote Reply
Re: How can I do this ..??? In reply to
Sorry, it was Bobsie that posted the Location thing, not Alex.

Well, rather than printing out a page with META refresh, you just send the user on with the Location header. So you don't print any HTML, at the end of the routine you just put:

Code:
print "Location: http://path/to/next/page\n\n";

Don't print the Content-Type header, because all it will do then is print out the Location header as text. And make *sure* you have the "\n\n" at the end there or you'll get a 500 error.

I *think* that's what you mean anyway Smile.

If you mean that you want to use a routine that you can use again in other routines, just bung it into one:

Code:
function go_home {
print "Location: http://path/etc/etc/\n\n";
}

and call it at the end of the routine with &go_home;

Cheers,
adam

[This message has been edited by dahamsta (edited March 30, 1999).]