I first thought it was in the $_POST
super global, but it isn't if values are included in the URL.
$_REQUEST
did so and surprised me by not including cookies (reference http://php.net/manual/en/reserved.variables.request.php), and I later found that I am evidently using the default distribution php.ini file which does not contain the 'C' for cookies (reference http://php.net/manual/en/ini.core.php#ini.request-order). I don't wish to use $_REQUEST
, however, as it doesn't differentiate between a get request, and changing servers and php.ini files could cause a security concern.
What is the proper way to access all post values?
EDIT. I added the $real_post
part. Is this the proper way to do so?
<?php
setcookie('cookie', 'COOKIE', time() + (86400 * 30), "/");
echo('$_GET<pre>'.print_r($_GET,1).'</pre>');
echo('$_POST<pre>'.print_r($_POST,1).'</pre>');
echo('$_COOKIE<pre>'.print_r($_COOKIE,1).'</pre>');
echo('$_REQUEST<pre>'.print_r($_REQUEST,1).'</pre>');
$real_post=($_SERVER['REQUEST_METHOD'] == 'POST')?array_merge($_GET,$_POST):array();
echo('$real_post<pre>'.print_r($real_post,1).'</pre>');
?>
<form action='postorget.php?get=GET' method='post'>
<input type='text' name='post' value='POST'>
<input type='submit'>
</form>
$_GET
Array ( [get] => GET )
$_POST
Array ( [post] => POST )
$_COOKIE
Array ( [cookie] => COOKIE )
$_REQUEST
Array ( [get] => GET [post] => POST )