Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Using global variables in PHP

Tuesday, January 29th, 2013 by Servage

Have you ever wondered how you get access to parameters passed to your PHP scripts via a request? Well, it’s fairly simple and PHP provides a range of global variables which are available to you as a developer. Mainly they help you to get access to dynamic information or params.

POST and GET parameters

These params are passed either as part of the URL or posted from a form. You can access them like this:

// Get a param
echo $_POST['param'];
echo $_GET['param'];

// It even works like arrays
echo $_POST['param']['subparam'];

Server paremeters

The $_SERVER global provides various information about the executed script and environment.

// Information from the server
echo $_SERVER['PHP_SELF'];


the $_COOKIE global provides possibilities to store and read cookies from the browser.

// Set and get Cookie data
$_COOKIE['param'] = 'value';
echo $_COOKIE['param'];

There are plenty of more useful PHP globals which you can see here.

Using global variables in PHP, 4.8 out of 5 based on 4 ratings
Categories: Guides & Tutorials, Tips & Tricks


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet (leave a comment)

You are welcome to initiate a conversation about this blog entry.

Leave a comment

You must be logged in to post a comment.