i have a problem on my friends server when testing my php code on it.(it works fine in my local server).
there is a form that contain checkbox inputs like
when submitting the form:
- In my server : print_r($_POST) prints:
Array ( [names] => Array ( [0] => john [1] => sam ) ) - In his server : print_r($_POST) prints:
Array ( [names] => Array )
and Array is a string not an array !
his php version is 5.2.17
<form method="post">
john <input type="checkbox" name="names[]" value="john"/>
sam <input type="checkbox" name="names[]" value="sam"/>
moh <input type="checkbox" name="names[]" value="moh"/>
<input type="submit"/>
</form>
<?php
print_r($_POST);
?>
From comments of first post here is the answer:
You are doing this which is wrong:
$_POST = array_map('stripslashes',$_POST);That’s exactly the cause of this problem, using
stripslasheson every element of$_POSTis worng,stripslashesworks on strings and an array in string is equal to “Array” so that function is doing the convert of your array to"Array", you should write a custom function and check if the element is not an array use stripslashes or if it is use the array_map again, like this:The reason of different results on array input for stripslashes function is probably due the different php versions …