Jarod Posted December 22, 2009 Share Posted December 22, 2009 Okay I have a site im working on for the login, http://jarodsworld.ismywebsite.com/trookine/index.php You can log in using test for the username and password. When you log out the Member Access Feature is empty, but if you refresh page one more time it shows you are logged in. Any reason why it does that empty box content after redirect (when you successfully log in)? Here is my PHP code: <?php $login_message = "<p>Login with your existing account to access more features.</p>\n"; if(isset($_POST['islogging'])) { // User is attempting to login $username = mysql_real_escape_string($_POST['user1']); $password = mysql_real_escape_string($_POST['pass1']); $verification_result = $member_handler->verify_member($username, $password); if($verification_result == 0) { // User details are verified $username = $_POST['user1']; $_SESSION['username'] = $username; $_SESSION['islogged'] = true; } else { $login_message = '<p class="red_text">The submitted username and/or password is incorrect, please try again.</p>'."\n"; } } else { // Not attempting to login if(isset($_SESSION['islogged']) == true) { // Check if user is logged in if(isset($_GET['option']) == "logout") { // User is logging out --- See if they have clicked the logout button header("Location: logout.php"); } ?> <h4 class="hello_member">Hey there, <a href="#" title="Click here to view your profile"><?php print($_SESSION['username']); ?></a>! (<a href="?option=logout">Logout</a>)</h4> <p>An announcement was made while you were away. <a href="#">Check it out</a>!</p> <h4>Account Statistics</h4> <ul class="stats"> <li><b>Account type:</b><span class="list_info"><?php print($member_handler->member_type($_SESSION['username'])); ?></span></li> <li><b>New messages:</b><span class="list_info">0</span></li> <li><b>Total messages:</b><span class="list_info">0</span></li> <li><b>Total news comments:</b><span class="list_info">0</span></li> <li><b>Total guide comments:</b><span class="list_info">0</span></li> </ul> <h4>Runescape Statistics</h4> <ul class="stats"> <li><b>In-Game Name:</b><span class="list_info"><?php print($member_handler->rs_name($_SESSION['username'])) ?></span></li> <li><b>Quests Complete:</b><span class="list_info">0</span></li> </ul> <?php } else { // User is not logged in ?> <?php print($login_message); ?> <p><b>If you don't have an account yet, consider joining TrooKine today!</b></p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label for="user1">Username:</label> <input type="text" name="user1" id="user1" class="field" /> <label for="pass1">Password:</label> <input type="password" name="pass1" id="pass1" class="field" /> <input type="hidden" name="islogging" /> <input type="submit" value="Login" /> </form> <?php } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2009 Share Posted December 23, 2009 A little off topic but this piece of logic doesn't make much sense. $verification_result = $member_handler->verify_member($username, $password); if($verification_result == 0) { // User details are verified $username = $_POST['user1']; $_SESSION['username'] = $username; $_SESSION['islogged'] = true; } else { $login_message = '<p class="red_text">The submitted username and/or password is incorrect, please try again.</p>'."\n"; } 0 equates to false in php, surely the verify_member() method should return true if the user is verified. Logic such as this will make your code hard for anyone else to read / follow. Quote Link to comment Share on other sites More sharing options...
Jarod Posted December 23, 2009 Author Share Posted December 23, 2009 A little off topic but this piece of logic doesn't make much sense. $verification_result = $member_handler->verify_member($username, $password); if($verification_result == 0) { // User details are verified $username = $_POST['user1']; $_SESSION['username'] = $username; $_SESSION['islogged'] = true; } else { $login_message = '<p class="red_text">The submitted username and/or password is incorrect, please try again.</p>'."\n"; } 0 equates to false in php, surely the verify_member() method should return true if the user is verified. Logic such as this will make your code hard for anyone else to read / follow. In my functions I always used 0 as true and -1 as false, maybe I should change up on that consider what you just said. I never thought of values being true or false that way to be honest. Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2009 Share Posted December 23, 2009 A little off topic but this piece of logic doesn't make much sense. $verification_result = $member_handler->verify_member($username, $password); if($verification_result == 0) { // User details are verified $username = $_POST['user1']; $_SESSION['username'] = $username; $_SESSION['islogged'] = true; } else { $login_message = '<p class="red_text">The submitted username and/or password is incorrect, please try again.</p>'."\n"; } 0 equates to false in php, surely the verify_member() method should return true if the user is verified. Logic such as this will make your code hard for anyone else to read / follow. In my functions I always used 0 as true and -1 as false, maybe I should change up on that consider what you just said. I never thought of values being true or false that way to be honest. Well, your logic is completely the opposite to that of php. 0 is always considered false and 1 always considered true. You should take a look at booleans. Quote Link to comment Share on other sites More sharing options...
Jarod Posted December 23, 2009 Author Share Posted December 23, 2009 I guess, but I'm still having a buggy issue here :'(, any reason why the login is doing this?? (I changed them for true/false by the way) Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2009 Share Posted December 23, 2009 This would also enable you to perform your checks with less code. eg; if ($member_handler->verify_member($username, $password)) { $username = $_POST['user1']; $_SESSION['username'] = $username; $_SESSION['islogged'] = true; } instead of.... $verification_result = $member_handler->verify_member($username, $password); if($verification_result == 0) { // User details are verified $username = $_POST['user1']; $_SESSION['username'] = $username; $_SESSION['islogged'] = true; } Quote Link to comment Share on other sites More sharing options...
Jarod Posted December 23, 2009 Author Share Posted December 23, 2009 That's not fixed anything, it's still clutching Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2009 Share Posted December 23, 2009 Once you have verified your user is valid and set the appropriate $_SESSION variables you will need to redirect the user back to this page. Quote Link to comment Share on other sites More sharing options...
Jarod Posted December 23, 2009 Author Share Posted December 23, 2009 Thanks, I just figured that out myself l0l.... 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.