[英]Get the previous page name in PHP (not the entire URL)
I have a URL like this; 我有这样的网址;
http://www.mydomain.co.uk/blist.php?prodCodes=NC023-NC022-NC024-NCB33&customerID=NHFGR http://www.mydomain.co.uk/blist.php?prodCodes=NC023-NC022-NC024-NCB33&customerID=NHFGR
Which i grab using HTTP Referrer. 我使用HTTP Referrer抓取。 The trouble is i only need the page name ie blist.php from the link, not the entire URL as is default using:
问题是我只需要链接中的页面名称即blist.php,而不是默认使用的整个URL:
$_SERVER['HTTP_REFERER']
Can anyone give me an idea on how to grab that part of the URL? 任何人都可以给我一个关于如何获取URL部分的想法?
try with 尝试
parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH);
Note: this variable doesn't exist in mobile devices. 注意:此变量在移动设备中不存在。
Try this one: 试试这个:
basename($_SERVER['HTTP_REFERER']);
REF: http://www.php.net/manual/en/function.basename.php 参考: http : //www.php.net/manual/en/function.basename.php
basename(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH)
这将只为您提供文件名而不是任何子目录或查询字符串
/[\w-]+.php/
您可以使用正则表达式仅获取文件的名称。
I think you are looking for $_SERVER['REQUEST_URI'] which just gives you the requested page. 我想你正在寻找$ _SERVER ['REQUEST_URI'],它只是给你所需的页面。
You can review all of the $_SERVER variables here: 您可以在此处查看所有$ _SERVER变量:
http://php.net/manual/en/reserved.variables.server.php http://php.net/manual/en/reserved.variables.server.php
This seems to work, but there might be other elegant url functions . 这似乎有效,但可能还有其他优雅的url功能 。
$url = 'http://www.mydomain.co.uk/blist.php?prodCodes=NC023-NC022-NC024-NCB33&customerID=NHFGR';
preg_match('/\/[a-z0-9]+.php/', $url, $match);
$page = array_shift($match);
echo $page;
check out 查看
http://ca.php.net/manual/en/function.parse-url.php http://ca.php.net/manual/en/function.parse-url.php
focus in on the path ($_SERVER['REQUEST_URL']) portion, then do something like substr($path,strrpos($path,"/")+1); 专注于路径($ _SERVER ['REQUEST_URL'])部分,然后做一些像substr($ path,strrpos($ path,“/”)+ 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.