奇怪的Warning: Invalid argument supplied for foreach()
我的代码在本机测试好好的
但别人通过局域网连我机器上的网站就出现这个错误
这是什么原因?
我的代码
<?php
require_once("application/modules/umc/register/register.php");
require_once("application/modules/umc/product/search.php");
require_once("application/modules/umc/detail/index.php");
$doublecheck = new DoubleCheck();
$StringCode = new StringCode();
$Search = new Search();
@session_start();
//最近浏览过的商品
$previous_viewed_products2=$_SESSION['previous_viewed_products'];
$previous_viewed_products_arr2=$Search->getPreviousViewedProducts($previous_viewed_products2);//得到结果集,是一个二维数组
?>
<table width=<?php echo count($previous_viewed_products2)*90+10 ?>px height=150px cellspacing=9 cellpadding=1 ><tr >
<?php
//if(is_array($previous_viewed_products))
=========================>>>>>>>>>>>>>这句话报错 foreach($previous_viewed_products2 as $p_source)//嵌套循环的原因是把无序的$previous_viewed_products_arr2改成session里的$previous_viewed_products的顺序
{
foreach($previous_viewed_products_arr2 as $p)
{
if($p['productid']==$p_source)
{
$im_1 =$p['imageurl'];
$str_1=explode("../",$im_1);
$im_2 =$str_1[3];
$price= $doublecheck->DoubleChecks($p['sell_price']);
$proname=$p['productname'];
if(mb_strlen($proname,'utf-8')>12)
$proname=$StringCode->cut($proname,20,0,'utf-8');
else if(mb_strlen($productname,'utf-8')<=8)//理论上用6比较好,但8保险点,因为有的名称是中文+数字和英文
$productname.=" ";
echo "<td width=100px align=center>";
echo "<table cellspacing=0 cellpadding=0 width=80px>";
echo "<tr height=90px><td><img src='$im_2' title='$productresult[productname]' width=80px height=80px></td></tr>";
echo "<tr height=30px><td>$proname</td></tr>";//产品名称
echo "<tr><td style='color:red'>¥$price</td></tr>";//价格
echo "<tr><td class=flpl_btn align=center><a href=\"javascript:_AddToCart('".$p[productid]."','".$p[productname]."','".$price."','".$p[weight]."')\"><img src='images/cart.png' border='0'></a></tr>";
echo "</table></td>";
}
}
}
?>
</tr></table>