PHP生成HTML纯静态网页程序代码
在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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
