Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would you ever use $_GET in PHP?

I haven't officially started learning PHP, just skimming through a couple tutorials and I have a question. Why would some one choose to use Get vs Post? Why would you ever want the data shown in the url bar? I understand post is used for passwords and important info but I don't understand why you would use get instead of just post all the time?

Thanks for any insight.

like image 797
user377419 Avatar asked Nov 27 '22 20:11

user377419


2 Answers

$_GET is useful for pages where users are requesting data - such as a search page, and pages that a user might want to bookmark and share with others. Actions that should be readonly.

$_POST is useful for pages where users are "posting" data - such as a signup form. $_POST should be used when you don't want your visitors to be able to bookmark page. Actions that write data.

As prodigitalson added: you may use $_POST or $_GET for any operation, but it is good practice to use them as described above.

like image 152
Michael Robinson Avatar answered Dec 06 '22 00:12

Michael Robinson


If you want people to be able to share the link with their friends...for eg http://example.com/products.php?product_id=12

like image 35
Neil Sarkar Avatar answered Dec 05 '22 23:12

Neil Sarkar