hi im trying to conbine all these scripts into 1 unless for security reason this is a bad thing.
i am VERY new to php so trying to learn at the same time, so please keep responses very simple and easy to understand. this script. Please dont confuse me by rewriting a complete new script
login.php
<?php
// Include init file
include 'init.php';
if (!isset($_POST['submit']))
{
// Show the form
include 'login_form.inc.php';
exit;
}
else
{
// Try and login with the given username & pass
$result = user_login($_POST['username'], $_POST['password']);
if ($result != 'Correct')
{
// Reshow the form with the error
$login_error = $result;
include 'login_form.inc.php';
}
else
{
echo 'Thank you for logging in, <a href="index.php">click here</a> to go back.';
}
}
?>
loginregisterform.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="Style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="banner">banner</div>
<p class="PageHeading">Login or Register</p>
<p>If you have registered before then please log in. Otherwisew please register below.</p>
<div id="login2">
<?php if (isset($login_error)) { ?>
There was an error: <?php echo $login_error; ?>, please try again.
<?php } ?>
<form action="login.php" method="post">
<b>Username:</b> <input type="text" size="20" maxlength="20" name="username"
<?php if (isset($_POST['username'])) { ?> value="<?php echo $_POST['username']; ?>" <?php } ?>/><br />
<b>Password:</b> <input type="password" size="20" maxlength="10" name="password" /><br />
<input type="submit" name="submit" value="Login" />
</form>
</div>
<div id="register2">
<?php if (isset($reg_error)) { ?>
There was an error: <?php echo $reg_error; ?>, please try again.
<?php } ?>
<form action="register.php" method="post">
<b>Username:</b> <input type="text" size="20" maxlength="20" name="username"
<?php if (isset($_POST['username'])) { ?> value="<?php echo $_POST['username']; ?>" <?php } ?>/><br />
<b>Password:</b> <input type="password" size="20" maxlength="10" name="password" /><br />
<b>Confirm Password:</b> <input type="password" size="20" maxlength="10" name="confirmpass" /><br />
<input type="submit" name="submit" value="Register!" />
</form>
</div>
</body>
</html>
register.php
<?php
// Include init file
include 'init.php';
if (!isset($_POST['submit']))
{
// Show the form
include 'register_form.inc.php';
exit;
}
else
{
// Check if any of the fields are missing
if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmpass']))
{
// Reshow the form with an error
$reg_error = 'One or more fields missing';
include 'register_form.inc.php';
exit;
}
// Check if the passwords match
if ($_POST['password'] != $_POST['confirmpass'])
{
// Reshow the form with an error
$reg_error = 'Your passwords do not match';
include 'register_form.inc.php';
exit;
}
// Everything is ok, register
user_register ($_POST['username'], $_POST['password']);
echo 'Thank you for registering on our site, <a href="index.php">click here</a> to go back.';
}
?>