If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Using $_GET and $_POST

Php Get and Post

Lecture

Introduction

In php you have alot of functions that you use many over and over again, but the 2 i've come to use
the most are the '$_GET' and '$_POST' functions. I have just mislead you by calling them functions
though since they are not. They are part of the group of called 'superglobal variables'. 'Superglobal
variables' are predefined variables in PHP, and they are available in all scopes throughout a script.
Here is a list of all the global variables.

$GLOBALS

$_SERVER

$_GET

$_POST

$_FILES

$_COOKIE

$_SESSION

$_REQUEST

$_ENV

*note - I call these functions in the tutorial because its easier to say then superglobalWhat Is It For?

The get and post variables are for sending data from one page to another. For example you have a form with a textbox named 'name'. When you click the button in the form, it will pass what ever data is in the textbox to the next page and using get and post you must retrieve it. This can come in handy in many scenarios, that involve user information needing to be send into a database.

My Personal Method

I don't know if everyone does it like this, if its just me, or if a few others do or not, but I use get and post each in a certain way though they can be used in the exact same manner as one another. In my opinion putting data inside the url (ex. 'localhost/index.php?user=info&pass=moreinfo') looks exetremely tacky and unorganized, as well as hard to memorize. I like my users to understand what the url says as well, i want them to be able to come back to an exact page easily. So i use post when passing data, but when handling stuff such as a webpage with mulitple outputs i would use get.

Whats The Difference

There is a small but at the same time a very major difference in get and post. When using get all the information being gained must be taken from the url, thus giving you long url names. Though post is completely hidden from all user eyes(comes in handy for passing a password). You may say, 'well why not always use post'. Simple answer there, you can't, post can only be accessed when passing on data inside of a form. Meaning that in order to make your websites better, your gonna have to manage to mix in a bit of both.

Coding

Introduction

We all know that the lecture part of anything is boring but its also always necessary. Alot of tutorials
just give the code instead of explain it. In doing so, leaves the readers confused to what they're doing
and unable to help others with the knowledge. Now that that parts over lets get into the code though.
In this tutorial were gonna be developing a login system, but the system will not be complete until my
next tutorial. In this tutorial were gonna learn the basics of multipages inside of one file, and sending
and echoing data through the server.

Down To Code

Okay to start were gonna need to design the page, lucky for you i've already done that since this is a php
tutorial not a css one i don't wanna stray from what were here to learn.

the code is explained in the comments, and there we have a functional login system, keep looking around for my next tutorial, which will explain creating the session to keep them logged in and use mysql to store accounts and retrieve info from there.