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']; echo $_SERVER['SERVER_NAME'];
Cookies
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.
No comments yet (leave a comment)