VirusDoctor Posted December 17, 2007 Share Posted December 17, 2007 Hi guys, I've designed my login page for one of my new scripts. The problem is that I'd like the script to display a message "You are now logged in" and then after about 3 seconds, change to the main page after login. It currently doesn't do it. Could anyone assist as to how this can be done? I've tried using header("Location: template.php"); but it doesn't seem to be working and I cant figure this out on my own. Here is the code for the login.php page. <?php session_start(); // Start the session login timer. $start=time(); $_SESSION['time_start']=$start; // We check to see if a session is or isn't active. if (!isset($_SESSION[my_loginstatus])) { require_once("std_config.php"); require_once("header.php"); require_once ("php/qry_mngr.php"); // If the user clicks login... if(isset($_POST['login'])) { $username = trim(addslashes($_POST['username'])); $password = md5(trim($_POST['password'])); $query = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($query); if(mysql_num_rows($query) > 0) { // Check if the users account is activated, if it is, log them in and set some session variables. if ($row['activated'] > 0) { $_SESSION[my_loginstatus] = 'true'; $_SESSION['username'] = $username; $_SESSION['name'] = $row['name']; echo ("<br><div class='notice'>Welcome ".$row['name'].", You are now logged in.</div><br>"); mysql_query("UPDATE users SET logged_in='1' WHERE logged_in='0' AND username='$username'") or die (mysql_error()); header("Location: template.php"); } else { echo '<p class="error">Sorry, you must activate your account first. Please check your email for the email.</p> <p>Didn'."'".'t get your validation email? <a href="resend.php">Click here</a> to resend the validation email.</p>'; } } else { echo '<br><p class="error">There was an error processing your login, it appears that your username and/or password was incorrect. Please try again.</p> <p class="notice">Didn'."'".'t get your validation email? <a href="resend.php">Click here</a> to resend the validation email.</p><br>'; } } else { ?> <br> <div class="error"> Please Login to access your Members Area: </div> <br> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <br> <table class="loginTable" border="1"> <tr> <td class="bgcolor">Username:</td> <td class="inputbox"><input class="textinput" type="text" name="username" value="<?php if(isset($_POST['username'])) { print $_POST['username']; }?>" size="17"></td> </tr> <tr> <td class="bgcolor">Password:</td> <td class="inputbox"><input class="textinput" type="password" name="password" value="" size="17"></td> </tr> </table> <br> <div> <input class="buttons" name="login" type="submit" id="login" value="Login"> </div> </form> <br> <div class="notice"> Didn't get your validation email? <a href="resend.php">Click here</a> to resend the validation email. </div> <br> <div class="notice"> Need an account? <a href="register.php">Click here</a> to register, it's completely free! </div> <br> <?php } require("footer.php"); } else { header("Location: template.php"); } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 i think that header location has to go before any html coding for it to work. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 or you could use <meta http-equiv="refresh" content="5;url=http://wikipedia.org" /> Quote Link to comment Share on other sites More sharing options...
VirusDoctor Posted December 17, 2007 Author Share Posted December 17, 2007 Hi Adam, I realize that, it seems like it has to do with the way I designed the login script, using the If and Else statements where I have them prevents me from sending header info wherever I want it. I just cant think of how to get around this though or where to play the header info for it to work only once a users login is ok. Shaun Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 17, 2007 Share Posted December 17, 2007 put your require_once("header.php"); in your if(isset($_POST['login'])) login block Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 17, 2007 Share Posted December 17, 2007 Use the <meta http-equiv="refresh" content="0;url=http://wikipedia.org" /> That will redirect your page instantly. That's how i did it. Quote Link to comment Share on other sites More sharing options...
VirusDoctor Posted December 17, 2007 Author Share Posted December 17, 2007 Hey guys, thanks for all the help. The meta refresh is what worked perfectly for what I'm trying to do, thanks Adam! Rajiv, the reason why your fix didn't work is because in my header.php there's quite a bit of stuff going on in there, so when I added it to the isset login block, it made the whole page no longer function. Fortunately the problem is solved now though, thanks again guys. Shaun 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.