PHP access Global-Superglobals array Variables
Contents
In this Post We Will Explain About is PHP access Global-Superglobals array Variables With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Manipulating PHP Superglobal VariablesExample
In this post we will show you Best way to implement scope – PHP access global variable in function, hear for References all variables available in global scopewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
PHP $GLOBALS (super global) variable
$GLOBALS is a core PHP super global any palce to use variable which is used to any page access global variables from any module as well as anywhere in the PHP script or other PHP frameworks Like as a Magento,CI,Yii,Laravel..
PHP has all the predefined some array variables.
The List of PHP superglobal variables are as follows:
*-> $GLOBALS
*-> $_SERVER
*-> $_REQUEST
*-> $_POST
*-> $_GET
*-> $_FILES
*-> $_ENV
*-> $_COOKIE
*-> $_SESSION
PHP $GLOBALS variable
<?php $supr = 25; $temp = 50; function subtraction() { $GLOBALS['v'] = $GLOBALS['temp'] - $GLOBALS['supr']; } subtraction(); echo $v; ?>
PHP $_SERVER variable
<?php echo "PHP $_SERVER variable Developed By Pakainfo.com"; echo "<br>PHP_SELF:"; echo $_SERVER['PHP_SELF']; echo "<br>SERVER_NAME:"; echo $_SERVER['SERVER_NAME']; echo "<br>HTTP_HOST:"; echo $_SERVER['HTTP_HOST']; echo "<br>HTTP_REFERER:"; echo $_SERVER['HTTP_REFERER']; echo "<br>HTTP_USER_AGENT :"; echo $_SERVER['HTTP_USER_AGENT']; echo "<br>SCRIPT_NAME :"; echo $_SERVER['SCRIPT_NAME']; ?>
PHP $_REQUEST variable
<html> <body> <h1>PHP $_REQUEST variable By Pakainfo.com</h1> <form method="post" id="liveForm" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="username"> <input type="submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect username value of input field $username = $_REQUEST['username']; if (empty($username)) { echo "username is empty"; } else { echo $username; } } ?> </body> </html>
PHP $_POST variable
<html> <body> <h1>PHP $_POST variable Example</h1> <form method="post" id="liveForm" action="<?php echo $_SERVER['PHP_SELF'];?>"> Client Name: <input type="text" name="username"> <input type="submit"> </form> <hr/> <?php //using $_POST method if ($_SERVER["REQUEST_METHOD"] == "POST") { // By Pakainfo.com collect your value of input simple field $username = $_POST['username']; if (empty($username)) { echo "username is empty"; } else { echo $username; } } ?> </body> </html>
PHP $_GET variable
<html> <body> <h1>PHP $_GET variable Example</h1> <?php echo "Students " . $_GET['livename'] . " at " . $_GET['querystring']; ?> </body> </html>
I hope you have Got What is Global, Superglobal, Session variables – scope and persistance in PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.