L Posted July 2, 2007 Share Posted July 2, 2007 Hey, I have learned, with your guy's help, to make a login script. It is all done...just need to work out some small things with while loops, but I have a question. How come every so often it just crashes? Like an hour ago it was working fine. Then thrity minites ago my login script stopped working. By this I mean it wouldn't log me in, again, meaning the login form would still be there and i wouldn't be allowed into the usr cp where it redirects me to. But then right now its working again. Is there a way i can fix this or is this just my host? url is http://infinitevortex.ulmb.com Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2007 Share Posted July 2, 2007 Posting some code might help. Quote Link to comment Share on other sites More sharing options...
L Posted July 2, 2007 Author Share Posted July 2, 2007 hmm...i didn't think it was the code but maybe it is...here is login.php <?php session_start(); if (ISSET($_POST['sublogin'])) { $username = trim($_POST['username']); $password = trim($_POST['password']); $cryptpassword = md5($password); $url = '/cp.php?user=$_SESSION[username]'; require("database.php"); $table = "users"; $sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'"; $result = mysql_query($sql)or die(mysql_error()); if(mysql_num_rows($result) > 0) { $storage = mysql_fetch_assoc($result); $_SESSION['username'] = $storage['username']; $_SESSION['userid'] = $storage['userID']; header("location: $url"); } else { echo "Wrong Username or Password"; } if(isset($_POST['remember'])){ setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("cookpass", $password, time()+60*60*24*100, "/"); } } if((empty($_SESSION['username'])) || (empty($_SESSION['userid']))) { echo' <form action="" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30" /></td></tr> <tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30" /></td></tr> <tr><td>Remember Me:<input type="checkbox" name="remember"> <input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr> </table> </form>'; } else { echo "Welcome <b>$_SESSION[username]</b>, you are logged in! <br /><br />"; echo "<div class=\"navlink\"><img src=\"arrow.png\" alt=\"\" /> <a href=\"cp.php?user=$_SESSION[username]\">My Account</a></div>"; echo "<div class=\"navlink\"><img src=\"arrow.png\" alt=\"\" /> <a href=\"editcp.php?user=$_SESSION[username]\">Edit Profile</a></div>"; echo "<div class=\"navlink\"><img src=\"arrow.png\" alt=\"\" /> <a href=\"logout.php\">Logout</a></div>"; } ?> EDIT: also could this be a problem with overloading sessions? Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2007 Share Posted July 2, 2007 I dont see any real problems, except this line.... $url = '/cp.php?user=$_SESSION[username]'; Should be... $url = '/cp.php?user='. $_SESSION['username']; Quote Link to comment Share on other sites More sharing options...
L Posted July 2, 2007 Author Share Posted July 2, 2007 ic...can u test it out for me then? like quickly register and see if it works for u(meaning u stay logged in)?...Also could this problem be caused by storing too many sessions and making too many queries? Because before I had like 20 things stored as sessions for the editcp page...but i deleted them because they didn't seem to be needed.... One last thing....do you know why the remember me feature isn't working?....because when i log out shouldn't my info be already filled out with the cookies im setting? -Thank you for your time ~L 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.