i jjust want now to log in and continue my script
can anyone gimme a example of how to do a login script using cookies or session >_<
Moderator: General Moderators
Code: Select all
//initialize session
session_start();
if (!empty($_POST))
{
//make the query
$sql = "SELECT * FROM `users` WHERE `username` = '".$_POSTї'username']."' && `password` = '".$_POSTї'password']."' LIMIT 1";
//perform the query w/ error output
$result = mysql_query($sql) or die(mysql_error);
//check if a row exists
if (mysql_num_rows($result) > 0)
{
//fetch the row checking if row exists
//get users info
$user = mysql_fetch_assoc($result);
//create session "logged in"
$_SESSIONї'loggedin'] = true;
//add user to session
$_SESSIONї'username'] = $userї'username'];
//redirect them to new page
header("Location: loggedin.html");
}
}
//put form hereCode: Select all
if ($_SESSIONї'loggedin'])
{
//show protected content
}Code: Select all
$sql = "SELECT * FROM `users` WHERE `username` = '".$_POSTї'username']."' && `password` = '".$_POSTї'password']."' LIMIT 1";Code: Select all
if (!empty($_POST)){ ...Code: Select all
<input type="text" name="username" size="25" maxlength="25" />Code: Select all
$_POSTї"username"]; // Will contain the value typed into the form element named "username".Code: Select all
print_r($_POST)Code: Select all
$sql = "SELECT * FROM `users` WHERE `username` = '".$_POSTї'username']."' && `password` = '".md5($_POSTї'password'])."' LIMIT 1";