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

How to perform PHP form handling using POST method?

 

1)   How to perform PHP form handling using POST method.

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

 
 

<html >

 

<head >

 

<title ></ title >

 

 

</head >

 

<body >

 

<form action =" PostHandling .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 > </html >

LoginPage.html

 

 

 

 

 

 

 
 

<?php

 

echo "<h2 >";

 

$user_db = array ( array ("ID"=>" clitus ","PWD"=>"123"),

array ("ID "=>" oliver ","PWD"=>1234 "),

array("ID"=>" manish ","PWD"=>" 789"),

array("ID"=>" joyce ","PWD"=>123456 "));// user data

 

$LoginID = $_GET ['loginID '];

// collecting value of LoginID through $_POST //superglobal variable

 

$password = $_GET ['password '];

// collecting value of Password through $_POST //superglobal variable

 

$flag = FALSE ;

 

foreach ( $user_db as $user )

 

{

 

if( $user ['ID ']== $LoginID && $user ['PWD '] == $password )

 

{

 

$flag = TRUE ;

 

break ;

 

}

 

}

 

 

if( $flag )

 

{

 

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

 

}

 

else

{

 

echo " Login Fail .... Try again ";

 

}

 

?>

 

PostHandling.php

 

 

 

 


LoginPage

 

 

ResultPage

 

 

 

Attachment: PostHandling.php


 

How to use POST function in PHP?

 

POST Method is different from GET Method that we have used previously.Here the information sent to the server is not visible in the URL so this method provides security factor.

 

//Program for POST function in PHP

<!DOCTYPE html>

<html>

<body>

<form action="Test1.php" method="post">

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

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

<br><br>

<input type = "submit"/>

</form>

</body>

</html>

 

This is Test1.php

<!DOCTYPE html>

<html>

<body>

<?php

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

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

?>

</body>

</html>

 

/*Output of the above program is:

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/Test1.php

 

 

 

In the above URL there is no information visible which is sent by the user,So Post method is more secure compared to get Method.

 

 

 

 

 

Was it useful?  




Please login to reply to this problem.