开发者

Redirect of page using meta tag and PHP

开发者 https://www.devze.com 2023-01-31 17:12 出处:网络
Here, in PHP code I am facing problem to redirect a page after valid login. Sample code: $result=mysql_query($sql);

Here, in PHP code I am facing problem to redirect a page after valid login.

Sample code:

    $result=mysql_query($sql);

    $count=mysql_num_rows($result);

    if($count==1){      
        e开发者_开发问答cho "<meta http-equiv='refresh' content='3;url=<?php echo "home.php"; ?>'>";
    }
    else{
    ?>
    <META HTTP-EQUIV="refresh" content="5;URL=<?php print "index.php"; ?>">
    <?php
    echo "Wrong Username or Password";
    }
?>

Here I want to redirect the page to home.php.

How can I modify the following line?

<meta http-equiv='refresh' content='3;url=<?php echo "home.php"; ?>'>


Send a location header:

header('Location: /home.php');
die;

Ensure that no content has been sent (including white space that may appear before and after <?php tags before calling header. Otherwise, it won't work.

For invalid login error, you can simply display the form again with an error message (rather than performing a redirect).

If you insist on using META tags:

echo "<meta http-equiv='refresh' content='3;url=home.php'>";

(You don't need the php open/close tags in a string).


Read this as to why you should use header() instead of META refresh: Use standard redirects: don't break the back button!

0

精彩评论

暂无评论...
验证码 换一张
取 消