Go Back   Web Server Hosting Forum by BODHost > Support > PHP Forum
 

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-05-10, 13:45
BOD Member
 
Join Date: Jan 2009
Posts: 172
Default PHP redirect?

I'm new to PHP scripting and currently learning how to make one. Unfortunately I don't know how make a PHP script about page redirect. Still trying to figure out on how to redirect to a different page in case that the page I'm trying to access no longer exist. Any tips?
Reply With Quote
  #2 (permalink)  
Old 04-27-10, 15:41
BOD Member
 
Join Date: Apr 2010
Location: Greece
Posts: 3
Default


PHP Code:
<?php
    
//Redirect to new page
    
header('Location: http://www.domain.tld/new-page.php');
?>
Reply With Quote
  #3 (permalink)  
Old 04-27-10, 17:18
BOD Member
 
Join Date: Mar 2010
Posts: 15
Default

Hello Ioulios,

Thank you for the code. Also, can you please let me know that how to add a notification so that the users can be notified that they would be redirected to an another page so that they can change their bookmark for the new page.
Reply With Quote
  #4 (permalink)  
Old 04-27-10, 18:14
BOD Member
 
Join Date: Apr 2010
Location: Greece
Posts: 3
Default

PHP Code:
<?php 
    
//Redirect Message
    
echo "You will be automatically redirected to a new location.<br>\n";
    echo 
"If your browser does not redirect you in 10 seconds, or you do not wish to wait, <a href=\"http://www.domain.tld/new-page.php\">click here</a>.\n";
    
//Redirect to new page 
    
header('Refresh: 10; URL=http://www.domain.tld/new-page.php'); 
?>
or

PHP Code:
<?php 
    
//Redirect Message
    
echo "You will be automatically redirected to a new location.<br>\n";
    echo 
"If your browser does not redirect you in 10 seconds, or you do not wish to wait, <a href=\"http://www.domain.tld/new-page.php\">click here</a>.\n";
    
//Redirect to new page 
    
$start time();
    
$end $start 10;
    while (
time() < $end) {
        
header('Location: http://www.domain.tld/new-page.php');
    }
    exit();
?>
Reply With Quote
  #5 (permalink)  
Old 07-21-10, 10:38
BOD Member
 
Join Date: Jun 2010
Posts: 50
Default

You probably already know this, but you can also put HTML in the redirect message, between the quotation marks. That way you're able to spruce up the redirect page a little - I hate seeing plain white pages with Times New Roman. ;)
Reply With Quote
  #6 (permalink)  
Old 01-20-11, 17:38
BOD Member
 
Join Date: Jan 2011
Posts: 2
Default

Quote:
Originally Posted by ioulios View Post
PHP Code:
<?php 
    
//Redirect Message
    
echo "You will be automatically redirected to a new location.<br>\n";
    echo 
"If your browser does not redirect you in 10 seconds, or you do not wish to wait, <a href=\"http://www.domain.tld/new-page.php\">click here</a>.\n";
    
//Redirect to new page 
    
header('Refresh: 10; URL=http://www.domain.tld/new-page.php'); 
?>
or

PHP Code:
<?php 
    
//Redirect Message
    
echo "You will be automatically redirected to a new location.<br>\n";
    echo 
"If your browser does not redirect you in 10 seconds, or you do not wish to wait, <a href=\"http://www.domain.tld/new-page.php\">click here</a>.\n";
    
//Redirect to new page 
    
$start time();
    
$end $start 10;
    while (
time() < $end) {
        
header('Location: http://www.domain.tld/new-page.php');
    }
    exit();
?>
The above code may return errors, when using a header function after any blank spaces, black lines or html code. If you do experience any header errors, use:

PHP Code:
<?php
   ob_start
();
      
//Redirect Message
    
echo "You will be automatically redirected to a new location.<br>\n";
    echo 
"If your browser does not redirect you in 10 seconds, or you do not wish to wait, <a href=\"http://www.domain.tld/new-page.php\">click here</a>.\n";
    
//Redirect to new page 
    
$start time();
    
$end $start 10;
    while (
time() < $end) {
        
header('Location: http://www.domain.tld/new-page.php');
    }
    exit();
   
ob_flush();
?>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump


All times are GMT -6. The time now is 23:21.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 1999-2012, BODHost Ltd. All rights reserved.