开发用到的函数,获取当前页面的URL,自动识别HTTP和HTTPS、端口。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /* 获取当前页面完整URL */ if (!function_exists( 'huayi_page_url' )) { function huayi_page_url(){ $pageURL = 'http' ; if (! empty ( $_SERVER [ "HTTPS" ])) { $pageURL .= "s" ; } $pageURL .= "://" ; if ( $_SERVER [ "SERVER_PORT" ] != "80" ) { $pageURL .= $_SERVER [ "SERVER_NAME" ] . ":" . $_SERVER [ "SERVER_PORT" ] . $_SERVER [ "REQUEST_URI" ]; } else { $pageURL .= $_SERVER [ "SERVER_NAME" ] . $_SERVER [ "REQUEST_URI" ]; } return $pageURL ; } } |
使用方法:
1 | echo huayi_page_url(); |