Trium918 Posted April 7, 2007 Share Posted April 7, 2007 I cannot get the password() function to work. <? session_start(); if(!('username') && !('password')) { // if the user has just tried to log in $username = stripslashes($_POST['username']); $password = stripslashes($_POST['password']); $db_conn = mysql_connect("localhost") or die(mysql_error()); mysql_select_db("member_auth")or die(mysql_error()); $query = "select * from user_info_auth " ."where username='$username' " ." and password=('password')"; $result = mysql_query($query)or die(mysql_error()); if (mysql_num_rows($result) >0 ) { // if they are in the database register the user id $valid_user = $username; session_register("valid_user"); } } ?> <html> <body> <h1>Home page</h1> <? if (session_is_registered("valid_user")) { echo "You are logged in as: $valid_user <br>"; echo "<a href=\"logout.php\">Log out</a><br>"; } else { if (isset($username)) { // if they've tried and failed to log in echo "Could not log you in"; } else { // they have not tried to log in yet or have logged out echo "You are not logged in.<br>"; } // provide form to log in echo "<form method=post action=\"session.php\">"; echo "<table>"; echo "<tr><td>Userid:</td>"; echo "<td><input type=text name=username></td></tr>"; echo "<tr><td>Password:</td>"; echo "<td><input type=password name=password></td></tr>"; echo "<tr><td colspan=2 align=center>"; echo "<input type=submit value=\"Log in\"></td></tr>"; echo "</table></form>"; } ?> <br> <a href="members_only.php">Members section</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
jokur Posted April 7, 2007 Share Posted April 7, 2007 You aren't using password() " and password=('password')"; What you want to use is " and password = password('".$password."')"; Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 7, 2007 Author Share Posted April 7, 2007 You aren't using password() " and password=('password')"; What you want to use is " and password = password('".$password."')"; No result. The page is refreshing when I click the submit button. Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 7, 2007 Author Share Posted April 7, 2007 Any ideas why my I am not able to log in. Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 7, 2007 Author Share Posted April 7, 2007 I truely believe that this is some good code because once it was working when register_global = On. Now that it is off I am have trouble. session_start(); if(!('username') && !('password')) { // if the user has just tried to log in $username = stripslashes($_POST['username']); $password = stripslashes($_POST['password']); $db_conn = mysql_connect("localhost") or die(mysql_error()); mysql_select_db("member_auth")or die(mysql_error()); $query = "select * from user_info_auth " ."where username='$username' " ." and pass=password('password')"; $result = mysql_query($query)or die(mysql_error()); if (mysql_num_rows($result) >0 ) { // if they are in the database register the user id $valid_user = $username; session_register("valid_user"); } } ?> <html> <body> <h1>Home page</h1> <? if (session_is_registered("valid_user")) { echo "You are logged in as: $valid_user <br>"; echo "<a href=\"logout.php\">Log out</a><br>"; } else { if (isset($username)) { // if they've tried and failed to log in echo "Could not log you in"; } else { // they have not tried to log in yet or have logged out echo "You are not logged in.<br>"; } // provide form to log in echo "<form method=post action=\"session.php\">"; echo "<table>"; echo "<tr><td>Userid:</td>"; echo "<td><input type=text name=username></td></tr>"; echo "<tr><td>Password:</td>"; echo "<td><input type=password name=pass></td></tr>"; echo "<tr><td colspan=2 align=center>"; echo "<input type=submit value=\"Log in\"></td></tr>"; echo "</table></form>"; } ?> <br> <a href="logout.php">Members section</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 8, 2007 Author Share Posted April 8, 2007 Could someone have a look at this script? Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 8, 2007 Author Share Posted April 8, 2007 I am having problems accessing variables when register_global=Off <? session_start(); if ($_POST['username'] && $_POST['password']) { // if the user has just tried to log in $db_conn = mysql_connect("localhost"); mysql_select_db("member_auth"); $query = "select * from use_info_auth " ."where name='$username' " ." and password=password('$password')"; $result = mysql_query($query); if (mysql_num_rows($result) >0 ) { // if they are in the database register the user id $valid_user = $username; session_register("valid_user"); } } ?> <html> <body> <h1>Home page</h1> <? if (session_is_registered("valid_user")) { echo "You are logged in as: $valid_user <br>"; echo "<a href=\"logout.php\">Log out</a><br>"; } else { if (isset($username)) { // if they've tried and failed to log in echo "Could not log you in"; } else { // they have not tried to log in yet or have logged out echo "You are not logged in.<br>"; } // provide form to log in echo "<form method=post action=\"session.php\">"; echo "<table>"; echo "<tr><td>Userid:</td>"; echo "<td><input type=text name=username></td></tr>"; echo "<tr><td>Password:</td>"; echo "<td><input type=password name=password></td></tr>"; echo "<tr><td colspan=2 align=center>"; echo "<input type=submit value=\"Log in\"></td></tr>"; echo "</table></form>"; } ?> <br> <a href="members_only.php">Members section</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 8, 2007 Author Share Posted April 8, 2007 Could someone please have a look at this script and tell me what they think is going on? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 in the sql, "ans password = (....." is that a special word and needs `baticks`??? Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 8, 2007 Author Share Posted April 8, 2007 in the sql, "ans password = (....." is that a special word and needs `baticks`??? No, that is how it's set up. I once had this script working when register_global=On but now I am having problems getting data from form. Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 8, 2007 Author Share Posted April 8, 2007 This is the original code. The thing is I cannot get it working with register_global=Off <? session_start(); if ($userid && $password) { // if the user has just tried to log in $db_conn = mysql_connect("localhost", "webauth", "webauth"); mysql_select_db("auth", $db_conn); $query = "select * from auth " ."where name='$userid' " ." and pass=password('$password')"; $result = mysql_query($query, $db_conn); if (mysql_num_rows($result) >0 ) { // if they are in the database register the user id $valid_user = $userid; session_register("valid_user"); } } ?> <html> <body> <h1>Home page</h1> <? if (session_is_registered("valid_user")) { echo "You are logged in as: $valid_user <br>"; echo "<a href=\"logout.php\">Log out</a><br>"; } else { if (isset($userid)) { // if they've tried and failed to log in echo "Could not log you in"; } else { // they have not tried to log in yet or have logged out echo "You are not logged in.<br>"; } // provide form to log in echo "<form method=post action=\"authmain.php\">"; echo "<table>"; echo "<tr><td>Userid:</td>"; echo "<td><input type=text name=userid></td></tr>"; echo "<tr><td>Password:</td>"; echo "<td><input type=password name=password></td></tr>"; echo "<tr><td colspan=2 align=center>"; echo "<input type=submit value=\"Log in\"></td></tr>"; echo "</table></form>"; } ?> <br> <a href="members_only.php">Members section</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 8, 2007 Author Share Posted April 8, 2007 I don't want anyone to fix it just tell me how. 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.