Jump to content

Password and Login problem


nomadrw

Recommended Posts

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.