我在设置和回显cookie时遇到问题,我想知道你是否可以帮助我,我对php相对较新,但我可以自己解决这个问题。这是代码......
if (empty($_COOKIE['source'])) {
$kw = $_SESSION["keyword"];
//echo $kw;
$needle = array(
"bomanite"
);
if (multineedle_stripos($kw, $needle) || $engineName == 'Direct' || $engineName == '') {
// branded search, don't display lead tracking phone/email
$source = "direct";
$liveemail = "bomanite@bomanite.ca";
$livephone = "<span id='bom-phone'>Call us for a Quote: (416) 800 5545</span>";
} elseif ($engineName == 'ppc') {
$source = "ppc";
$liveemail = "bomanite@bomanite.ca";
$livephone = "<span id='bom-phone'>Call us for a Quote: (416) 800 5446</span>";
} else {
$source = "organic";
$liveemail = "bomanite@bomanite.ca";
$livephone = "<span id='bom-phone'>Call us for a Quote: (905) 660 5545</span>";
}
setcookie("source", $source, time() + (60 * 60 * 24 * 30), '/', 'bomanite.cidev.info/');
setcookie("kw", $kw, time() + (60 * 60 * 24 * 30), '/', 'bomanite.cidev.info/');
setcookie("liveemail", $liveemail,time() + (60 * 60 * 24 * 30), '/', 'bomanite.cidev.info/');
setcookie("livephone", $livephone,time() + (60 * 60 * 24 * 30), '/', 'bomanite.cidev.info/');
} else {
$source = $_COOKIE['source'];
$kw = $_COOKIE["kw"];
$liveemail = $_COOKIE['liveemail'];
$livephone = $_COOKIE['livephone'];
}
?>
答案 0 :(得分:1)
Cookie对路径非常敏感。你能试试吗?
setcookie("source", $source, time() + (60 * 60 * 24 * 30), '/');
答案 1 :(得分:0)
确保在setcookie()
通话之前没有其他输出到客户端。因为它使用HTTP标头,所以不能在它之前输出。
这可能是您问题中的拼写错误,但您需要在文件顶部打开<?php
标记。