dongwei4103 2019-03-04 08:23
浏览 68
已采纳

Cookie未在浏览器中设置[PHP]

I have some simple static login PHP logic and trying to save the username in a cookie. Unfortunately, it doesn't save anything and also returns no errors, so I'm not really sure what's wrong. Maybe you can spot something in the code I'm doing wrong.

$users = array('allan'=>'allanpass');

$username = $_POST["username"];
$enterpass = $_POST["password"];

if(isset($_POST["username"])) {
    if (array_key_exists($username, $users)) {
        $pass = $users["allanpass"];
        if($enterpass == $pass) {
            setcookie("heyhey", 'user2', time() + 60 * 60 * 24 * 7, '/');
            echo "Welcome back! <br />";
            echo '<a href="login.php?link=link1">Link1</a><br />';
            echo '<a href="login.php?link=link2">Link2</a><br />';
            echo '<a href="login.php?link=link3">Link3</a><br />';

        } else {
            echo "pass does not exist";
        }
    } else {
        array_push($users, $username);
        echo "hello new user <br />";
        echo '<a href="#">Link1</a><br />';
        echo '<a href="#">Link2</a><br />';
        echo '<a href="#">Link3</a><br />';
    }
} else {
    echo "Please fill in the form";
};

EDIT: I have no previous cookies saved. Everything is destroyed.

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 在线教育培训平台,主要以点播视频和在线练习测试为主,除将视频做切片外,有其他哪种方式降低流量?(关键词-带宽速率)
      • ¥20 用c语音或c++实现银行叫号系统
      • ¥15 人工智能 规则正向演绎和推理
      • ¥20 基于STM32F401的电子密码锁设计
      • ¥15 famamacbeth回归中遇到only size-1 arrays can be converted to Python scalars,求解答
      • ¥15 单片机多个自锁按键的编程实践
      • ¥15 用python操作redis存储中文后,再取出的数据变成了乱码怎么办?
      • ¥15 C语言简单排序问题有偿求解
      • ¥20 请问图片的代码什么意思
      • ¥15 coq问题求带,有偿