ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 code to authentication page is <?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'; } } ?> code to check wheather your logged in or not <?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/page/2/#findComment-520944 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 Make a new file and put this code and only this code in it... Be sure --include '../tracking/db_connx.php';-- is still correct <?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()); $count=mysql_num_rows($result); if($count==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/page/2/#findComment-520946 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 just one more thing, please post your form as well. Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520947 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" name="Submit" value="Log In"/> </p> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520948 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 The onlt problem i saw was: if (mysql_num_rows($result) == 1) { Should be: $count=mysql_num_rows($result); if($count==1){ Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520949 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 it looks as though your trying to compare a boolean to a stored variable. lol Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520950 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 That would be funny if I new what it meant. lol Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520951 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 i'm saying that's what his problem is with the code... he's comparing a boolean to a stored variable lol. Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520953 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 what does that mean Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520954 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 and how to fix please Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520956 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 Did you put that code on a new page? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520957 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 i put it in the same page just replace what i had there Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520959 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 I set it up and it worked. How about you? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520960 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 did you use the same code that i did Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520962 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 if (isset($_POST['Submit'])) { if ($_POST['username'] == $username && $_POST['passwd'] == $passwd) { header("location: //wherever your main page is located"); } else { header("location: //location of your login page"); } } Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520964 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 where does this go i put it after the database stuff and it says theres an error Parse error: parse error, unexpected $ in /usr/home/jlytal/public_html/newsite/login/authuser.php on line 32 Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520967 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 paste your page with the new code i gave you exactly how you have it right now without changing anything. Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520969 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 <?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()); $count=mysql_num_rows($result); if (isset($_POST['Submit'])) { if ($_POST['username'] == $username && $_POST['passwd'] == $passwd) { header("location: ../indexin.php"); } else { header("location: ../indexlog.php"); } } ?> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520971 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 <?php session_start(); $errorMessage = ''; if (isset($_POST['Submit'])) { if ($_POST['username'] == $username && $_POST['passwd'] == $passwd) { header("location: ../indexin.php"); } else { header("location: ../indexlog.php"); } } include '../tracking/db_connx.php'; $sql = "SELECT * FROM webusers WHERE username = '$username' AND passwd = '$passwd'" $result = mysql_query($sql); $count=mysql_num_rows($result); ?> Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520975 Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 Hey BrianM, Know anything about Multidimensional Arrays? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520977 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 does this check it against the database Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520978 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 what do you need help with, phpretard? Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520980 Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 and yes, ublapach. Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520981 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 still getting error Notice: Undefined variable: username in /usr/home/jlytal/public_html/newsite/login/authuser.php on line 22 Notice: Undefined variable: passwd in /usr/home/jlytal/public_html/newsite/login/authuser.php on line 22 Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-520985 Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 i think i found out what the problem is the form isnt passing the variables username and passwd on to the auth page any ideas on how to fix this Link to comment https://forums.phpfreaks.com/topic/101786-login-management/page/2/#findComment-521207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.