$_GET METHOD

  • In PHP we get user input via html forms by the use of two superglobal methods called the $_GET and $_POST
  • In get method data is sent along the address bar of the browser and is visble to everyone
  • So this makes it not suitable for Passwords and Sensitive Information
  • The values are passed after the question mark ‘?’
  • When there are more than 1 Parameters they are separated by an ampersand
  • Not more than 2000 characters can be sent along with the get method
  • An example snippet is given below
<form action="process.php" method="get">
Username:<input type="text" name="username" />
Password:<input type="text" name="password" />
<input type="submit" name="submit" value="submit"/>
</form>
  • It will be sent as for example
 http://www.scriptsnippets.com?username=sathesh&password=sathesh
  • We can use this passed data on the other page using the following snippet
Your Name:<?php echo $_GET["username"];?>
Password :<?php echo $_GET["password"];?>
  • Note: Be Aware of Sql Injection attacks when using a mysql database and look for proper methods to prevent sql injection attacks.

$_POST METHOD

  • $_POST method is used to send considerable amount of user data recieved via userinputs consider for example an text area in which we want to store a entire paragraph.
  • Here the values are not visible on the address bar.
  • So it is safe to transmit password and sensitive information
  • An example snippet is given below
<form action="process.php" method="post">
Username:<input type="text" name="username" />
Password:<input type="text" name="password" />
<input type="submit" name="submit" value="submit"/>
</form>
  • We can use the passed data on the other page using the following snippet
    Your Name:<?php echo $_POST["username"];?>
    Password :<?php echo $_POST["password"];?>
  • Note: We can change the maximum size of data that is transferred in php.ini file by changing the ‘post_max_size’.

$_REQUEST METHOD

  • The Request method stores all the passed information via the $_POST,$_GET,$_COOKIE methods
  • So when we are not sure of what method we have used in the form input we can use the $_REQUEST METHOD to obtain the data that is posted or set
  • The example Snippet is given below
Your Name:<?php echo $_REQUEST["username"];?>
Password :<?php echo $_REQUEST["password"];?>

About Sathesh Bm

Sathesh Bm has written 26 post in this website.

Engineer, Web Lover, Thinker, Blogger

Related Posts Plugin for WordPress, Blogger...