ublapach Posted April 18, 2008 Share Posted April 18, 2008 Im having trouble with makeing a login user name password system that checks values against a database and moves on to a main page once the user is loged in im haveing trouble with the code in the auth user file and im not sure why pleas help heres the code <?php // we must never forget to start the session session_start(); //$errorMessage = ''; //if (isset($_POST['username']) && isset($_POST['passwd'])) { include '../tracking/db_connx.php'; $username = @$_POST['username']; $passwd = @$_POST['passwd']; // check if the user id and password combination exist in database $sql = "SELECT username FROM webusers WHERE username = '$username' AND passwd = '$passwd'" or die("error 1"); $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { // the user id and password match, // set the session $_SESSION['db_is_logged_in'] == true; // after login we move to the main page header('Location:../indexin.php'); exit; } else { $errorMessage = 'Sorry, wrong user id / password'; } ?> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/ Share on other sites More sharing options...
dptr1988 Posted April 18, 2008 Share Posted April 18, 2008 What is the 'trouble' that you are having? Are you getting an error message? a blank page? redirect not working? ....... Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520791 Share on other sites More sharing options...
madspof Posted April 18, 2008 Share Posted April 18, 2008 I would try this: <?php // we must never forget to start the session session_start(); //$errorMessage = ''; //if (isset($_POST['username']) && isset($_POST['passwd'])) { include '../tracking/db_connx.php'; $username = @$_POST['username']; $passwd = @$_POST['passwd']; $issuchusername = mysql_query("SELECT * FROM webusers WHERE username = '$username'"); $usernamelogin = mysql_num_rows($issuchusername); if ($usernamelogin == 1) { $issuchpassword = mysql_query("SELECT * FROM webusers WHERE username = '$username' AND passwd = '$passwd'"); $passwordlogin = mysql_num_rows($issuchpassword); if ($passwordlogin == 1) { $_SESSION['db_is_logged_in'] == true; // after login we move to the main page header('Location:../indexin.php'); exit; }else{ echo "Your password was incorrect"; } }else{ echo "Your username was incorrect"; } }else{ echo "You did not enter either you password or username"; } ?> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520797 Share on other sites More sharing options...
ublapach Posted April 18, 2008 Author Share Posted April 18, 2008 now getting error Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /usr/home/jlytal/public_html/newsite/login/authuser.php:2) in /usr/home/jlytal/public_html/newsite/login/authuser.php on line 4 Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520833 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 I'm wanting to have it log you in and then go to a different page based on user access level stored in the database i think i can get this part if i could get it to set the session and stay logged in though out the site till you hit the logout button i dont think it is passing the form information along the the auth page but im not sure ive only done this once before and then i had the help of a teacher Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520845 Share on other sites More sharing options...
947740 Posted April 19, 2008 Share Posted April 19, 2008 There can be 0 spaces/linebreaks/whitespace in between the <?php tags and the header(). Example: This will not/should not work: <?php header("Location: test.php"); ?> This will/should work: <?php header("Location: test.php"); ?> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520846 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 what if the header is not at the top of the page Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520849 Share on other sites More sharing options...
947740 Posted April 19, 2008 Share Posted April 19, 2008 That makes no difference whatsoever. Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520853 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 do i need any configuration file to tell the sever where to send the cookie of how to set the session? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520856 Share on other sites More sharing options...
947740 Posted April 19, 2008 Share Posted April 19, 2008 You should not. The only other problem would be the fact that sessions are disabled. In that situation, you would need to edit a configuration file. Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520861 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 ok heres the code form my index page where it redirects to the indexlog page and then that page is just html whith a form thats action is authuser.php then that page is spost to check the username and password to see if they match form a database here the code of the two pages <?php session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page header('Location:indexlog.html'); exit; }else{ header('Location:indexin.php'); exit; } ?> thats the index page <?php session_start(); //$errorMessage = ''; //if (isset($_POST['username']) && isset($_POST['passwd'])) { include '../tracking/db_connx.php'; $username = @$_POST['username']; $passwd = @$_POST['passwd']; $issuchusername = mysql_query("SELECT * FROM webusers WHERE username = '$username'"); $usernamelogin = mysql_num_rows($issuchusername); if ($usernamelogin == 1) { $issuchpassword = mysql_query("SELECT * FROM webusers WHERE username = '$username' AND passwd = '$passwd'"); $passwordlogin = mysql_num_rows($issuchpassword); if ($passwordlogin == 1) $_SESSION['db_is_logged_in'] == true; // after login we move to the main page header('Location:../indexin.php'); exit; } ?> theres the authuser page and im sure that the db_connx.php file works cause i used it somewhere else and it worked so its not that oh and then after loged in it should redirect you to the indexin.php which checks for the session variable heres that code <?php session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page header('Location: indexlog.php'); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520865 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 still need help on this issue please Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520919 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 I have read throught the post and still don't know the problem. I see that some problems were made. What was the original problem? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520920 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 i cant get it to validate the user name and password and then move on to the logged in page Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520926 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 What happen when you try to log in? Blank page, Error, etc... Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520928 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 well blank page till i commented out the //if (isset($_POST['username']) && isset($_POST['passwd'])) { then it just goes back to the login page Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520930 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 Can you post the form code? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520931 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 <p> <form id="login" name="login" method="POST" action="login/authuser.php"> <input type="text" id="username" name="username" value="User Name" /> <input type="password" id="passwd" name="passwd" value="Password"/> <input type="submit" id="submit" value="Log In"/> </p> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520932 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 I gave your submit button a name and used it for the isset <?php session_start(); $errorMessage = ''; if (isset($_POST['Submit'])) { $username=$_POST['username']; $passwd=$_POST['passwd']; include '../tracking/db_connx.php'; $sql = "SELECT * FROM webusers WHERE username = '$username' AND passwd = '$passwd'" or die("error 1"); $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { echo"Loged In"; /* UNCOMMENT THIS LATER $_SESSION['db_is_logged_in'] == true; header('Location:../indexin.php'); exit; */ } else { $echo = 'Sorry, wrong user id / password'; } } ?> <p> <form id="login" name="login" method="POST" action=""> <input type="text" id="username" name="username" value="User Name" /> <input type="password" id="passwd" name="passwd" value="Password"/> <input type="submit" id="submit" name=Submit value="Log In"/> </form> </p> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520933 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 oh yeah...I also --selected * from table-- instead of just username Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520934 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 change the action="" to whatever it was... Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520936 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 um getting a black page now Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520937 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 Black? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520938 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 oh no type o blank my bad cant type Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520942 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 he probably means 'blank'... ? in which case, it's most likely a syntax error. ublapach, can you please copy your code here again and i'll review what you have. Link to comment https://forums.phpfreaks.com/topic/101786-login-management/#findComment-520943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.