Help me add cookies
Here are session but would like to add and cookies to maintain logged more.
Login
// Login
if($_POST['login_submit']){
$LOGIN['Email'] = mysql_real_escape_string($_POST['Email']);
$LOGIN['password'] = mysql_real_escape_string($_POST['login_password']);
$LOGIN_QUERY = "SELECT * FROM users WHERE email='".$LOGIN['Email']."' AND password='".$LOGIN['password']."'";
$LOGIN_RESULT = mysql_query($LOGIN_QUERY);
$LOGIN_ROW = mysql_num_rows($LOGIN_RESULT);
if(mysql_num_rows($LOGIN_RESULT)) {
$LOGIN_ROW = mysql_num_rows($LOGIN_RESULT);
$_SESSION['id'] = $LOGIN_ROW['id'];
$_SESSION['username'] = $_POST['Email'];
$_SESSION['password'] = $_POST['login_password'];
header('Location: /home');
} else {
header('Location: ');
}
}
function get_members
function get_members($id)
{
db_connect();
$query = ("SELECT * FROM users WHERE username='".$_SESSION['username']."' OR email='".$_SESSION['username']."' ");
$result = mysql_query($query);
$row = mysql_fetch_array($result);
return $row;
}
form Login
<form class="Container" name="" action="/" method="POST">
<div class="field">
<label>Email</label>
<input name="Email" type="email" name="Email" id="Email" value="" autofocus="autofocus">
</div>
<div class="field">
<label>Password</label>
<input name="login_password" type="password" name="Password" id="Password" value="">
</div>
<div class="btn-container">
<input name="login_submit" type="submit" class="submit_button" value="Login in">
</div>
</form>
Please help me if you can.
I need very strong
Change $_SESSION['username'] = $_POST['Email'];
to setcookie('username', $_POST['Email'], time()+86400);
, same to pswd.
In your function get_members
, change $_SESSION['username']
to $_COOKIE['username']
.
Don't store pswd directly, use md5()
first.