From PHP to Perl


Redirect

Posted in Other by assasiner on December 6, 2006

Well, i think you all know how to redirect in PHP (header(‘Location: page.php’)) but, in perl, you have to set the header before the input, and what if you always include a header file, print the content, and then a footer file, or use some kind of “PHP” Navigation, including files?
Well, there is one way to do this, “Javascript”
You can redirect with Javascript from Perl!

First, you need to make a basic JS Code

function redirect(time, url)
{
$seconds = time*1000;
$url = url;
setTimeout(“window.location=$url”,$seconds);
}

That will redirect in x seconds, to an x url
And, for some Perl integration, i made this simple function

sub redirect
{
print ‘<script language=”javascript” type=”text/javascript”>redirect(‘.$_[0].’,\”.$_[1].’\')</script>’;
}

And thats all! Now, when you want to redirect, just make

redirect(1,’mypage.pl’);

Thats the equivalent of PHP’s

header(‘refresh: 1; url=mypage.php’);

Well, i hope you find this useful :] Bye!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.