How to use PHP & GET Method ($_GET,$HTTP_GET_VARS) Learn PHP how to using GET method and read a php variable from $_GET method.
ShotDev Focus:
- Using PHP & $_GET method.
Example 1 Using $_GET from URL QueryString
php_get1.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <a href="php_get2.php?Name=Weerachai&SiteName=ShotDev.Com">Test $_GET </a> </body> </html>
php_get2.php
<html> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <?php echo $_GET["Name"]."<br>"; echo $_GET["SiteName"]."<br>"; ?> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_get1.php
Screenshot
..
Example 2 Using $_GET from Tag <form> and Method GET
php_get3.php
<html> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form action="php_get4.php" method="get" name="form1"> Name <input name="txtName" type="text"> SiteName <input name="txtSiteName" type="text"> <input type="submit" name="Submit" value="Submit"> </form> </body> </html>
php_get4.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <?php echo $_SERVER["REQUEST_URI"]."<br>"; // URL echo "<hr>"; echo $_GET["txtName"]."<br>"; // Get txtName echo $_GET["txtSiteName"]."<br>"; // Get txtSiteName echo "<hr>"; foreach($_GET as $key => $val) // Get All Key & Value { echo $key . " : " . $val . "<br>"; } ?> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_get2.php
Screenshot
3gymnastic…
…