Posted By:
7 Mar, 2014 11:21 pm PST

How to perform PHP form handling using GET method?

 

1)               How to perform PHP form handling using GET method?

 

Get method is used to pass information from static web page to PHP or some other controller pages. When you used get method in form, after submitting information, the information which is submitted will appear in the address bar.

 

// Write a PHP application for LOGIN page using get method?

 

     
 

<html >

 

<head >

 

<title ></ title >

 

 

</head >

 

<body >

 

<form action =" GetHandling .php " method ="get ">

 

<table border ="1" align =" center ">

 

<tbody >

 

<tr >

 

<td > User Name :</td >

 

<td >< input type =" text " name =" loginID " value ="" size = "20"

placeholder =" Enter Login ID"/></td >

 

</tr >

 

<tr >

 

<td > Password :</td >

 

<td >< input type =" password " name =" password "

value ="" size ="20" placeholder =" Enter password "/></td >

 

</tr >

 

<tr >

 

<td >< input type =" submit " value =" Submit " name =" submit " /></td >

 

<td >< input type =" submit " value =" Reset " name =" reset " /></td >

 

</tr > </tbody>

 

</table > </form >

 

</body > </htm>

 

LoginPage.html

 
 
 

<?php

 

if (! isset ( $_GET ['submit ']))

// if we try to run php page without submitting information from LogoinPage

 

header ('Location : LoginPage . html ');// this willredirect it to main Login Page

 

echo "<h2 >";

 

$LoginID = $_GET ['loginID '];// collecting value of LoginID through $_GET superglobal variable

 

$password = $_GET ['password ']; // collecting value of Password

// through $_GET superglobal variable

 

if( $LoginID ==" Archi "&& $password ==" 1234 ")

 

echo " Login Successful .... <br > Welcome { $LoginID } ";

 

else

 

{

 

//header (' Location : LoginPage . html ');

 

echo " Login Fail Try again ";

 

}

 

?>

GetHandling.php

 

 

 

 


LoginPage

 

 

 

 

ResultGetForm

 

 

 

Attachment: GetHandling.php


How to use GET Method in PHP?

Client can send information to the web server  using GET method which produce long string (maximum 1024)  in server logs.Start of the GET data is from ?.User should not use GET method  because it whatever user will be sending will be visible in URL and thus its not secure for sensitive information.

 

//To show how to use GET method

<!DOCTYPE html>

<html>

<body>

<form action="test.php" method="get">

Your Name:<input type = "text" name = "yourname"/>

Last Name:<input type = "text" name = "lastname"/>

<br><br>.<input type = "submit"/>

</form>

</body>

</html>

 

 This is test.php file .

 

<html>

<body>

<?php

 echo("Your Name:".$_GET['yourname']."<br/>\n");

 echo("Last Name:".$_GET['lastname']."<br/>\n");

 ?>

 

</body>

</html>

 

 
Output

Your Name:

Joy

 

Last Name:

Felice

 

Submit Query

 

On clicking Submit button you will se the following:

Your Name:

Joy

Last Name:

Felice

 

And also URL wil be visible as:

http://localhost/phpIntern/test.php?yourname=Joy&lastname=Felice

 

Here the information sent to the server is visible in the URL.So this this not secure.

 

 

 

 

 

 

Attachment: get.php
Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud