This lesson will be short be cause i will talk about the php post get and the difference between the post function and the get function, and we will use the form of the last lesson php forms example
The code was like this
<?php
$username= $_POST['user'];
$password= $_POST['password'];
echo "My username is $username and my password is $password";
?>
<form action="<?php echo $PHP_SELF; ?>" method="post" >
<input name="user" type="text" value="usernam" />
<input name="password" type="password" value="password" />
<input name="submit" type="submit" value="Log in" />
</form>
And the result was:
Now let's use the GET function and see what's the difference
<?php
$username= $_GET['user'];
$password= $_GET['password'];
echo "My username is $username and my password is $password";
?>
<form action="<?php echo $PHP_SELF; ?>" method="get" >
<input name="user" type="text" value="usernam" />
<input name="password" type="password" value="password" />
<input name="submit" type="submit" value="Log in" />
</form>
The result
The same result but look at the url, the GET function shows my username and my password unlike the POST function
Notes:
- We should always use the POST function because it safe
- When you use the POST function the method must be post method="get"
I hope you learn something useful, see you next time.
No comments :
Post a Comment