所以这是交易。我有一个登录表单,我可以用 Jquery 设置 cookie,但我的雇主希望它用 php 完成。所以我试图这样做。
这是我的表格
<?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>";
}
?>
当我尝试设置 cookie 时,它看起来像这样:
<?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 不会设置。
任何帮助是极大的赞赏 :)
编辑:
不知道这是否有任何区别,但我也在使用 Bootstrap