PHP HTML GET

From CoderLearner
Jump to: navigation, search

PHP $_GET

$_GET gets the HTTP GET REQUEST values.

Syntax $_GET

$_GET['Name']

Note

HTTP GET REQUEST passes information through the URL. It is considered not very secure.

Example 1: Display all the forms elements process by the HTTP GET REQUEST

<?php
if ($_GET) {
   print_r($_GET);
}
?>

<html>
   <head>
      <title>GET</title>
   </head>
   <body>
   <html>
      <head>
         <title>Reset password</title>
      </head>
      <body>
         <p>Provide your email address to reset your password</p>
         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
            Email:<input type="text" name="email"/><br/>
            <input type="submit" name="rset_pwd" value="Request"/><br/>
         </form>
      </body>
   </html>
</body>
</html>

Try It

Example 2

<?php
if (!empty($_GET['email'])) {
   echo 'Your email address: ' . $_GET['email'];
} else {
   echo 'Need a valid email address';
}
?>

<html>
   <head>
      <title>GET</title>
   </head>
   <body>
   <html>
      <head>
         <title>Reset password</title>
      </head>
      <body>
         <p>Provide your email address to reset your password</p>
         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
            Email:<input type="text" name="email"/><br/>
            <input type="submit" name="rset_pwd" value="Request"/><br/>
         </form>
      </body>
   </html>
</body>
</html>

Try It