Table of Contents
php superglobal variables introduction
PHP में कई सारे predefined global variable है|. उसे superglobal variable बी कह सकते है वह Php के inbuilt variable है!. जिसे में functions, class, file में बिना कुछ उसके लिए create किये access कर सकते है!. superglobal variable एक project files में कही बी access किये जा सकते है!. क्यों की वह variable का scope global होता है!. superglobal variables php के array variable है|.
php superglobal variables जैसे की
- $GLOBALS
- $_SERVER
- $_REQUEST
- $_POST
- $_GET
- $_FILES
- $_ENV
- $_COOKIE
- $_SESSION
php $GLOBALS variable
$GLOBALS php का superglobal variable है!. और php में global variable सहित सभी superglobal variable शामिल है!.PHP $GLOBALS[“index”] नाम के इंडेक्स में सभी globalvariable को store करता है!.
$GLOBALS variable के example के जरिये समझने की कोसिस करते है!.
Example:
<?php
$a = 10;
$b = 40;
function val_multiplication() {
$GLOBALS["c"] = $GLOBALS["a"] * $GLOBALS["b"];
}
val_multiplication();
echo $c;
?>
output
400
php $_SERVER variable
$_SERVER PHP का superglobal variable है!. $_SERVER के array variable में headers, file path, and script location जैसी information hold करके रखता है!. और सभी information server provide करता है!.
Example:
<?php
echo $_SERVER["PHP_SELF"];
echo "<br>";
echo $_SERVER["SERVER_NAME"];
echo "<br>";
echo $_SERVER["HTTP_HOST"];
echo "<br>";
echo $_SERVER["HTTP_REFERER"];
echo "<br>";
echo $_SERVER["HTTP_USER_AGENT"];
echo "<br>";
echo $_SERVER["SCRIPT_NAME"];
?>
| Code | Description |
| $_SERVER[‘PHP_SELF’] | इसका इस्तेमाल currently execute हो रही script की filename को display करने के लिए. |
| $_SERVER[‘GATEWAY_INTERFACE’] | इसका इस्तेमाल common gateway interface का version display करने के लिए होता है जो server इस्तेमाल कर रहा हैi. |
| $_SERVER[‘SERVER_NAME’] | इसका इस्तेमाल server name display करने के लिए होता हैi. |
| $_SERVER[‘SERVER_ADDR’] | इसका इस्तेमाल host server का IP address को display करने के लिए होता है!. |
| $_SERVER[‘SERVER_SOFTWARE’] | इसका इस्तेमाल server identification string display करने के लिए होता है!. |
| $_SERVER[‘SERVER_PROTOCOL’] | इसका इस्तेमाल infromation protocol का नाम और revision display करने के लिए होता है!. |
| $_SERVER[‘REQUEST_METHOD’] | इसका इस्तेमाल page तक पोहचने के लिए या page पर data send करने के लिए इस्तेमाल की जनि वाली method को display करता है!. methods जैसे की “GET”,”POST” |
| $_SERVER[‘REQUEST_TIME’] | यह request की शरुआत के timestamp display करता है!. |
| $_SERVER[‘QUERY_STRING’] | अगर pages को query string से access किया जाता है तो वह query string को display करता है!. |
| $_SERVER[‘HTTP_ACCEPT’] | इसका इस्तेमाल current request मेसे header को display करने के लिए किया जाता है!. |
| $_SERVER[‘HTTP_ACCEPT_CHARSET’] | इसका इस्तेमाल current request मेसे Accept_Charset header को display करने के लिए किया जाता है!. |
| $_SERVER[‘HTTP_HOST’] | इसका इस्तेमाल current request मेसे Host header को display करने के लिए किया जाता है!. |
| $_SERVER[‘HTTP_REFERER’] | इसका इस्तेमाल page का पूरा url display करने के लिए किया जाता है!. |
| $_SERVER[‘HTTPS’] | यह दिखता है की क्या script को secure HTTP protocol के माद्यम से दिखाया गया है!. |
| $_SERVER[‘REMOTE_PORT’] | इसका इस्तेमाल webserver के साथ communication करने के लिए user के machine पर इस्तेमाल किये जा रहे port को display करने के लिए होता है!. |
| $_SERVER[‘SCRIPT_FILENAME’] | इसका इस्तेमाल currently execute script का full pathname display करने के लिए किया जाता है!. |
| $_SERVER[‘SERVER_ADMIN’] | यह webserver configuration file में SERVER_ADMIN निर्देश को दिए गए value को display करने के लिए इस्तेमाल किया जाता है!. |
| $_SERVER[‘REMOTE_ADDR’] | इसका इस्तेमाल IP address को display करने के लिए किया जाता है की user page view कहा से कर रहा है!. |
| $_SERVER[‘REMOTE_HOST’] | इसका इस्तेमाल hostname को display करने के लिए किया जाता है!. जहा से user current page देख रहा है!. |
| $_SERVER[‘SERVER_SIGNATURE’] | इसका इस्तेमाल server version और virtual host name display करने के लिए किया जाता है. जो server-generated pages जोड़े जाते है!. |
| $_SERVER[‘PATH_TRANSLATED’] | इसका इस्तेमाल current script में file system के आधार पर path display करने के लिए किया जाता है!. |
| $_SERVER[‘SCRIPT_NAME’] | current scripts path को display करने के लिए इस्तेमाल किया जाता है!. |
| $_SERVER[‘SCRIPT_URI’] | current pages के URL display करने के लिए इस्तेमाल किया जाता है!. |
php $_REQUEST variable
$_REQUEST php का superglobal variable है!. जिसके इस्तेमाल server-side में data को callect करने के लिये किया जाता है!. data जैसे की HTML form का data user submit करता है तो उस data को server-side collect करना पड़ता है तो इसके लिए हम $_REQUEST variable का बी इस्तेमाल कर सकते है!. उसके आलावा url में pass की गई query string value को get करने लिए बी $_REQUEST varible का खास इस्तेमाल किया जाता है|.Query string Example
Example:
http://localhost/test/test.php?lastname=rahul&firstname=Test
<?php
if ( !empty( $_REQUEST["firstname"] ) || !empty( $_REQUEST["lastname"] ) ) {
$firstname = $_REQUEST["firstname"];
$lastname = $_REQUEST["lastname"];
echo"FirstName is". $firstname;
echo"LastName is". $lastname;
}
?>
output
FirstName is Test
LastName is rahul
Example1:
<html>
<body>
<?php
if ( !empty( $_REQUEST["firstname"] ) || !empty( $_REQUEST["lastname"] ) ) {
$firstname = $_REQUEST["firstname"];
$lastname = $_REQUEST["lastname"];
echo"FirstName is". $firstname;
echo"LastName is". $lastname;
}
?>
<form action="#" method="post">
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" name="firstname" class="form-control" id="firstname">
</div>
<div class="form-group">
<label for="lastname">Lastname:</label>
<input type="text" name="lastname" class="form-control" id="lastname">
</div>
<input type="submit" class="btn btn-default" value="submit">
</form>
</body>
</html>
output
FirstName is Test
LastName is rahul
php $_POST variable
HTML form data को server side में collect करने के लिए खास करके $_POST का ही इस्तेमाल किया जाता है!. $_POST php का एक superglobal variable है!.
Example:
<html>
<body>
<?php
if ( !empty( $_POST["firstname"] ) || !empty( $_POST["lastname"] ) ) {
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
echo"FirstName is". $firstname;
echo"LastName is". $lastname;
}
?>
<form action="#" method="post">
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" name="firstname" class="form-control" id="firstname">
</div>
<div class="form-group">
<label for="lastname">Lastname:</label>
<input type="text" name="lastname" class="form-control" id="lastname">
</div>
<input type="submit" class="btn btn-default" value="submit">
</form>
</body>
</html>
output
FirstName is Test
LastName is rahul
php $_GET variable
HTML form data को server side में collect karne के liye $_GET variable का बी इस्तेमाल कर सकते है. $_GET variable php का एक superglobal variable है!. $_GET variable से query-string value को collect कर सकते है|
Example:
http://localhost/test/test.php?lastname=rahul&firstname=Test
OR
<html>
<body>
<form action="#" method="get">
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" name="firstname" class="form-control" id="firstname">
</div>
<div class="form-group">
<label for="lastname">Lastname:</label>
<input type="lastname" class="form-control" id="lastname">
</div>
<input type="submit" class="btn btn-default" value="submit">
</form>
</body>
</html>
<?php
if ( !empty( $_GET["firstname"] ) || !empty( $_GET["lastname"] ) ) {
$firstname = $_GET["firstname"];
$lastname = $_GET["lastname"];
echo"FirstName". $firstname;
echo"LastName ". $lastname;
}
?>
output
FirstName is Test
LastName is rahul
php $_FILES[“FormElementName”]
$_FILES php का superglobal variable है!. जिसके इस्तेमाल client machine से images files को server में upload करने के लिए इस्तेमाल करने के लिए किया जाता है!.
और
$_FILES[“FormElementName”][“ArrayIndex”] जिसमे image file की filename, filetype, filesize, file temporary name जैसी information get कर सकते है!.
php $_SESSION[“VariableName”]
$_SESSION php का एक superglobal variable है!. एक session variable का इस्तेमाल user के बारे में information store करने के लिए किया जाता है|. एक web application के सभी pages में इस session variable का इस्तेमाल किया जा सकता है!.
php COOKIE[“VariableName”]
user की पहचान करने के लिए cookie का इस्तेमाल किया जाता है!. cookie एक small file होती है जो user के machine में store होती है!.






