User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 429,860 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,477 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1732 | Replies: 7
Reply
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Just a simple question.

  #1  
Jul 6th, 2005
Hi,

I'm new to php, I want to know what's the better time to use POST instead of GET(or GET instead of POST)? what's the advantage to use one rather than other.

Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Just a simple question.

  #2  
Jul 6th, 2005
POST vars are more secure because they are not visible in the URL. Also, if you are posting large amounts of text, GET method is not going to work well. I generally only use GET (querystring) method for pages such as a product detail page. I might do something like product_detail.php?id=15. In this case, I like having the ability to directly call the URL for a specific product. Also, I'm very likely to be using the querystring URL in a link. You can't POST in a link. e.g. <a href="product_detail.php?id=15">Daniweb Logo T-Shirt</a>
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Re: Just a simple question.

  #3  
Jul 6th, 2005
As POST is more secure than GET, and can handle larger amount of text, why we still need GET? Even if we cannot POST in a link like <a href="product_detail.php?id=15">, we still can use POST in form to pass id, right?
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Just a simple question.

  #4  
Jul 6th, 2005
Correct. You probably should always use method="POST". This is not a rule or a policy, just probably usually best and will suit your needs.

You would use method="GET" in a form if you were submitting your form to a third-party who only accepts GET input.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jun 2005
Location: Troy
Posts: 1,277
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 36
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: Just a simple question.

  #5  
Jul 6th, 2005
Use GET for a location if you want somebody to be able to revisit the page. For example, search engines use GET.
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Just a simple question.

  #6  
Jul 6th, 2005
Good point, Rashakil Fol.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jun 2005
Posts: 9
Reputation: keibi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
keibi keibi is offline Offline
Newbie Poster

Re: Just a simple question.

  #7  
Jul 10th, 2005
GET methods also makes it easier for someone to bookmark a page. And your users don't get the annoying "This page contains POST data (...) when they try to use the back and forward buttons in their browser. Also, GET don't need a form (or javascript cheating) - you can easily print out dynamic url-s like "www.somedomain.com/product.php?id=116" in your php scripts, and people can just follow the links, with no need for form handling, which is neat.

General rule of thumb: Use get for pages that views stuff and POST for pages that change stuff. For instance, you don't want an URL a la "www.somedomain.com/products/raiseprice.php?rate=10%", because if someone calls this page twice, they will change the price twice.

Also, information that you would like to be secret should not occur in url's. For instante, don't go "www.somedomain.com/login.php?user=admin&password=adminpass". That's piece of cake to hack, and you don't waht that to happen

Hope this cleared things up.

- Karianne
Reply With Quote  
Join Date: May 2005
Location: London, UK
Posts: 145
Reputation: Electrohead is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Electrohead's Avatar
Electrohead Electrohead is offline Offline
Junior Poster

Re: Just a simple question.

  #8  
Jul 11th, 2005
GET is useful with searches, etc. POST is more secure beacuse you can't see it in the address bar.

If you are dealing with passwords you should use POST always

Hope it helps
: :: Click here to join my website :: :
Brand new online community! Help my forum grow!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 7:32 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC