Php 未设置setcookie(手册中的示例)

Php 未设置setcookie(手册中的示例),php,cookies,setcookie,Php,Cookies,Setcookie,为什么setcookie不起作用? 我从数据库中获取数据并尝试设置cookie,但它未设置。我从php手册中得到了一个示例 $usrunic = $row['userunic']; $usrfname=$row['first_name']; $usrlname=$row['last_name']; session_start(); $_SESSION['email']=$usremail; $_SESSION['userid']=$usrunic; $_SESSION['username']=$

为什么setcookie不起作用? 我从数据库中获取数据并尝试设置cookie,但它未设置。我从php手册中得到了一个示例

$usrunic = $row['userunic'];
$usrfname=$row['first_name'];
$usrlname=$row['last_name'];
session_start();
$_SESSION['email']=$usremail;
$_SESSION['userid']=$usrunic;
$_SESSION['username']=$usrfname;
$_SESSION['userlname']=$usrlname;
if (!isset($_COOKIE[$usremail])){
setcookie($usremail,$usrunic,time()+3600);//1h
}

这真的是你所有的代码吗?除此之外没有其他内容?没有。在与数据库的连接上面,我得到$usrunic=$row['userunic']$usrfname=$row['first_name']$usrlname=$row['last_name'];会话是否已设置?您知道不能在setcookie上设置输出吗?另外,如果您通过php读取cookie,您知道必须重新加载页面以查看cookie是否已设置。可能是因为使用了本地主机?会话_start()仅工作