genzedu777 Posted June 24, 2010 Share Posted June 24, 2010 Hi, I need some help here. May I know what is the difference between $_GET and $_POST As I have seen in most codings, it comes with $_POST, does it mean that both $_GET and $_POST work the same way? Thanks, Wilson Quote Link to comment https://forums.phpfreaks.com/topic/205727-difference-between-_get-and-_post/ Share on other sites More sharing options...
conker87 Posted June 24, 2010 Share Posted June 24, 2010 $_GET as the name suggest GET's the value of the variable from the url for instance: index.php?page=about $_GET['page'] would have the value of "about." $_POST handles values from the html <form>. So. <form method="post" action=""> <input type="text" name="about" /> <input type="submit" name="submit" value="Send" /> </form> Both $_POST['about'] and $_POST['submit'] would have values (usually, you'd use the submit button to check if the form has been submitted.) Quote Link to comment https://forums.phpfreaks.com/topic/205727-difference-between-_get-and-_post/#findComment-1076521 Share on other sites More sharing options...
phpology Posted June 24, 2010 Share Posted June 24, 2010 or you could use $_REQUEST which will give you values if you have subbmited via a form or by getting params from a URL. Quote Link to comment https://forums.phpfreaks.com/topic/205727-difference-between-_get-and-_post/#findComment-1076541 Share on other sites More sharing options...
conker87 Posted June 24, 2010 Share Posted June 24, 2010 or you could use $_REQUEST which will give you values if you have subbmited via a form or by getting params from a URL.I don't find there to be many instances where you need to use $_REQUEST. In fact, the only situation I've used it in is custom confirm codes for login systems. Quote Link to comment https://forums.phpfreaks.com/topic/205727-difference-between-_get-and-_post/#findComment-1076546 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 or you could use $_REQUEST which will give you values if you have subbmited via a form or by getting params from a URL.I don't find there to be many instances where you need to use $_REQUEST. In fact, the only situation I've used it in is custom confirm codes for login systems. Strangely enough, that's the only place I've ever used it as well. Quote Link to comment https://forums.phpfreaks.com/topic/205727-difference-between-_get-and-_post/#findComment-1076682 Share on other sites More sharing options...
premiso Posted June 24, 2010 Share Posted June 24, 2010 or you could use $_REQUEST which will give you values if you have subbmited via a form or by getting params from a URL. You could, but people tend to not do this in that it is a potential security issue. Given that you should know exactly how your data is suppose to be passed to the script, so why have a "catch-all" to retrieve it? Better to code it to your needs. In an instance where you are expecting $_POST or $_GET data, as in confirmation email hashes, $_REQUEST is fine because you expect either or. But if your form is POSTing, you do not want to grab the data from $_REQUEST, because you know it should be posted and this helps "validate" (I use this term loosely as forms are easy to fake) the code and it also helps debugging so you know what form it is potentially coming from etc. Also, $_REQUEST contains more than just the $_POST / $_GET data. It also includes $_COOKIE data, which can be overwritten by $_POST / $_GET(or vice versa see the link below for the order in the 3rd notation) and, as stated above, create a potential security hole in your script. Hence why they have them broken out into separate arrays and why you should stick to using the superglobal array where you expect the data to be coming in from. http://www.php.net/manual/en/reserved.variables.request.php Quote Link to comment https://forums.phpfreaks.com/topic/205727-difference-between-_get-and-_post/#findComment-1076686 Share on other sites More sharing options...
genzedu777 Posted June 25, 2010 Author Share Posted June 25, 2010 Thanks guys for the constructive discussion. Quote Link to comment https://forums.phpfreaks.com/topic/205727-difference-between-_get-and-_post/#findComment-1077129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.