top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What are various methods for redirecting a PHP page?

+1 vote
113 views
What are various methods for redirecting a PHP page?
posted May 14, 2014 by Sachin Dahda

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote
 
Best answer

After form submission or a page redirect is triggered, it's commonplace to redirect the user to a different page or to the same page, formatted in a different way. Usually, you'd complete this by coding:

header('Location:  destination.php');
exit();

This is a completely acceptable way to code your pages, but I prefer to use a redirect function instead. Why? It's much more readable, and quite honestly, I'm tired of writing the header('Location: …') code.

function redirect($url,$permanent = false)
{
    if($permanent)
    {
        header('HTTP/1.1 301 Moved Permanently');
    }
    header('Location: '.$url);
    exit();
}
answer May 17, 2014 by Vrije Mani Upadhyay
0 votes

You can redirect your PHP page via following methods:

  1. By Using Java script:
    '; echo 'window.location.href="'.$filename.'";'; echo ''; echo ''; echo ''; echo ''; } } redirect('http:// '); ?>

  2. By Using php function: header ("Location: http:// ");

answer May 15, 2014 by Rahul Mahajan
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...