yobo Posted March 9, 2007 Share Posted March 9, 2007 hey all, i am not sure if my login system is working correctly with the sessions? my login2.php (shows once the user has submitted the login form) <?php include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $match = "SELECT userid FROM users WHERE username = '".$_POST['username']."' and password = '".$_POST['password']."';"; $qry = mysql_query($match) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows <= 0) { echo "Sorry, there is no username $username with the specified password.<br>"; echo "<a href=login.html>Try again</a>"; exit; } else { $_SESSION['ok'] = 'username'; echo "You are now logged in!<br>"; echo "Continue to the <a href=members.php>members</a> section."; } ?> my members.php <?php session_start(); ob_start(); if (!isset($_SESSION['ok'])) $_SESSION['ok']; echo "you are logged in as $username"; ?> <a href="logout.php">Logout Here</a> logout.php <?php session_destroy('ok'); echo "You are now logged out.<br>"; echo "<a href=\"login.php\">Log in</a>."; ?> much appricated for help Link to comment https://forums.phpfreaks.com/topic/42020-not-sure-if-i-have-coded-my-login-system-correctly/ Share on other sites More sharing options...
virtuexru Posted March 9, 2007 Share Posted March 9, 2007 First things first.. Do this in the beginning, take the $_POST, clear it, and assign variables.. It's safer and cleaner this way. $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); Then, to error check, instead of doing <= 0, do this: $num_rows = mysql_num_rows($qry); if ($num_rows != '1') {} else {} Hope that helps, if not, let me know what the error is. Link to comment https://forums.phpfreaks.com/topic/42020-not-sure-if-i-have-coded-my-login-system-correctly/#findComment-203772 Share on other sites More sharing options...
yobo Posted March 9, 2007 Author Share Posted March 9, 2007 everything is working fine now Link to comment https://forums.phpfreaks.com/topic/42020-not-sure-if-i-have-coded-my-login-system-correctly/#findComment-203781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.