1

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

Ex.

?page=home&optional=lol

I am not familiar with any of the server commands, so much help would be appreciated. Also note that the GET variables are dynamic and will be different.

0

3 Answers 3

3

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

$_SERVER['QUERY_STRING'];
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Why parse the whole thing? $_SERVER['QUERY_STRING'] already provides the query string.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.