在根据 cookie 值显示不同内容的网站上工作。例如:
http://peewee.betaforming.com/
对比
http://peewee.betaforming.com/?cu=10010
该值可以在任何页面上设置,因为我在每个页面上都包含一个功能。如果 cookie 已设置或已保存,则加载该 CU 的信息。如果未设置 cookie 值或传递了数据库中不存在的值,则站点将显示默认信息。
这就是问题所在。如果您从没有设置 cookie 值到请求将“?cu=10010”附加到任何页面的站点,则当前页面在刷新之前不会加载当前数据。
根据我的阅读,我需要使用 header("location....
这是函数文件中用于设置/检索 cookie 的相关代码。
// CU cookies
if (isset($_GET["cu"]) && is_numeric($_GET["cu"])) {
$pass_cu = $_GET["cu"];
// See if passed value returns an active CU record
mysql_select_db($database_peewee, $peewee);
$query_rs_valid_cu = "SELECT * FROM tbl_cus WHERE cu_id = $pass_cu";
$rs_valid_cu = mysql_query($query_rs_valid_cu, $peewee) or die(mysql_error());
$row_rs_valid_cu = mysql_fetch_assoc($rs_valid_cu);
$totalRows_rs_valid_cu = mysql_num_rows($rs_valid_cu);
if ($totalRows_rs_valid_cu != 0) {
// Set cookie
$peewee_cu_querystring = $_GET["cu"];
$expire_month = time()+60*60*24*30; //30 days
//kill current cookie
setcookie("peewee_cu", "", time()-10);
//set new cookie
setcookie("peewee_cu", $peewee_cu_querystring, $expire_month, "/");
}
mysql_free_result($rs_valid_cu);
}
// See of cookie exists
if ((isset($_COOKIE['peewee_cu'])) && $_COOKIE['peewee_cu'] != "") {
$cu_cookie_value = $_COOKIE['peewee_cu'];
// Set values for getting CU record
$colname_rs_cu_data = $cu_cookie_value;
$load_custom_cu = 'true';
} else {
// Set defualt CU value
$colname_rs_cu_data = 10000;
$load_custom_cu = 'false';
}
// Get and Set CU Information (CU specific or default)
mysql_select_db($database_peewee, $peewee);
$query_rs_cu_data = "SELECT * FROM tbl_cus WHERE cu_id = $colname_rs_cu_data";
$rs_cu_data = mysql_query($query_rs_cu_data, $peewee) or die(mysql_error());
$row_rs_cu_data = mysql_fetch_assoc($rs_cu_data);
$totalRows_rs_cu_data = mysql_num_rows($rs_cu_data);
$cu_sidebar_image = $row_rs_cu_data['cu_logo'];
$cu_sidebar_name = $row_rs_cu_data['cu_name'];
$cu_sidebar_link = $row_rs_cu_data['cu_link'];
$cu_sidebar_address = $row_rs_cu_data['cu_address'];
$cu_sidebar_city = $row_rs_cu_data['cu_city'];
$cu_sidebar_state = $row_rs_cu_data['cu_state'];
$cu_sidebar_postal = $row_rs_cu_data['cu_postal'];
$cu_sidebar_phone = $row_rs_cu_data['cu_phone'];
$cu_sidebar_toll = $row_rs_cu_data['cu_phone_toll_free'];
$cu_meta_title = $row_rs_cu_data['cu_name'];
$cu_tab_title = $row_rs_cu_data['cu_name'];
mysql_free_result($rs_cu_data);
// Set default error page for all pages except home page
$default_error_page = 10007;
$default_error_page_home = 10005;
谢谢
布雷特