$_GET and $_POST

$_GET සහ $_POST කියන්නේ php වල use වෙන global variables දෙකක්. Global variables වල තියෙන විශේෂ දේ තමයි php script එකේ ඕනෑම තැනකදී මේ variables call කරන්න පුළුවන්. පොදුවේ ගත්තම $_GET හා $_POST variables දෙකම අපි භාවිතා කරන්නේ web application එකකදී user කෙනෙක් enter කරන data collect කරගැනීමට.

$_GET
$_GET method එකෙන් අපි collect කරන data අපේ browser එකේ address bar එකෙන් පෙන්නනවා. ඒ වගේම characters 100ක් වෙනකම්  විතරයි $_GET method එකෙන් collect කරගන්න පුළුවන්.

<?php
if(isset($_GET["submit"])){
$name=$_GET["name"];
$age=$_GET["age"];
echo "Hi $name, You are $age years old";
}
?>

<html>
<body>
<form method="GET">
Your Name<input type="text" name="name"> <br/>
Your Age<input type="text" name="age"> <br/>
<input type="Submit" name="submit" Value="Enter">
</form>
</body>
</html>

මේ තියෙන්නේ අපේ html interface එක. දැන් අපි data enter කරලා බලමු. 


දැන් form එක fill කරලා enter කරමු.




$_POST
$_POST method එකේ enter කරන data address bar එකේ පෙන්නන්නේ නෑ. ඒ නිසා enter කරන data වලට හොඳ security එකක් ලැබෙනවා. Password එහෙම enter කරනකොට use වෙන්නේ මේ method එක. දැන් කලින් කරපු example එකම method එකෙන් කරලා බලමු.

<?php
if(isset($_POST["submit"])){
$name=$_POST["name"];
$age=$_POST["age"];
echo "Hi $name, You are $age years old";
}
?>
<html>
<body>
<form method="POST">
Your Name<input type="text" name="name"> <br/>
Your Age<input type="text" name="age"> <br/>
<input type="Submit" name="submit" Value="Enter">
</form>
</body>

</html>

Form එක fill කරලා enter කරාම

 


මෙතන අපි isset() function එක පාවිච්චි කරලා තියනවා. මෙහෙදී වෙන්නේ මොකක් හරි variable එකක් set වෙලාද නැද්ද කියලා බලන එක. Set වෙලා තිබුනොත් තමයි code එක run වෙන්නේ.