PHP page redirect [duplicate]

2019-01-02 20:21发布

This question already has an answer here:

Can PHP make a redirect call after executing a function? I am creating a function on the completion of which I want it to redirect to a file located in the same root folder. Can it be done?

 if {
      //i am using echo here
 }

 else if ($_SESSION['qnum'] > 10) { 
            session_destroy();
            echo "Some error occured.";
            //redirect to user.php
        }

15条回答
一个人的天荒地老
2楼-- · 2019-01-02 21:16

You can use this code to redirect in php

<?php
/* Redirect browser */
header("Location: http://example.com/");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
查看更多
十年一品温如言
3楼-- · 2019-01-02 21:17

The header() function does this:

header("Location: user.php");
查看更多
路过你的时光
4楼-- · 2019-01-02 21:19

Simple way is to use:

  echo '<script>window.location.href = "the-target-page.php";</script>';
查看更多
登录 后发表回答