Page 1 of 1

PHP Login Where Password is Given

Posted: Fri Nov 13, 2009 11:46 am
by jschneier
I am relatively new to PHP and have previously only worked in HTML. I have a client that asked me to create a login page for him using Mysql and PHP. I have the database set up and understand how to do a standard login with just a username and password.

Ok. So this is my question: the client wants to be able to give a single password to users (he will do this on his own). When the users come to the login page he wants them to be required to use his password but he wants them to then be required to enter in their real name and email address.

This is what I have so far but I don't think this will actually work the way I have it.
Any suggestions would be welcome! I really appreciate it!

<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', True);

session_start();

if (isset($_GET['logout']))
{
$_SESSION = array();
if ($_COOKIE[session_name()])
{
setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
header('Location: test3.php');
}

if (isset($_POST['Full_Name']))
{
$Full_Name = htmlentities($_POST['Full_Name']);
$password = htmlentities($_POST['password']);
$email = htmlentities($_POST['email']);

if ($password == 'test')
{
$_SESSION['email'] = $email;
echo 'Login Successful<br/>';
echo 'Welcome, ' . $email;
}
else
{
echo '<span style="color: red">Login Failed</span>';
echo $email . ', does not exsit';
}
}
?>

<html>
<head>
<title>My login</title>
</head>
<body>
<div></div>
<?php if (isset($_SESSION['Full_Name'])) { ?>
You are now logged in
<a href="test3.php?logout=1">Logout</a>
<?php } else { ?>
<form action="" method="post">
Full Name: <input name="Full_Name" type="text" />
Password: <input name="password" type="password" />
Email: <input name="email" type="email" />
<input type="submit" value="Login to Voveen"/>
</form>
<?php } ?>
</body>
</html>