最近在修改 一页支付遇到个重定项的小问题
$payment_modules = new payment($_SESSION['payment']);
$payment_modules->update_status();
if (($_SESSION['payment'] == '' && !$credit_covers) || (is_array($payment_modules->modules)) && (sizeof($payment_modules->modules) > 1) && (!is_object($$_SESSION['payment'])) && (!$credit_covers) ) {
$messageStack->add_session('checkout_payment', ERROR_NO_PAYMENT_MODULE_SELECTED, 'error');
}
if (is_array($payment_modules->modules)) {
$payment_modules->pre_confirmation_check();
}
if ($messageStack->size('checkout_payment') > 0) {
zen_redirect(zen_href_link(FILENAME_CHECKOUT, '', 'SSL'));
}
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函数 原型如下;
/**
* Redirect to another page or site
* @param string The url to redirect to
*/
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 == '') {
session_write_close();
header('Location: ' . $url);
} else {
session_write_close();
header('Location: ' . $url, TRUE, (int)$httpResponseCode);
}
exit();
}