How to Get Parameters from a URL

Friendly & Normal URLs

By Scott M. Stolz

Getting Parameters from a Normal URL

Normally, parameters are sent after the ? in a URL.


To access this variable, you can use the $_GET global variable.

$articleslug = $_GET['article'];

if ($articleslug != "") {

echo "<p>Article Slug: " . htmlspecialchars($articleslug , ENT_QUOTES);   


This would assign "this-title-is-not-clickbait" to the variable $articleslug.

Getting Parameters from a Friendly URL

If you are using friendlky URLs that do not have a ?, you would use a different approach.


First, you would need to get the URL.


If you want the last part of the path, you could use this:

echo basename(parse_url($url, PHP_URL_PATH));

It's output would be: "this-title-is-not-clickbait"

But if you want the whole path, not including the ddomain name, you would use this:

echo trim(parse_url($url, PHP_URL_PATH), '/');

It's output would be "articles/this-title-is-not-clickbait"

Sanatizing Content

Don't forget to sanitize!

For output to the screen, use:

htmlspecialchars($_GET['id'], ENT_QUOTES)

For data going into a query, use:


Content for tab 2.

Content for tab 3.

How to Get Parameters from a URL

Friendly & Normal URLs

This Article:   Last Major Update: 2022-11-11   Last Minor Update: 2022-11-11   Last Verified:

Sorry, you have got no notifications at the moment...
User Menu