Learning & Integrating web technology and code help directory

How to use PHP & GET Method ($_GET,$HTTP_GET_VARS)

No comments
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

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <a href="php_get2.php?Name=Weerachai&SiteName=ShotDev.Com">Test  $_GET </a>  
  7. </body>  
  8. </html>  
php_get2.php

  1. <html>  
  2. <html>  
  3. <head>  
  4. <title>ShotDev.Com Tutorial</title>  
  5. </head>  
  6. <body>  
  7. <?php  
  8. echo $_GET["Name"]."<br>";  
  9. echo $_GET["SiteName"]."<br>";  
  10. ?>  
  11. </body>  
  12. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP GET
PHP GET
..
Example 2 Using $_GET from Tag <form> and Method GET
php_get3.php

  1. <html>  
  2. <html>  
  3. <head>  
  4. <title>ShotDev.Com Tutorial</title>  
  5. </head>  
  6. <body>  
  7. <form action="php_get4.php" method="get" name="form1">  
  8. Name  
  9. <input name="txtName" type="text">  
  10. SiteName  
  11. <input name="txtSiteName" type="text">  
  12. <input type="submit" name="Submit" value="Submit">  
  13. </form>  
  14. </body>  
  15. </html>  
php_get4.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?php  
  7. echo $_SERVER["REQUEST_URI"]."<br>"// URL  
  8. echo "<hr>";  
  9. echo $_GET["txtName"]."<br>"// Get txtName  
  10. echo $_GET["txtSiteName"]."<br>"// Get txtSiteName  
  11. echo "<hr>";  
  12.   
  13. foreach($_GET as $key => $val// Get All Key & Value  
  14. {  
  15. echo $key . " : " . $val . "<br>";  
  16. }  
  17. ?>  
  18. </body>  
  19. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP Concat String

No comments :

Post a Comment