Ch-7 Method using in
PHP
Now a day , many of internet users create their personal
profile, use money transaction and other many things.
For use these modern trends, people first demand is security.
They want to safely transaction of money.
In any kind of transaction so many things are travel like,
password, OTP for mobile and email verification, debit card number.
These all data traverse between client to server, and server
to client.
So, for data traversing purpose, PHP provide use 2 method for
data transfer :
1.
Get
2.
Post
In previous chapter , you have
already seen post method program.
As like post method, you can also
code same program as get method for eg.
<html>
<body>
<fieldset
style=width:0px>
<legend>User
registration form</legend>
<form
action="form.php" method="get">
User
Name<input type ="textbox" name="text1"><br>
password<input
type="password" name="text2"><br>
<input
type="submit" name="submit" value="register">
</fieldset>
</body>
</html>
<?php
$a=$_GET['text1'];
$b=$_GET['text2'];
echo
'Welcome'.$a,"<br>";
?>
Same this program as form.php
Output:
|
|
password
Notice: Undefined index: text1 in C:\xampp\htdocs\booktutorial\form.php on line 15
Notice: Undefined index: text2 in C:\xampp\htdocs\booktutorial\form.php on line 16
Welcome
Pay
attention, in previous chapter program output
and also this output.
Firstly, you will
see in output ,two notice is appeared (Undefined index).
This is a minor error, and doesn’t impact on program output. But after all, if
you want remove such kind of error or notice you need to use isiset() function.
So, you need to add one code , that is
: if(isset($_GET['submit']))
Eg.
<html>
<body>
<fieldset
style=width:0px>
<legend>User
registration form</legend>
<form
action="form.php" method="get">
User
Name<input type ="textbox" name="text1"><br>
password<input
type="password" name="text2"><br>
<input
type="submit" name="submit" value="register">
</fieldset>
</body>
</html>
<?php
if(isset($_GET['submit']))
{
$a=$_GET['text1'];
$b=$_GET['text2'];
echo
'Welcome '.$a,"<br>";
}
?>
|
User Name
password
password
Welcome mukesh
Same isset() function , you can also
use in post method.
Difference between get and post method
GET method is less secure, because when data is transfer by get method ,
your input parameter shows in address bar .
Here, you will see your input
parameter is append with url
For eg
Try to give input “mukesh” as user
name, and password will be “1234” , then see address bar.
You will see such output:
But, in case of POST method, your data will traverse as a invisible
manner.
You will try to upper code by
replacing GET method by POST method.
When you run, Your input data
parameter is invisible. Means it is not appeared while data traversed.
$_POST[] and $_GET[]
$_POST and $_POST both are super global variable , you
can use these two variable to send data
in different page(as you already seen last chapter program , where data sent to
data.php page ) or server.
Both variable use [] bracket. Because
these two variable contains form input data in array form .
No comments:
Post a Comment