在php中我们要获取 当前页面完整url地址需要使用到几个常用的php全局变量函数了,主要是以$_SERVER[]这些变量,下面我来给各位看一个获取当前页面完整url地址程序吧。
先来看一些PHP变量:
$_SERVER[ 'SERVER_NAME' ] #当前运行脚本所在服务器主机的名称。
$_SERVER[ 'QUERY_STRING' ] #查询(query)的字符串。
$_SERVER[ 'HTTP_HOST' ] #当前请求的 Host: 头部的内容。
$_SERVER[ 'HTTP_REFERER' ] #链接到当前页面的前一页面的 URL 地址。
$_SERVER[ 'SERVER_PORT' ] #服务器所使用的端口
$_SERVER[ 'REQUEST_URI' ] #访问此页面所需的 URI。
有了些面函数我们就可以开始了,先来看一些base方法.
baseUrl的两种方法
方法一代码如下:
- // baseUrl
- function baseUrl($uri=''){
- $baseUrl = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https://' : 'http://';
- $baseUrl .= isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : getenv('HTTP_HOST');
- $baseUrl .= isset($_SERVER['SCRIPT_NAME']) ? dirname($_SERVER['SCRIPT_NAME']) : dirname(getenv('SCRIPT_NAME'));
- return $baseUrl.'/'.$uri;
- }
方法二代码如下:
- /**
- * Suppose, you are browsing in your localhost
- * http://localhost/myproject/index.php?id=8
- */
- function baseUrl()
- {
- // output: /myproject/index.php
- $currentPath = $_SERVER['PHP_SELF'];
- // output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
- $pathInfo = pathinfo($currentPath);
- // output: localhost
- $hostName = $_SERVER['HTTP_HOST'];
- // output: http://
- $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://' ? 'https://' : 'http://';
- // return: http://localhost/myproject/
- return $protocol.$hostName.$pathInfo['dirname']."/";
- }
方法三代码如下:
- <?php
- /**
- *@author mckee
- *@blog http://www.phpfensi.com
- */
- function get_page_url(){
- $url = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
- $url .= $_SERVER['HTTP_HOST'];
- $url .= isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : urlencode($_SERVER['PHP_SELF']) . '?' . urlencode($_SERVER['QUERY_STRING']);
- return $url;
- }
- echo get_page_url();
- ?>
下面说明一下获取当前页面完整路径的方法,代码如下:
- <?php
- function getFullUrl(){
- # 解决通用问题
- $requestUri = '';
- if (isset($_SERVER['REQUEST_URI'])) { #$_SERVER["REQUEST_URI"] 只有 apache 才支持,
- $requestUri = $_SERVER['REQUEST_URI'];
- } else {
- if (isset($_SERVER['argv'])) {
- $requestUri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
- } else if(isset($_SERVER['QUERY_STRING'])) {
- $requestUri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
- }
- }
- // echo $requestUri.'<br />';
- $scheme = emptyempty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
- $protocol = strstr(strtolower($_SERVER["SERVER_PROTOCOL"]), "/",true) . $scheme;
- $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
- # 获取的完整url
- $_fullUrl = $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $requestUri;
- return $_fullUrl;
- }
echo getFullUrl();注:由于php没有内置的函数,我们需要对url上的参数进行组合,从而实现整个url.
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php获取当前页面完整url地址实例
波比源码 » php获取当前页面完整url地址实例
buy levofloxacin 500mg online cheap order levofloxacin online
avodart price buy avodart 0.5mg sale ondansetron sale
aldactone 100mg drug diflucan 200mg us order fluconazole 200mg pills
ampicillin 500mg oral erythromycin 250mg tablet erythromycin cost
fildena 100mg price nolvadex order robaxin online order
suhagra online order purchase suhagra pill estrace price
lamictal usa minipress pills buy tretinoin gel for sale
order tadalafil 20mg sale order avanafil 200mg for sale cheap voltaren 100mg
indomethacin uk indocin 50mg brand buy amoxicillin for sale
cialis 10mg uk Buy branded viagra buy sildenafil 50mg without prescription
vrai cialis 20mg prix sildenafil gГ©nГ©rique sildenafil 200mg gГ©nГ©rique
purchase isotretinoin pills buy accutane 10mg pill cheap stromectol
purchase clonidine generic clonidine 0.1mg price buy tiotropium bromide 9mcg sale
order terazosin 5mg generic azulfidine without prescription azulfidine without prescription
alendronate tablet buy fosamax 70mg order pepcid 20mg online
order olmesartan 20mg generic order verapamil generic acetazolamide order
zyban 150 mg brand cetirizine 10mg brand buy quetiapine 100mg without prescription
molnunat 200mg tablet naproxen 250mg drug buy lansoprazole generic
zoloft 100mg drug Pfizer viagra 50 mg online 50mg viagra
order imuran 100 mcg generic protonix 20mg drug cheap generic sildenafil
cialis 5mg uk buy generic prozac 20mg buy viagra 50mg pills
cialis coupon cvs amantadine 100mg drug buy symmetrel 100mg online cheap
order medroxyprogesterone online medroxyprogesterone for sale online cyproheptadine cheap
oral fluvoxamine cymbalta sale buy glucotrol generic
cialis 20mg for sale cheap sildenafil sale sildenafil for men
buy cialis 10mg pills buy betamethasone 20 gm creams buy generic clomipramine
itraconazole 100mg pills oral tinidazole 300mg tindamax medication
purchase glycomet online cheap order tadalafil 20mg generic cialis 5mg ca
olanzapine cost order valsartan 80mg sale diovan 80mg us
oral clozaril 100mg buy ipratropium 100mcg for sale dexamethasone 0,0,5 mg pill
sildenafil fast shipping sildenafil 25mg for sale order lisinopril 5mg pill
order linezolid 600mg generic online casino usa online slot machines real money
letter writing services win real money online casino for free best online blackjack
buy vardenafil pills order pregabalin generic methylprednisolone 16 mg tablet
professional letter writing services buying a term paper sildenafil citrate 50mg
triamcinolone medication buy desloratadine online cheap order desloratadine generic
xenical canada buy orlistat acyclovir uk
buy methotrexate 2.5mg online metoclopramide over the counter metoclopramide 10mg uk
purchase domperidone generic order sumycin online cheap flexeril 15mg canada
cost baclofen 10mg baclofen online order toradol usa
buy sumatriptan online cheap order avodart 0.5mg for sale buy dutasteride for sale
colchicine 0.5mg price spins real money online gambling meaning
ranitidine order online purchase celebrex without prescription purchase celebrex pills
casino online usa casino slot games play roulette for free
fluconazole order online viagra 50mg over the counter sildenafil citrate 50mg
cephalexin 500mg price order cephalexin 125mg generic erythromycin 500mg canada
tadalafil 20mg tablet buy tadalafil cheap generic sildenafil
ceftin 500mg drug buy cefuroxime pill robaxin drug
purchase desyrel online order aurogra 50mg oral sildenafil 100mg
brand prednisone 5mg buy amoxicillin tablets purchase amoxil sale
play roulette real casinos online no deposit tadalafil 10mg over the counter
order azithromycin 500mg pills buy prednisolone 20mg neurontin cheap
slot machine online casino for real money provigil 200mg drug
order prednisone 20mg sale vermox 100mg cheap mebendazole 100mg generic
buy sildenafil 50mg without prescription purchase sildenafil without prescription purchase rhinocort
retin order order tretinoin generic brand avana 100mg
brand tadalafil 10mg buy voltaren 100mg pill indocin drug
clarithromycin 250mg usa clarithromycin 500mg tablet antivert 25 mg over the counter
buy naprosyn 500mg online cheap lansoprazole uk oral lansoprazole
albuterol 100mcg cost order pantoprazole 40mg without prescription buy ciprofloxacin 500mg for sale
order generic montelukast 5mg order singulair 10mg sale buy sildenafil 100mg online
purchase cialis sale Approved cialis pharmacy online blackjack free
cheap tadalafil generic cialis dosage 40 mg female cialis pill
online gambling hollywood casino best casino
writing paper online buy a research paper online buy azulfidine pill
buy asacol 800mg online order azelastine for sale order irbesartan 300mg pill
temovate us generic clobetasol buy generic amiodarone 100mg
amoxicillin usa stromectol 6mg usa buy stromectol
order nortriptyline 25mg online cheap pamelor 25 mg tablet paxil 20mg generic
order indomethacin 75mg generic cenforce online order order cenforce pill
tadalafil price buy amoxicillin 500mg online cheap order trimox 250mg online cheap
minocycline online order neurontin 600mg pill terazosin 5mg oral
buy provigil 100mg online stromectol 12mg drug cheap promethazine
metformin 500mg cheap tamoxifen 10mg price tamoxifen 10mg brand
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. Onwin , Onwin Giriş , Onwin Güncel Giriş , Onwin Yeni Adres , onwin
buy generic deltasone buy accutane pill oral amoxil 500mg
Hackdra has revolutionized the web3 with its Free cyber security trainings, ethical hacking courses and artificial intelligence courses.
order generic ondansetron amoxicillin 250mg cheap bactrim buy online
ivermectin 20 mg prednisone 20mg usa prednisone pill