Xeoncross Posted October 1, 2007 Share Posted October 1, 2007 Has anyone ever had a PHP script that had different values in the $_POST array than in the $_REQUEST array? Take a look at the values below and you will see that data sent through a method="POST" form became different for both arrays. print_r($_POST); - inputs became a string Array ( [inputs] => Array [action] => disable [submit] => submit [active] => 1 ) print_r($_REQUEST); inputs became an array Array ( [active] => 1 [inputs] => Array ( [0] => 65 [1] => 64 ) [action] => disable [submit] => submit ) Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/ Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 because they ARE different. compare GET too... Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359474 Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 It is because $_REQUEST holds the values for both GET and POST. Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359480 Share on other sites More sharing options...
Xeoncross Posted October 1, 2007 Author Share Posted October 1, 2007 because they ARE different. compare GET too... I know they are different - but not whole array-to-string different. What is going on? why would a POST array be a string? (REQUEST got it right). Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359481 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 I didn't know that. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359482 Share on other sites More sharing options...
wildteen88 Posted October 1, 2007 Share Posted October 1, 2007 $_REQUEST and $_POST the same here! Array ( [txtbox] => foo [inputs] => Array ( [0] => b [1] => c ) [submit] => submit ) Array ( [txtbox] => foo [inputs] => Array ( [0] => b [1] => c ) [submit] => submit Not sure what you mean? Test code: <?php echo '<h1>$_REQUEST</h1> <pre>' . print_r($_REQUEST, true) . '</pre> <h1>$_POST</h1> <pre>' . print_r($_POST, true) . '</pre>'; ?> <form action="#" method="post"> Text: <input type="text" name="txtbox" /><br /> Inputs:<br /> <input type="checkbox" name="inputs[]" value="a" /> A<br /> <input type="checkbox" name="inputs[]" value="b" /> B<br /> <input type="checkbox" name="inputs[]" value="c" /> C<br /> Submit: <input type="submit" name="submit" value="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359501 Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 wildteen88 - If you changed your form method to GET they wouldn't end up the same. Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359506 Share on other sites More sharing options...
wildteen88 Posted October 1, 2007 Share Posted October 1, 2007 same output no change. Tested in FF, IE 7 and Safari (Win). I cannot see how $_POST displays differently. Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359514 Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 Okay, manually put something in the URL. Just add this ?id=1 Then submit the form. That makes them different, I just tested it. Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359543 Share on other sites More sharing options...
Xeoncross Posted October 1, 2007 Author Share Posted October 1, 2007 Ok, I just striped my code down to something simple like the below code - and it works. So my guess is that somewhere in my system something is messing with the $_POST data and turning it into a string. (the only thing is that I can't find anywhere where my code messes with the $_POST data!) So any ideas? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>POST and REQUEST TEST</title> <script type="text/javascript"> // Check All Code from // http://www.dustindiaz.com/check-one-check-all-javascript/ function checkAllFields(ref) { var chkAll = document.getElementById('checkAll'); var checks = document.getElementsByName('inputs[]'); var removeButton = document.getElementById('submit'); var boxLength = checks.length; var allChecked = false; var totalChecked = 0; if ( ref == 1 ) { if ( chkAll.checked == true ) { for ( i=0; i < boxLength; i++ ) checks[i].checked = true; } else { for ( i=0; i < boxLength; i++ ) checks[i].checked = false; } } else { for ( i=0; i < boxLength; i++ ) { if ( checks[i].checked == true ) { allChecked = true; continue; } else { allChecked = false; break; } } if ( allChecked == true ) chkAll.checked = true; else chkAll.checked = false; } for ( j=0; j < boxLength; j++ ) { if ( checks[j].checked == true ) totalChecked++; } removeButton.value = "Process ["+totalChecked+"] Selected"; } </script> </head> <body> <?php echo '<h1>$_REQUEST</h1> <pre>' . print_r($_REQUEST, true) . '</pre> <h1>$_POST</h1> <pre>' . print_r($_POST, true) . '</pre>'; ?> <form action="#" method="post" onsubmit="return confirm('Are you sure you want to ' + document.getElementById('action').value + ' the selected items?');"> <fieldset> <legend></legend> <dl> <dt> <label for="title"> <input class="boxes" value="67" name="inputs[]" onclick="checkAllFields(2);" type="checkbox"> </label> </dt> <dt> <label for="title"> <input class="boxes" value="68" name="inputs[]" onclick="checkAllFields(2);" type="checkbox"> </label> </dt> <dt> <label for="title"> <input class="boxes" value="69" name="inputs[]" onclick="checkAllFields(2);" type="checkbox"> </label> </dt> <dt> <label for="title"> <input class="boxes" value="70" name="inputs[]" onclick="checkAllFields(2);" type="checkbox"> </label> </dt> <dt> <label for="action">Action to take:</label> </dt> <dd> <select name="action" id="action"> <option selected="selected" value="approve">Approve</option> <option value="disable">Disable</option> <option value="delete">Delete</option> </select> </dd> <dt> <label for="removeChecked"></label> </dt> <dd class="submit"> <input value="Process [0] Selected" name="submit" id="submit" type="submit"> <input value="1" name="active" type="hidden"> </dd> </dl> </fieldset> </form> Again, the simplified code above works just fine. Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359553 Share on other sites More sharing options...
Xeoncross Posted October 1, 2007 Author Share Posted October 1, 2007 Ok, I found it. I was cleaning the POST data somewhere like this: <?php if (get_magic_quotes_gpc()) { //foreach $_GET variable foreach($_GET as $key => $value) { //Clean the value of the added slashes $_GET[$key] = stripslashes($value); } //foreach $_POST variable foreach($_POST as $key => $value) { //Clean the value of the added slashes $_POST[$key] = stripslashes($value); } } ?> Which is bad because I had a multi-level $_POST array ($_POST['inputs'][0] was on level 3). So I was messing myself up by trying to clean the forward slashes from the posted code. aghhhhh! Quote Link to comment https://forums.phpfreaks.com/topic/71416-solved-_post-is-different-from-_request/#findComment-359610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.