在php中有系统自带的全局变量$_SERVER,里面有很多参数,下面我来介绍获取URL完整路径程序代码有需要的朋友可参.
举例 URL : http://www.phprm.com/Test/Test.php,代码如下:
$_SERVER['SERVER_NAME']:www.phprm.com $_SERVER['SERVER_PORT']:80 $_SERVER['REQUEST_URI']:/Test/Test.php
那我们把上面几句结合起来就可以实现了,URL完整路径为:
"http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']
如果你是开了端口号,我们可以使用$_SERVER['SERVER_PORT']就好了,上面的代码修改一下即可,代码如下:
"http://".$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']
大家要注意一点:
$_SERVER['PHP_SELFT']与$_SERVER['SCRIPT_NAME']和$_SERVER['REQUEST_URI']和$_SERVER['QUERY_STRING']的区别:
$_SERVER['PHP_SELF']会返回/phptour/test7.php/a=b,会返回文件名/后面的内容 $_SERVER['SCRIPT_NAME']只会返回/phptour/test.php,不会返回文件名后面的/后面的内容 http://localhost:60/phptour/test/test7.php/a=b $_SERVER['PHP_SELF']将得到:/phptour/test/test7.php/a=b $_SERVER['SCRIPT_NAME']将得到:/phptour/test/test7.php $_SERVER['REQUEST_URI']将得到:/phptour/test/test7.php/a=b $_SERVER['QUERY_STRING']将得到:''
永久地址:
转载随意~请带上教程地址吧^^

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
