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; } ?> Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment 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){ Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 what does that mean Quote Link to comment Share on other sites More sharing options...
ublapach Posted April 19, 2008 Author Share Posted April 19, 2008 and how to fix please Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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"); } } Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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"); } } ?> Quote Link to comment 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); ?> Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 19, 2008 Share Posted April 19, 2008 Hey BrianM, Know anything about Multidimensional Arrays? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 what do you need help with, phpretard? Quote Link to comment Share on other sites More sharing options...
BrianM Posted April 19, 2008 Share Posted April 19, 2008 and yes, ublapach. Quote Link to comment 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 Quote Link to comment 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 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.