这么设置cookie有错吗?为什么不成功

WBOY
Release: 2016-06-13 13:00:53
Original
960 people have browsed it

这样设置cookie有错吗?为什么不成功
1.php:
    if($_GET["action"]=="login"){
        setCookie("lg","1",time()+3600);
    }
?>


        





2.php:
    if($_COOKIE["lg"]){
        echo $_POST["username"]."欢迎你";
    }else{
        echo "cookie不成功";
    }
------解决方案--------------------
逻辑问题:
// 进入这个分支的前提是你的表单提交到了本文件1.php,而不是2.php
if($_GET["action"]=="login"){
   setCookie("lg","1",time()+3600);
}
------解决方案--------------------
怎么访问1.php 的? 会进入if条件吗?
------解决方案--------------------
地址栏输入 http://localhost/1.php?action=login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template