开发者

PHP URL Redirect (Getting full URL + GET)

开发者 https://www.devze.com 2023-02-12 00:39 出处:网络
How would I get just the last part to my URL? Ex. ?page=home&optional=lol I am not f开发者_开发技巧amiliar with any of the server commands, so much help would be appreciated. Also note that th

How would I get just the last part to my URL?

Ex.

?page=home&optional=lol

I am not f开发者_开发技巧amiliar with any of the server commands, so much help would be appreciated. Also note that the GET variables are dynamic and will be different.


The QUERY_STRING server variable should be what you're looking for:

$_SERVER['QUERY_STRING'];


Use parse_url

Getting the full URL of the page is a bit complicated, but not very:

$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"];
}
$parsed_url = parse_url($pageURL);
$qs = $parsed_url['query']; //query string, this is the ? part of the URL


This can be found in $_SERVER['REQUEST_URI']

0

精彩评论

暂无评论...
验证码 换一张
取 消