這裏我有情況的表單提交到同一頁面後設置cookie .....在PHP表單提交中設置Cookie?
這裏是代碼:
<?php
require_once 'config.php';
$dbHandle = DBHandler::getInstance();
@session_start();
if($_POST['division'])
{
$fromDiv =$_POST['division'];
$divId =explode(',',$fromDiv);
echo $divId[0].'~';
echo $_COOKIE['preDiv'].'dfg'.'<br/>';
setcookie("preDiv",$divId[0],time() + (10 * 365 * 24 * 60 * 60));
$_SESSION['division'] = $divId[0];
}
$sql=$dbHandle->execQuery("SELECT * FROM master_division");
$division_str = '<option value="">--select--</option>';
while($fetch = $dbHandle->fetchObjectQuery($sql))
{
$division = $fetch->division_id.','.$fetch->name;
$division_str .= '<option value="'.$division.'">'.$fetch->name.'</option>';
}
echo $_COOKIE['preDiv'].'dfg'.'<br/>';
echo $_SESSION['division'];
?>
<!DOCTYPE html>
<html>
<body class="login" style="overflow: hidden;">
<div class="login-box" style="position: absolute;z-index: 999;padding: 10px;width: 40%;min-height: 200px;margin-left:-20%;">
<section class="portlet login-box-top" style="height:100%;">
<header>
<h2 class="ac">CHOOSE DIVISION To MEDISMO CRM LOGIN</h2>
</header>
<section style="height:76%;">
<div id="popup_box" > <!-- OUR PopupBox DIV-->
<div id="group_comp" style="margin-top:15%;margin-left:20%;">
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" style="border:none;">
<label><b>Choose Division:</b></label>
<select id="division" name="division"><?php echo $division_str;?></select>
<input type="submit" id="ok" value="OK" />
</form>
</div>
</div>
</section>
</section>
</div>
</body>
</html>
任何暗示我什麼是錯的。 ..
問題是? Cookie未設置?它被吃掉了嗎? Cookie開始與你談話?或者是度假的cookie?也許曲奇只是偏執狂,不想被打擾:| – dbf 2013-04-29 12:09:38
我不想讓餅乾過期.............. – 2013-04-29 12:11:00
生活是不公平的......即使餅乾不得不在某個時候死亡: ..所以餅乾沒有設置,你在評論中說的答案..你怎麼檢查它沒有設置?什麼'setcookie'返回? ..'如果在調用此函數之前存在輸出,則setcookie()將失敗並返回FALSE。如果setcookie()成功運行,它將返回TRUE。這並不表示用戶是否接受了cookie.' – dbf 2013-04-29 12:12:48