Page 1 of 1
Get `n post
Posted: Sat Mar 20, 2004 7:06 pm
by [n00b]
Hello. First post here
See my nick? Then don`t laugh at my questions!!!
Ok, here it is:
Whats the difference between GET and POST methods? Any examples?
Say I make a form containing a text field and a submit button which when pressed sends the data in the text field and saves it in a db. Which should I use in this case?[/php_man]
Posted: Sat Mar 20, 2004 7:13 pm
by tim
hi
you'll see this at
<form action="page.php" method=POST>
generically speaking, POST is when you send variables to a different location. the above link would send the variable(s) in the form to page.php.
GET would look like this:
Code: Select all
<form action=$PHP_SELF method=GET>
this sends the variable(s) to the same page (it refreshed the page with the variables present, basically)
Posted: Sat Mar 20, 2004 7:27 pm
by [n00b]
you mean that post is used to pass variables to another php file while get when a php file is calling itself?
Posted: Sat Mar 20, 2004 7:36 pm
by tim
i think u have the idea.
heres an example how one may use the POST method:
Code: Select all
<?php
// this code is on index.php
<form action=verify.php method=POST>
<input type=text name=username>
<input type=submit value=submit>
//then on verify.php
if (isset($username)) {
echo $username;
}
or something like
$name = $_POST["username"];
echo $name;
?>
$_GET would do whats on verifiy.php on index.php (meaning its done on the same page and u need to call the variables sent from the form(thats on index.php) with $_GET)
i'm sorry if i'm confusing you, let me know if i am.
Posted: Sat Mar 20, 2004 7:55 pm
by Bill H
Whenever you see a link like this:
Code: Select all
<a href="foobash.php?Var=3">Link</a>
The variable "Var" is being sent via the "GET" method.
Using a <form method="GET"> would be a bit unusual, as
the usage <form method="POST"> is much more common.
Posted: Sat Mar 20, 2004 9:01 pm
by d3ad1ysp0rk
Post is good for most things
Get is good for things where they may want to copy the link, add it to their favorites, send it to a friend, etc (ie. a catalog of items, a specific page on your site, etc).
Posted: Sun Mar 21, 2004 12:14 am
by McGruff
Post is always preferred as the form action since it is harder to forge a form than it is to tamper with the query string. Hence, post is slightly more secure.
[n00b] wrote:you mean that post is used to pass variables to another php file while get when a php file is calling itself?
That's not correct: each can be used in either case.
Posted: Sun Mar 21, 2004 2:54 am
by patrikG
$_GET is also limited in size. As a rule of thumb it can't be longer than 255 characters. $_POST is not size-restricted and not as transparent (i.e. somewhat more secure).
Posted: Sun Mar 21, 2004 6:39 am
by [n00b]
guys thanx a lot! You were really helpful!
EDIT:
One more question.
It is possible to pass POST vars only using forms?
Posted: Sun Mar 21, 2004 10:13 am
by d3ad1ysp0rk
unfortunately, yes.
get can be passed with hyperlinks or forms, post vars are only from forms