Home >Backend Development >PHP Tutorial > php读取不已cookie

php读取不已cookie

WBOY
WBOYOriginal
2016-06-13 12:33:13855browse

php读取不了cookie
做一个登录界面,自动记忆用户名的功能

if(empty($_POST['chkRemember'])) {
       //用户没有选择单选框
         if(!empty($_COOKIE['username'])){
            setcookie('username','',time()-100);
         }
      }else{
       //用户选择单选框
       setcookie('username',$username,time()+7*24*3600);
      }

当用户选了记住用户名的单选框时,COOKIE已经保存,在C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Cookies菜单下多了一个COOKIE文件(administrator@localhost[1].txt),内容也是正确的

但是读取COOKIE却不成功,每次都是返回控制
' />

  function GetCookieVal($key){
  if(empty($_COOKIE[$key])){
     return "none";
  }else{
  return $_COOKIE[$key];
  }
}
?>

直接打印COOKIE数组   print_r($_COOKIE);
得到的也是空数组


求教这是怎么回事?
是不是COOKIE保存路径和读取路径不一致?

Statement:
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