所以这里的交易。我有一个登录表单,我可以使用Jquery设置cookie,但我的雇主希望使用php完成。所以我试图这样做。PHP Cookie没有设置表单提交
这里是我的形式
<?php if(!isset($_POST['commit'])){
echo "<a id='loginbtn' class='btn dropdown-toggle loginbtn' href='#' data-toggle='dropdown'>Sign in <strong class='caret'></strong></a>";
echo "<div id='loggedout' class='dropdown-menu' style='padding: 15px; padding-bottom: 0px;'>";
echo "<form name='LoginForm' id='LoginForm' action='' method='post' accept-charset='UTF-8'>";
echo "<input id='user_username' style='margin-bottom: 15px; height:25px;' type='text' name='username' size='30' value='Username' />";
echo "<input id='user_password' style='margin-bottom: 15px; height:25px;' type='password' name='password' size='30' value='********' />";
echo "<input class='btn btn-primary' id='login' style='clear: left; width: 100%; height: 32px; font-size: 13px;' type='submit' name='commit' value='Sign In' />";
echo "</form>";
echo "</div>";
}
?>
,当我尝试设置它看起来像这样的饼干:
<?php
if(isset($_POST['commit'])){
$username= $_POST["username"];
setcookie("TestCookie", $username, time()+3600, '/', 'mydomain.com');
}
?>
<!DOCTYPE html>
<html class='wf-franklingothicurwcond-n5-active wf-franklingothicurwcond-n7-active wf-active' lang='en'>
我,在一个点上,取得了$ username变量的全局和其输出该网页,所以我知道这是工作,但由于某种原因,cookie不会设置。
任何帮助是极大的赞赏:)
编辑:
不知道这有什么差别,但我使用的引导以及
修复它谢谢:)我有一个函数上面我设置cookie的位置:P – 2012-08-09 22:17:39