Claude 🤖 Posted December 1, 2009 Share Posted December 1, 2009 Hello Everyone: I have some troubles on a simple coding. I'm getting a redirect when I enter a password and user name. The password and User name is valid. Project is on a test server on a Mac using XMAPP Here is the codeing: Userlogin.html <html> <head> <title>User Login Form</title> </head> <body> <H1>Login Form</H1> <FORM METHOD="POST" ACTION="userlogin.php"> <P><STRONG>Username:</STRONG><BR> <INPUT TYPE="text" NAME="username"></p> <P><STRONG>Password:</STRONG><BR> <INPUT TYPE="password" NAME="password"></p> <P><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Login"></P> </FORM> </body> </html> userlogin.php <?php //check for required fields from the form if ((!$_POST[username]) || (!$_POST[password])) { header("Location: userlogin.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "nomad", "nomad") or die(mysql_error()); mysql_select_db("allysonart",$conn) or die(mysql_error()); //create and issue the query $sql = "select f_name from auth_users where username = '$_POST[username]' AND password = password('$_POST[password]')"; $result = mysql_query($sql,$conn) or die(mysql_error()); //get the number of rows in the result set; should be 1 if a match if (mysql_num_rows($result) == 1) { //if authorized, get the values of f_name l_name $f_name = mysql_result($result, 0, 'f_name'); //set authorization cookie setcookie("auth", "1", 0, "/", "www.allysonjonesmurals.com", 0); //create display string $display_block = "<P>$f_name $l_name is authorized!</p> <P>Authorized Users' Menu: <ul> <li><a href=\"secretpage.php\">secret page</a> </ul>"; } else { //redirect back to login form if not authorized header("Location: userlogin.html"); exit; } ?> <HTML> <HEAD> <TITLE>User Login</TITLE> </HEAD> <BODY> <? echo "$display_block"; ?> </BODY> </HTML> secretpage.php <?php if ($_COOKIE[auth] == "1") { $display_block = "<p>You are an authorized user.</p>"; } else { //redirect back to login form if not authorized header("Location: allyson_show.htm"); exit; } ?> <html> <head> <title>Secret Page</title> </head> <body> <?php echo "$display_block"; ?> </body> </html> DB information db name is allysonart table auth_users id int not null primary key auto_increment f_name varchar (50) l_name varchar (50) email varchar (150) username varchar (50) password varchar (50) all the files are in the same folder Any help would be great. Thanks in advance Please not this is not a class assignment. damon Quote Link to comment https://forums.phpfreaks.com/topic/183607-password-and-login-problem/ Share on other sites More sharing options...
Claude 🤖 Posted December 1, 2009 Author Share Posted December 1, 2009 OK I figured it out and boy do I feel like a big dummy. I physically entered the data instead of writing a SQL in which the password was not encrypted. So I will remember that one. damon Quote Link to comment https://forums.phpfreaks.com/topic/183607-password-and-login-problem/#findComment-969378 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.