> Zencart中文手册 > zen_redirect函数

zen_redirect 函数的功能是做重定向,也可以说是页面调转函数 。该函数在includes/functions/functions_general.PHP 文件中定义 第一个参数就是调转页面的URL地址,如果是站内地址的话,可以使用zen_href_link()函数来生成地址,如果是站外地址的话,可以直接输入URL地址,包含http://开头的,第二个参数就是返回的HTTP响应码,一般情况下不使用该参数,这个参数跟php函数void header ( string $string [, bool $replace = true [, int $http_response_code ]] )
的最后一个参数一样,具体可以参考PHP函数
zen_redirect函数 原型如下;
function zen_redirect($url, $httpResponseCode = ”) {
global $request_type;
// Are we loading an SSL page?
if ( (ENABLE_SSL == ‘true’) && ($request_type == ‘SSL’) ) {
// yes, but a NONSSL url was supplied
if (substr($url, 0, strlen(HTTP_SERVER . DIR_WS_CATALOG)) == HTTP_SERVER . DIR_WS_CATALOG) {
// So, change it to SSL, based on site’s configuration for SSL
$url = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . substr($url, strlen(HTTP_SERVER . DIR_WS_CATALOG));
}
}

// clean up URL before executing it
while (strstr($url, ‘&&’)) $url = str_replace(‘&&’, ‘&’, $url);
while (strstr($url, ‘&&’)) $url = str_replace(‘&&’, ‘&’, $url);
// header locates should not have the & in the address it breaks things
while (strstr($url, ‘&’)) $url = str_replace(‘&’, ‘&’, $url);

if ($httpResponseCode == ”) {
header(‘Location: ‘ . $url);
session_write_close();
} else {
header(‘Location: ‘ . $url, TRUE, (int)$httpResponseCode);
session_write_close();
}

exit();
}