获取PHP中的上一页名称(不是整个URL)

I have a URL like this;

http://www.mydomain.co.uk/blist.php?prodCodes=NC023-NC022-NC024-NCB33&customerID=NHFGR

Which i grab using HTTP Referrer. The trouble is i only need the page name i.e. blist.php from the link, not the entire URL as is default using:

$_SERVER['HTTP_REFERER']

Can anyone give me an idea on how to grab that part of the URL?

This seems to work, but there might be other elegant url functions.

$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;
/[\w-]+.php/

you can use the regular expression to get only name of the file.

try with

parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH);

Note: this variable doesn't exist in mobile devices.

I think you are looking for $_SERVER['REQUEST_URI'] which just gives you the requested page.

You can review all of the $_SERVER variables here:

http://php.net/manual/en/reserved.variables.server.php

check out

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);

Try this one:

basename($_SERVER['HTTP_REFERER']);

REF: http://www.php.net/manual/en/function.basename.php

basename(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH)

This will give you just file name not any sub-directories or the query string