search
Homephp教程php手册php获取当前页面地址多种方法(附教程),php当前

php获取当前页面地址多种方法(附教程),php当前

php获取当前页面地址多种方法

有关php取得当前页面地址的多种方法,包括收集的一些实例教程,记录下。

参考教程:

PHP中获取当前页面的完整URL

php获取当前页面地址参数的三种方法

php获取url地址栏与详细参数实例

php获取当前域名与url地址的例子

php获取当前URL地址

php取得当前页面完整url地址的例子

PHP代码:

<span>//</span><span>获取域名或主机地址 </span>
<span>echo</span> <span>$_SERVER</span>['HTTP_HOST']."<br>"; <span>#</span><span>localhost

//获取网页地址 </span>
<span>echo</span> <span>$_SERVER</span>['PHP_SELF']."<br>"; <span>#</span><span>/blog/testurl.php

//获取网址参数 </span>
<span>echo</span> <span>$_SERVER</span>["QUERY_STRING"]."<br>"; <span>#</span><span>id=5

//获取用户代理 </span>
<span>echo</span> <span>$_SERVER</span>['HTTP_REFERER']."<br>"<span>;

</span><span>//</span><span>获取完整的url www.jbxue.com</span>
<span>echo</span> 'http://'.<span>$_SERVER</span>['HTTP_HOST'].<span>$_SERVER</span>['REQUEST_URI'<span>];
</span><span>echo</span> 'http://'.<span>$_SERVER</span>['HTTP_HOST'].<span>$_SERVER</span>['PHP_SELF'].'?'.<span>$_SERVER</span>['QUERY_STRING'<span>];
</span><span>#</span><span>http://localhost/blog/testurl.php?id=5

//包含端口号的完整url</span>
<span>echo</span> 'http://'.<span>$_SERVER</span>['SERVER_NAME'].':'.<span>$_SERVER</span>["SERVER_PORT"].<span>$_SERVER</span>["REQUEST_URI"<span>]; 
</span><span>#</span><span>http://localhost:80/blog/testurl.php?id=5

//只取路径</span>
<span>$url</span>='http://'.<span>$_SERVER</span>['SERVER_NAME'].<span>$_SERVER</span>["REQUEST_URI"<span>]; 
</span><span>echo</span> <span>dirname</span>(<span>$url</span>);

获取当前页面的位置,怎定义php函数

你的数据库都是有规律的啊,首页-产品中心-钢铁,这个面包屑导航首页不用说你也知道的,你现在所在的是钢铁页面,这个钢铁的上级栏目相信你很容易就能获取到的吧!
 

php函数获得当前所在页面的url

你可以看看这个:
A.php:


先点我,然后注意URL
点击我到b.php


B.php:



echo '刚刚的网页的URL是:'.$_SERVER['HTTP_REFERER'];
?>

----------------------------------------------------------------
.$_SERVER['HTTP_REFERER'];
获得上一级的URL
 
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools