【问题标题】:How to add cookies in this PHP file [closed]如何在这个 PHP 文件中添加 cookie [关闭]
【发布时间】:2015-04-03 04:28:45
【问题描述】:

帮我添加 cookie

这里是会话,但想添加和 cookie 以保持记录 更多。

登录

    // 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: ');
}
}

函数 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 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>

如果可以,请帮助我。

我需要很强的

【问题讨论】:

标签: php session cookies login session-cookies


【解决方案1】:
  1. $_SESSION['username'] = $_POST['Email'];改为setcookie('username', $_POST['Email'], time()+86400);,与pswd相同。

  2. 在您的函数get_members 中,将$_SESSION['username'] 更改为$_COOKIE['username']

  3. 不要直接存pswd,先用md5()

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 2020-11-18
    • 2019-12-26
    • 2018-05-31
    • 1970-01-01
    • 2015-02-12
    相关资源
    最近更新 更多