Hey, I need help with my login system i tried making. I got help before but a problem i encountered is that I don't stay logged in. EX: taizkul.prohosts.org. Log in with **** and pass ***. The login is still displayed. In that place I want a user menu to come up....How can I do this?
Here is my login code.
<?php
session_start();
if (ISSET($_POST['sublogin']))
{
// Recreation of variables for later encryption uses the $_POST will be replaced with the decrypted source
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$cryptpassword = md5($password);
$url = '/cp.php?user=$_SESSION[username]';
//Connects to DB
require("database.php");
$table = "users";
$sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'";
$result = mysql_query($sql)or die(mysql_error());
// If result matched $myusername and $mypassword, table row must be 1 row
if(mysql_num_rows($result) > 0)
{
// Registers sesions and redirect to file "login_success.php"
$storage = mysql_fetch_assoc($result);
//Sessions here
$_SESSION['username'] = $storage['username'];
$_SESSION['userid'] = $storage['userID'];
header("location: $url");
}
else
{
echo "Wrong Username or Password";
}
}
?>
<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30"/></td></tr>
<tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30"></td></tr><tr><td>
<input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr>
</table>
</form>
Thank you for your help
~L
[ModEdit - bpat1434] Never post usernames and passwords.