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.

20 comments:

Anonymous said...

Thanks for the tip!

rize wordpress said...

Rize PHP practice consists of Dedicated PHP Developers certified in related field from reputed universities and colleges.

SOMESPECIAL said...

Thanks so much

PHP Tutorial For Beginners with Examples PDF said...

excellent piece

Fully Help said...

Nice blog...Very useful information is providing by ur blog. Great beginning php tutorials Very clear and helpful for beginners.

Anonymous said...

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

jhansi joe 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

mary Brown said...

I have read your blog its very attractive and impressive. I like it your blog.

PHP Training in Chennai | Online PHP Training

PHP Training in Chennai | Online PHP Training

Jessica George 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

ranasing rajkumar 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

kim john said...

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

Amirtha rao 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

iice indore 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:)

iice indore 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:)

JamesWilliam said...

Interesting post! This is really helpful for me. I like it! Thanks for sharing!
Mobile application developers in Chennai | PHP developers Chennai

Ancy merina said...

What a fantastic and informative blog! i enjoyed reading this, and I must say your blog is great! Keep up the excellent work. You have a magical talent of holding readers mind.
Web Development Services in Bangalore
BEST web design services in bangalore
ECommerce Website developers in bangalore
Outsource magento ecommerce services india

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.

Swavish Softwares 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.

priya nigam said...

We, Swavish software is Top Mobile Apps Development Company in Delhi NCR. The need for mobile app developers is thus increasing at a higher rate. So, we are here to develop different mobile apps for our clients and We also provide the best IT security services in Delhi.
Website: - https://www.swavishsoftwares.com/mobileappsdevelopment.php

Swavish Softwares said...


Website Designing Company in Delhi offer services like responsive website design , ecommerce website design, custom website design in which our web designers deal directly with each customer.