PHP: how to get request path and query string included

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.

There are two different variables:

$_SERVER[‘REQUEST_URI’] and $_SERVER[‘REQUEST_URL’]

URI provides the entire request path (/directory/file.ext?query=string)
URL provides the request path, without the query string (/directory/file.ext)

If you want to paste in a web page be sure to clean it up first with htmlspecialchars() otherwise it poses a cross-site scripting vulnerability.

htmlspecialchars($_SERVER[‘REQUEST_URI’]);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: