PHP $_REQUEST

You probably already know that you can get variable from a html form in php using $_GET and $_POST, you use $_GET if the html form is like: <form name="name" action="form.php" method="get"> and use $_POST if it is <form name="name" action="form.php" method="post">.

But what if you want your php to work for both post and get datas in the same time, to precess the form whatever it was in post method or get method, you will then think to use if conditions to check whether of two methods was used:

if (isset($_POST['var']))
// process data...
if (isset($_GET['var']))
// process data in the same way...

BUT there is a little and usefull solution: $_REQUEST, because $REQUEST can get any form field value, whatever it was GET or POST method, it does not care.

This means that $_REQUEST['var'] = $_POST['var'] if the form was in post method, and $_REQUEST['var'] = $_GET['var'] if the form was get. ('var' is the field name you want to get its value)
So now you will not care what method the form use :)

You can also use isset() with $_REQUEST, for example:
if (isset($_REQUEST['var'])) is the same than if ( isset($_POST['var']) or isset($_GET['var']) )

I hope this little tip will help you, we will provide best php tips, scripts as well as php tutorials.

13 comments:

SOMESPECIAL said...

Thanks so much

PHP Tutorial For Beginners with Examples PDF said...

excellent piece

Anonymous said...

Yeah.. nice info.. Thnx bro.. :)

Unknown said...

This fundamentals of PHP programming helped me to improvise my skill set in PHP development.
Regards,
PHP Training in Chennai|PHP Course in Chennai

Unknown said...

Superb explanation & it's too clear to understand the concept as well, keep sharing admin with some updated information with right examples.Keep update more posts.

Digital Marketing Company in Chennai

mani said...

Thanks for your informative blog!!! Your article helped me to understand the future of Core Java programming language. Keep on updating your with such awesome information.
White Label Website Builder

Anonymous said...

Thanks for sharing the information about PHP Training Chennai .
PHP Training in Chennai
PHP Course in Chennai

Unknown said...

I went through your blog and it’s totally awesome. Keep on updating your site with such informative post. If possible please include rss feed for your blog.
web designing course in chennai|Best web designing institute in chennai

Blogger said...

Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Blog.Please feel free to visit our site. Thank you for sharing.
php training center in indore
Keep Posting:)

Ancy merina said...
This comment has been removed by the author.
Pro Integrate said...

Pro Integrate is one of the best technology companies which gives you the best services and also provides mixed working environment On-Site as well as Nearshore. The goal of our company is to help match employers who have job openings with qualified employees who are available. We provided specific resources, as requested, to be integrated in our partner’s projects. Business consultancy like us provides information, consulting, and insights to importers and exporters so that they can take accurate decisions.

Unknown said...

We provide Digital Marketing Services and we have high conversion rates. We help our clients significantly increase the number of customers in the shortest amounts of time.

Anonymous said...

How to deposit money at a casino | TrickToAction.com
The top 10 deposit 프랑스 리그1 순위 methods for depositing money at a 다 파벳 casino · 1. Create a 토토왕뚜껑 new account with the casino's deposit page, then start 스포츠토토 부스 샤오미 by creating a new account 안전한 토토사이트 샤오미 with