在php获取一个url地址我会使用到超级全局变量$_SERVER,他包括了各种参数获取,如HTTP_HOST、PHP_SELF、QUERY_STRING等等,这里就不介绍了。
PHP获取URL的几个函数介绍,代码如下:
- <?php
- //获取域名或主机地址
- echo $_SERVER['HTTP_HOST']."<br>";
- //获取网页地址
- echo $_SERVER['PHP_SELF']."<br>";
- //获取网址参数
- echo $_SERVER["QUERY_STRING"]."<br>";
- //来源网页的详细地址
- echo $_SERVER['HTTP_REFERER']."<br>";
- ?>
把上面的几个函数组合一下,即可得到完整的URL地址,代码如下:
- <?php
- // 说明:获取完整URL
- function curPageURL()
- {
- $pageURL = 'http';
- if ($_SERVER["HTTPS"] == "on")
- {
- $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;
- }
- ?>
定义该函数之后就可以直接调用了,代码如下:
- <?php
- echo curPageURL();
- ?>
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » PHP获取地址栏URL函数
波比源码 » PHP获取地址栏URL函数
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
Great post thank you. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
Good info. Lucky me I reach on your website by accident, I bookmarked it. Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Onwin , Onwin Giriş , Onwin Güncel Giriş , Onwin Yeni Adres , onwin
Nice article inspiring thanks. Hello Administ . Onwin , Onwin Giriş , Onwin Güncel Giriş , Onwin Yeni Adres , onwin
247579 531575Fantastic write-up mate, keep the great work, just shared this with ma friendz 383059
127713 394161Take a peek at the following tips what follows discover perfect strategy to follow such a mainly because you structure your small business this afternoon. earn cash 484767