1

经过几个月的使用,我的申请表突然停止并出现此错误:

Warning: strip_tags() expects parameter 1 to be string, array given in /home/useraccount/public_html/My_Application.php on line 9

第 9 行开始 cookie,但即使我删除它似乎与该strip_tags行有关。为什么这会突然停止工作?这已经工作了几个月,没有任何问题。服务器是5.3,我看到升级到5.3.26. 这种变化真的会导致这种情况吗?

if ($_POST)
{
    session_set_cookie_params(0);
    session_start();
    $post = new stdClass; 
    foreach ($_POST as $key => $val)
    $post->{$key} = trim(strip_tags($_POST[$key]));
    $post->accident_type =$_POST['accident_type'];
    $_SESSION['post']=$post;
} 
more code continued...

非常感谢任何帮助。

4

1 回答 1

2

Well, it's obvious - your $_POST[$key] as array and not string. So you need to decide what do do in terms of logic of your application. I can suggest:

if(is_scalar($_POST['$key']))
{
   //treat any scalar value as string and do stuff:
   $post->{$key} = trim(strip_tags($_POST[$key]));
}
else
{
   //here you need to decide what to do with such things as arrays
}
于 2013-09-30T06:36:09.817 回答