PHP $_REQUEST
In this page:
$_REQUEST["key"]; // combined $_GET, $_POST and $_COOKIE data
$_REQUEST क्या है?
$_REQUEST $_GET, $_POST, और $_COOKIE के contents को एक single array में merge कर देता है, इसलिए $_REQUEST से पढ़ने वाली एक script को पहले से जानने की ज़रूरत नहीं कि data कौन सा method लाया — एक quick prototype के लिए convenient, एक बार आप explicit होने की परवाह करें तो कम।
उदाहरण: What is $_REQUEST?
<?php
// Set `$_GET['q']` to "search term"
$_GET['q'] = "search term";
// Print `$_REQUEST['q']` to the output
echo $_REQUEST['q'];
?>
Login to try C/C++/Java/PHP code in the editor
$_REQUEST के through GET Data पढ़ना
URL query string के through actually भेजी गई किसी value के लिए $_REQUEST[q] पढ़ना exactly वैसे ही काम करता है जैसे इसे $_GET[q] से पढ़ना करेगा — $_REQUEST बस $_GET के contents को बाकियों के साथ fold कर देता है, एक catch-all fallback की तरह act करते हुए।
उदाहरण: Reading GET Data via $_REQUEST
<?php
// Set `$_GET['q']` to "php tutorials"
$_GET['q'] = "php tutorials";
// Print `$_REQUEST['q']` to the output
echo $_REQUEST['q'];
?>
Login to try C/C++/Java/PHP code in the editor
$_REQUEST के through POST Data पढ़ना
POST से भेजे गए form data के लिए भी वही लागू होता है: $_REQUEST[username] इसे उसी तरह पकड़ता है जैसे $_POST[username] करता।
Convenience यह है कि आपके code को branch नहीं करना पड़ता कि कौन सा method इस्तेमाल हुआ — tradeoff यह है कि यह सिर्फ $_REQUEST देखकर यह भी नहीं बता सकता कि कौन सा method इस्तेमाल हुआ।
उदाहरण: Reading POST Data via $_REQUEST
<?php
// Set `$_POST['username']` to "Alice"
$_POST['username'] = "Alice";
// Print `$_REQUEST['username']` to the output
echo $_REQUEST['username'];
?>
Login to try C/C++/Java/PHP code in the editor
_REQUEST में Variables Precedence
अगर एक GET parameter और एक POST parameter same key share करते हैं, तो $_REQUEST के अंदर कौन जीतता है यह php.ini में PHP की request_order (या पुरानी variables_order) setting decide करती है — आपके code से नहीं — जो outcome को खुद script में दिखने वाली किसी चीज़ के बजाय server configuration पर depend करा देता है।
उदाहरण: Variables Precedence in _REQUEST
<?php
$_GET['key'] = "from-get";
$_POST['key'] = "from-post";
// Which one $_REQUEST['key'] holds depends on php.ini's request_order setting
echo $_REQUEST['key'];
?>
Login to try C/C++/Java/PHP code in the editor
Limitations और Security
क्योंकि $_REQUEST एक GET request को एक POST से अलग नहीं बता सकता, इस पर भरोसा करने वाला code एक real form submission के बजाय एक simple crafted URL के through एक state-changing action accept करने के लिए trick किया जा सकता है।
Explicitly $_GET या $_POST इस्तेमाल करना इस पूरी class की confusion से बचाता है।
उदाहरण: Limitations and Security
<?php
// A crafted URL like ?delete_account=1 could trigger this if code trusts $_REQUEST
$_GET['delete_account'] = 1;
if (isset($_REQUEST['delete_account'])) {
echo "This should require $_POST, not any $_REQUEST source.";
}
?>
Login to try C/C++/Java/PHP code in the editor
$_REQUESTइस्तेमाल करना जब आप जानते हैं कि data POST से आता है, जो एक attacker को वह value URL या एक cookie के through भी supply करने देता है।$_REQUESTपर भरोसा करना जब एक GET और एक POST parameter same key share करते हैं, क्योंकि कौन जीतता है यहphp.iniमेंrequest_ordersetting पर depend करता है।- यह मान लेना कि
$_REQUESTमें हर server पर cookie data शामिल है, जबकि modern default configuration में सिर्फ GET और POST शामिल हैं।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: