Jump to content

$_GET or $_POST?


Maverickb7

Recommended Posts

If you are dealing with submitting data from a form I would use the POST method and use $_POST to retrieve the submitted data. 99% of the time. I rarely use the GET method on a form to submit data as the data is showing in the URL which may show personal information, such as passwords etc. POST is more secure as it is hidden and the user can't see what data is being submitted.

The only time I use $_GET is on links when I need to send variables to my script to show different information. When I'm send data over the url I usually only accept certain keywords/numbers to be sent over. Such as if I only want numerical data to be sent over the URL I'll check the data that is being sent is a of a numerical value like so:
[code]<a href="?var=0125698">Send 0125698 over the url</a> | <a href="?var=hello">Send hello over the url</a>
<hr />
<?php

if(isset($_GET['var']) && is_numeric($_GET['var']))
{
    echo "Var is number!";
}
else
{
    die("<b>Script Terminated</b> - No/Invalid data being sent!");
}

?>[/code]When you run the script the first time it'll display:
[b]Script Terminated[/b] - No/Invalid data being sent!

Untill you click the first link. When you click the secound link it'll show the above message.

You should always validate any user input from any user as you don't know who is sending what to your page. The same applies to $_POST too.
Link to comment
https://forums.phpfreaks.com/topic/7465-_get-or-_post/#findComment-27194
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.