Hey, you might find this useful, its a script ive made for the site im currently coding. Change what you need, hope it helps! Also, you'll have to make adjustments to your DB or the script, either way you need to change something, sorry 😛
<?
// Set the variables to the posted information
$pusername = $_POST['nick'];
$ppassword = $_POST['password'];
// If form is submitted
if(isset($login)) {
// Change the submitted password into MD5 hash
$md5password = md5($ppassword);
// Check to see if the username and password are correct
$check = "SELECT * FROM users WHERE nickname = '$pusername' AND md5pw = '$md5password'";
// Do the query
$query = safe_query($check) or die("Failed to do query ($check) because: ".mysql_error());
// If the username / password dont match
if(mysql_num_rows($query) == 0) {
// Show the error message
echo("Your username / password are incorrect, please go <a href=\"javascript:history.back()\">back</a> and try again.");
}
else {
// Pull out the user's information
$row = mysql_fetch_array($query);
$userID = $row['userID'];
$username = $row['nickname'];
$averify = $row['averify'];
// Set cookies or sessions
$_SESSION['xdloggedin'] = $username;
$_SESSION['xduserid'] = $userID;
$_SESSION['averify'] = $row['averify'];
echo ("You are now logged in as $username ($userID), thank you. Redirecting you to where you came from.<br>If this message appears for more than 5 seconds, click <a href=\"./index.php?\">here</a>");
?>
<META HTTP-EQUIV="Refresh" CONTENT=";URL=./index.php?">
<?
}} else {
if(isset($_SESSION['xdloggedin'])) {
// Set the admin variable
if($_SESSION['averify'] == 1) {
$admin = "<a href=\"index.php?site=admin\" target=\"_blank\">Admin Center</a>";
} else {
$admin = "";
}
echo("Welcome, <a href=\"./?p=profile\">{$_SESSION['xdloggedin']}</a>;");
echo("<br>");
echo("<br>");
echo("<a href=\"index.php?site=news\">Main News</a>");
echo("<br>");
echo("<a href=\"index.php?site=messenger\">Messenger</a>");
echo("<br>");
echo("<a href=\"index.php?site=buddys\">Buddys</a>");
echo("<br>");
echo("$admin");
echo("<br>");
echo("<a href=\"index.php?logout=true\">Logout</a>");
} else {
// Echo the form
?>
<form method="post" name="login" action="<? $_SERVER['PHP_SELF']; ?>">
<input name="nick" type="text" class="form_username" onFocus="this.className='form_on'" onBlur="this.className='form_off'" size="10">
<input name="password" type="password" class="form_password" onFocus="this.className='form_on'" onBlur="this.className='form_off'" size="10">
<input type="submit" name="login" value="login">
</form>
• <a href="index.php?site=register">register now</a><br>
• <a href="index.php?site=lostpassword">lost password</a><br>
• <a href="index.php?site=registered_users">registered users</a><br>
<?
}}
?>