最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Redirect of page using meta tag and PHP - Stack Overflow

programmeradmin2浏览0评论

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){      
        echo "<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"; ?>'>

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){      
        echo "<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"; ?>'>
Share Improve this question edited Aug 12, 2018 at 12:31 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Dec 17, 2010 at 19:51 RahulOnRailsRahulOnRails 6,54210 gold badges54 silver badges87 bronze badges 1
  • 1 What is your question? If you are asking about an error, what error is it? With what you posted, I would guess that you are getting a problem with echo "<meta http-equiv='refresh' content='3;url=<?php echo "home.php"; ?>'>"; and should change it to echo "<meta http-equiv='refresh' content='3;url=\"home.php\"'>"; – ughoavgfhw Commented Dec 17, 2010 at 20:01
Add a ment  | 

2 Answers 2

Reset to default 4

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)

  1. 暂无评论