0

I want to redirect web page using PHP. Currently I'm using this code to redirect:

header("Location: http://www.yourwebsite.com/user.php"); /* Redirect browser */
exit();

Do you have any alternative to redirect web page using PHP?

dur
  • 15,689
  • 25
  • 79
  • 125
  • 3
    Why would you want any other way? – Ivar May 01 '17 at 08:54
  • I want to know more about this because I redirected web page using this method from last 3 year years, but my friend asked me , Do you redirect web page using php but new method not old that's why I want to know? – Ranjeet Kumar May 01 '17 at 09:02
  • 1
    There is no other PHP alternative. You can do it using a html header or javascript, but why not stick to PHP? – Qirel May 01 '17 at 09:03
  • 1
    This is by far the best way indeed. This way your page does not have to render in order to redirect. It also always works even if Javascript is disabled. – Ivar May 01 '17 at 09:04
  • Maybe there are some frameworks that have an other function to redirect, but in the end, it always sends a Location header. – Ivar May 01 '17 at 09:05
  • Hi, you can redirect using the following script. But this is not a good way in my opinion. May be you can use any other framework for that. location.href='http://www.yourwebsite.com/user.php'; "; exit(); ?> – Muhammad Umar May 01 '17 at 15:36
  • I was looking another way to redirect web page @MuhammadUmar using php, I think " location.href='yourwebsite.com/user.php';; " this the good way to redirect Thanks once again – Ranjeet Kumar May 02 '17 at 09:13
  • @RanjeetKumar, I am going to give this solution as an Answer. Please mark that an an answer. Thank You – Muhammad Umar May 02 '17 at 09:57
  • http://stackoverflow.com/questions/283752/refresh-http-header – Deadooshka May 02 '17 at 10:05

1 Answers1

1

you can redirect using the following script. But this is not a good way in my opinion. May be you can use any other framework for that.

    <?php 
        echo "<script> location.href='yourwebsite.com/user.php';; </script>"; 
        exit(); 
    ?> 
Muhammad Umar
  • 349
  • 3
  • 14