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
2 Answers
Reset to default 4Send 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!