如何在使用modx时设置cookie?

时间:2013-11-29 13:27:45

标签: php cookies session-cookies modx

我正在尝试使用外部脚本中的以下代码设置cookie但由于某种原因当我尝试从Javascript或php读取cookie时,它从不显示我插入的信息,它只显示Modx cookie信息。我错过了什么?

$modx = new modX();
$modx->initialize('web');

$_SESSION["username"] = $_POST["username"];
$_SESSION["member_num"] =  $result["member_num"];
setcookie("member_num", $result["member_num"], time()+3600);

1 个答案:

答案 0 :(得分:0)

您必须在设置任何Cookie之前启动会话。

require_once ($_SERVER["DOCUMENT_ROOT"] . '/manager/includes/config.inc.php');

startCMSSession();

$modx = new modX();
$modx->initialize('web');

$_SESSION["username"] = $_POST["username"];
$_SESSION["member_num"] =  $result["member_num"];
setcookie("member_num", $result["member_num"], time()+3600);