PHP CodeIgniter框架中怎么获取当前页面的URL
发布网友
发布时间:2022-04-07 09:12
我来回答
共3个回答
热心网友
时间:2022-04-07 10:41
<?php
/**
* 获取当前页面完整URL地址
*/
function get_url() {
$sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
$php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
$path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
$relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);
return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
}
echo get_url();
?>
热心网友
时间:2022-04-07 11:59
$url = base_url();
这是基本的,当前页可自己设,比如$url = base_url().'index.php/welcome/page/';
热心网友
时间:2022-04-07 13:34
$_SERVER['REQUEST_URI']