Hey all,
I know generally POST is better for security but I'm just a little confused on which is best to use here. I was mucking around trying to get a random script to work. Now I have questions 😕
If I use the GET method in the script below I don't need to write the complete URL in the action field. Naturally the code works as expected with a url of page.php?display=show_yes or no
<?php
if ($_GET['display'] == 'show_yes')
{
echo '<p>Success, showing the text!</p>';
}
if ($_GET['display'] == 'show_no')
{
echo '<p>Nope, not showing the text!</p>';
}
?>
<form name="yes" method="get" action="page.php?display">
<input type="hidden" name="display" value="show_yes">
<a href ="#" onclick='document.yes.submit();'>submit</a>
</form>
<br>
<form name="no" method="get" action="page.php?display">
<input type="hidden" name="display" value="show_no">
<a href ="#" onclick='document.no.submit();'>submit2</a>
</form>
Now if I use the POST method I must write the full URL in the action field. If I don't it just displays the URL as page.php?display
<?php
if ($_POST['display'] == 'show_yes')
{
echo '<p>Success, showing the text!</p>';
}
if ($_POST['display'] == 'show_no')
{
echo '<p>Nope, not showing the text!</p>';
}
?>
<form name="yes" method="POST" action="page.php?display">
<input type="hidden" name="display" value="show_yes">
<a href ="#" onclick='document.yes.submit();'>submit</a>
</form>
<br>
<form name="no" method="POST" action="page.php?display">
<input type="hidden" name="display" value="show_no">
<a href ="#" onclick='document.no.submit();'>submit2</a>
</form>
It's 5:12am and I haven't had any coffee I don't know what I'm trying to ask but what the hell is the difference? The script is simple but would it matter when displaying information or something?
Cheers