View Full Version : PHP Redirect script [Tutorial I guess..]
Independent
15-06-2008, 09:07 AM
<?php
$time = ("3");
if($_GET['url'] == "yourhomepage.whatever") {
echo("You will be redirected to the homepage in ". $time ." seconds.");
}
else {
print("You will be redirected too ". $_GET['url'] ." in ". $time ." seconds.");
}
?>
<meta http-equiv="refresh" content="<?php echo $time; ?>;url=<?php echo $_GET['url']; ?>"/>
Doubt this well help anyone, but it's a redirection script I quickly made for newbies..
Create a page.. something like redirect.php, then visit redirect.php?url=websiteyouwishtogoto
Change yourpage.whatever too the URL of your homepage or something..
This is probably more like a tutorial, but for some reason I couldn't post there, hope this code helps somebody..
Also, change the value of $time if you wish for it too be quicker or slower, it goes by seconds if you did not know.
Decode
15-06-2008, 09:14 AM
They both redirect to the same place so shouldnt you just do this :S
header ("location: homepage.php");
Independent
15-06-2008, 09:16 AM
They both redirect to the same place so shouldnt you just do this :S
header ("location: homepage.php");
That's an instant redirection, I wanted to warn the user that they was about to leave the page.
& It just has diffrent text
You will be redirected to the homepage in ". $time ." seconds.
You will be redirected too ". $_GET['url'] ." in ". $time ." seconds.
Decode
15-06-2008, 09:25 AM
That's an instant redirection, I wanted to warn the user that they was about to leave the page.
& It just has diffrent text
You will be redirected to the homepage in ". $time ." seconds.
You will be redirected too ". $_GET['url'] ." in ". $time ." seconds.
I dont see the point in different text though, as they both go to the same page.
Independent
15-06-2008, 09:33 AM
I dont see the point in different text though, as they both go to the same page.
It's just more friendly I guess.. lolol
Agnostic Bear
15-06-2008, 10:03 AM
<?php
$time = ("3");
if($_GET['url'] == "yourhomepage.whatever") {
echo("You will be redirected to the homepage in ". $time ." seconds.");
}
else {
print("You will be redirected too ". $_GET['url'] ." in ". $time ." seconds.");
}
?>
<meta http-equiv="refresh" content="<?php echo $time; ?>;url=<?php echo $_GET['url']; ?>"/>
Doubt this well help anyone, but it's a redirection script I quickly made for newbies..
Create a page.. something like redirect.php, then visit redirect.php?url=websiteyouwishtogoto
Change yourpage.whatever too the URL of your homepage or something..
This is probably more like a tutorial, but for some reason I couldn't post there, hope this code helps somebody..
Also, change the value of $time if you wish for it too be quicker or slower, it goes by seconds if you did not know.
3 things:
1) stop using "" to echo stuff when you don't need it.
2) stop using print, it's slower and I doubt you need to get the integer it returns.
3) stop using == on $_GET or $_POST they always come through as strings so use === (=== is the same thing and the same type)
Independent
15-06-2008, 10:15 AM
3 things:
1) stop using "" to echo stuff when you don't need it.
2) stop using print, it's slower and I doubt you need to get the integer it returns.
3) stop using == on $_GET or $_POST they always come through as strings so use === (=== is the same thing and the same type)
Using print is a habbit, and ty for the === thing..
You learn something new everyday :)
Code update.. (if your interested :P)
<?php
$time = ("3");
if($_GET['url'] === "yourhomepage.whatever") {
echo("You will be redirected to the homepage in ". $time ." seconds.");
}
else {
echo("You will be redirected too ". $_GET['url'] ." in ". $time ." seconds.");
}
?>
<meta http-equiv="refresh" content="<?php echo $time; ?>;url=<?php echo $_GET['url']; ?>"/>
Edited by Hayd93(Forum Super Moderator): Posts merged due to forum lag :).
Excellent
15-06-2008, 12:43 PM
Nice little script but as Jew pointed out, stop using print, echo is faster.
Baving
15-06-2008, 01:07 PM
<?php
function redirect($url,$time=0){
if(!headers_sent()){
header("Location: ".$url);
}else{
echo '<meta http-equiv="refresh" content="'.$time.';url='.$url.'" />';
}
}
?>
Independent
15-06-2008, 02:07 PM
Nice little script but as Jew pointed out, stop using print, echo is faster.
I know, it's a habbit, although I've stopped now ^^
Agnostic Bear
15-06-2008, 03:19 PM
<?php
function redirect($url,$time=0){
if(!headers_sent()){
header("Location: ".$url);
}else{
echo '<meta http-equiv="refresh" content="'.$time.';url='.$url.'" />';
}
}
?>
<?php
function redirect( $url, $time = 0 )
{
if( !headers_sent() AND $time == 0)
{
header( 'Location: ' . $url );
}
else
{
echo( '<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '" />' );
}
}
?>
Would be better.
Independent
15-06-2008, 04:36 PM
Actually it wouldn't, because it's not getting the URL xD
Agnostic Bear
15-06-2008, 05:21 PM
Actually it wouldn't, because it's not getting the URL xD
Yes it is, the $url in the function.
Protege
16-06-2008, 12:51 AM
Could do it in javascript + some PHP.
<html>
<head>
<script type="text/javascript">
var time = 3; // in seconds...
var urlRedirect = '<?php echo ( $_GET [ 'url' ] ) ?>';
var time_redirect = time * 1000;
function checkUrl ()
{
// Don't know why we're checking this lawl
if ( urlRedirect == '' )
{
// Don't do nothing...
}
else if ( urlRedirect == 'homepage.php' )
{
// msgbox ( 'You are getting redirected in ' + time + ' seconds...' );
document.write( 'You are getting redirected in ' + time + ' seconds...' );
setTimeout( 'window.location = "' + urlRedirect + '"', time * 1000 );
}
else if ( urlRedirect != '' )
{
// msgbox ( 'You are getting redirected in ' + time + ' seconds...' );
document.write( 'You are getting redirected in ' + time + ' seconds...' );
setTimeout( 'window.location = "' + urlRedirect + '"', time * 1000 );
}
}
</script>
<title>Webpage Redirect</title>
</head>
<body onLoad="checkUrl();">
</body>
</html>
http://www.jamesrozee.com/urlRedirect.php?url=http://google.co.uk
Hypertext
16-06-2008, 03:42 AM
Nice seeing some code, but all of this seems incredibly pointless to one of simplest things.
You will be directed to the page in [insert time here] seconds.
<meta http-equiv="refresh" content="[insert time here];[insert link here]" />
Ooh look, and we didn't need php.
And echo isn't a function so why on earth would you use parentheses/brackets?
Must of been a long day. :)
Invent
16-06-2008, 05:08 AM
Nice seeing some code, but all of this seems incredibly pointless to one of simplest things.
You will be directed to the page in [insert time here] seconds.
<meta http-equiv="refresh" content="[insert time here];[insert link here]" />
Ooh look, and we didn't need php.
And echo isn't a function so why on earth would you use parentheses/brackets?
Must of been a long day. :)
How cute, lol.
Charlie thinking he's smarter than the best coder(s).
Protege
16-06-2008, 08:07 AM
Doesn't matter if you use brackets or not. Its a personal coding preference.
Nice seeing some code, but all of this seems incredibly pointless to one of simplest things.
You will be directed to the page in [insert time here] seconds.
<meta http-equiv="refresh" content="[insert time here];[insert link here]" />
Ooh look, and we didn't need php.
And echo isn't a function so why on earth would you use parentheses/brackets?
Must of been a long day. :)
Agnostic Bear
16-06-2008, 08:11 AM
Nice seeing some code, but all of this seems incredibly pointless to one of simplest things.
You will be directed to the page in [insert time here] seconds.
<meta http-equiv="refresh" content="[insert time here];[insert link here]" />
Ooh look, and we didn't need php.
And echo isn't a function so why on earth would you use parentheses/brackets?
Must of been a long day. :)
I can really see [insert time here] and [insert link here] being variables. Hmm. :eusa_eh:
Hypertext
16-06-2008, 12:18 PM
There doesn't seem any point in using variables. You only need to output the variables once. Invent that wasn't nice.
Protege
16-06-2008, 02:06 PM
Yes, I agree that this script is pretty useless - I'd never use it in all honesty.
Independent
16-06-2008, 07:04 PM
nice tutorial ;)
Thanks rofl.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.