Aaron4osu Posted December 23, 2011 Share Posted December 23, 2011 I'm having trouble getting my script to refresh the page. If the username, password match it falls into this if statement. Sometimes it works and other times and won't refresh the page automatically. I'm trying to use this line to refresh the page echo "<meta http-equiv='refresh' content='=2;index.php' />"; Here is the if statement if(mysql_num_rows($checklogin) == 1) { // store the row returned from query $row = mysql_fetch_array($checklogin); // get email address from row returned $email = $row['EmailAddress']; // store user variables in session array $_SESSION['Username'] = $username; $_SESSION['EmailAddress'] = $email; $_SESSION['LoggedIn'] = 1; // boolean echo "<h1>Success</h1>"; echo "<p>We are now redirecting you to the member area.</p>"; echo "<meta http-equiv='refresh' content='=2;index.php' />"; } here is the entire index.php file <?php include "base.php";?> <!-- base.php contains session_start() --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>User Management System (Tom Cameron for NetTuts)</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div id="main"> <?php // check if user is already logged in if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { ?> <h1>Pitch Shark Member Area</h1> <p>Thanks for logging in! You are <b><?=$_SESSION['Username']?><b> and your email address is <b><?=$_SESSION['EmailAddress']?></b>.</p> <ul> <!-- link that runs logout.php script --> <li><a href="logout.php">Logout.</a></li> </ul> <?php } // check login form elseif(!empty($_POST['username']) && !empty($_POST['password'])) { // strip away malicious code $username = mysql_real_escape_string($_POST['username']); // encrypt password $password = md5(mysql_real_escape_string($_POST['password'])); // return all matches to username and password $checklogin = mysql_query("SELECT * FROM haas12_test.users WHERE Username = '".$username."' AND Password = '".$password."'"); // if there is a match if(mysql_num_rows($checklogin) == 1) { // store the row returned from query $row = mysql_fetch_array($checklogin); // get email address from row returned $email = $row['EmailAddress']; // store user variables in session array $_SESSION['Username'] = $username; $_SESSION['EmailAddress'] = $email; $_SESSION['LoggedIn'] = 1; // boolean echo "<h1>Success</h1>"; echo "<p>We are now redirecting you to the member area.</p>"; echo "<meta http-equiv='refresh' content='=2;index.php' />"; } // if there information entered could not be found else { echo "<h1>Error</h1>"; echo "<p>Sorry, your account could not be found. Please <a href=\"index.php\">click here to try again</a>.</p>"; } } // display login form with link to register form else { ?> <h1>Member Login</h1> <p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p> <form method="post" action="index.php" name="loginform" id="loginform"> <fieldset> <label for="username">Username:</label><input type="text" name="username" id="username" /><br /> <label for="password">Password:</label><input type="password" name="password" id="password" /><br /> <input type="submit" name="login" id="login" value="Login" /> </fieldset> </form> <?php } ?> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
requinix Posted December 23, 2011 Share Posted December 23, 2011 Drop that extra equals sign and add a "url=": echo ""; Also know that it's entirely up to the browser whether it'll refresh the page or not (but most do). Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 23, 2011 Share Posted December 23, 2011 You shouldn't really be putting meta tags half way through the DOM. Why not use PHP headers? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.