PHP Redirect
Hi Friends today we will learn how to redirect in php..We will use 3 methods to redirect in php location method,refresh method and sleep() method....
php redirect |
header('location:http://codenair.com');
use redirect use to desired url or page instantly..
<form method="POST" action=""> <b>Url:</b><input type="text" name="url"/> <input type="submit" name="submit" value="Redirect"/> </form> <?php if(isset($_POST['submit'])){ $url=$_POST['url']; if(!empty($url)){ header('location:http://codenair.com'); }else{ echo 'URL is Empty'; } } ?>
PHP Redirection Method 2: delay in redirect refresh method
header('refresh:5;url=http://codenair.com');
method are used to delay redirect in php..
use the below codes to redirect user after 5 seconds ..you can increase the time..
<form method="POST" action=""> <b>Url:</b><input type="text" name="url"/> <input type="submit" name="submit" value="Redirect"/> </form> <?php if(isset($_POST['submit'])){ $url=$_POST['url']; if(!empty($url)){ echo 'Wait 5 Seconds to Redirect'; header('refresh:5 ; url='.$url.''); }else{ echo 'URL is Empty'; } } ?>
PHP Redirection Method 2: delay in redirect sleep method
php sleep method also used delay redirect ..
use the below php codes to delay redirect in php sleep method..
<form method="POST" action=""> <b>Url:</b><input type="text" name="url"/> <input type="submit" name="submit" value="Redirect"/> </form> <?php if(isset($_POST['submit'])){ $url=$_POST['url']; if(!empty($url)){ sleep(5); header('location:'.$url.''); }else{ echo 'URL is Empty'; } } ?>
That's it Friends all about php Redirect..Thank you for Visiting..
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.