问题是,当FTP推送时,本地主机的结果与实时站点不匹配。该 下面的代码似乎让我相信数组不会被创建 正确地在服务器上。另外,它正在做一些时髦的东西,如下所示。第97行的错误是“不能将标量值用作数组”,或者$ _SESSION [“count”] [$ i] + = 1。你看到了原因吗?或者我犯了不同的错误?
总结一下代码,以下会话数组构成了购物车的核心:$ _SESSION ['item_id'] [$ i],$ _SESSION ['size'] [$ i], $ _SESSION ['price'] [$ i],$ _SESSION ['count'] [$ i] ......他们都彼此相关。因此,检查组合是否存在,如果是,则附加计数,如果不存在,则首次添加项目组合。
In Stock: 3
Distinct Item Count: 3
Array ( [0] => 1 [1] => 2 [2] => 2 ) Item Array: 1
Array ( [0] => S [1] => M [2] => L ) Size Array: 1
Array ( [0] => 15 [1] => 20 [2] => 20 ) Price Array: 1
Array ( [0] => 15 [1] => 35 [2] => 17 ) Count Array: 1
Quantity Increased to 18
1
S
15
15
2
M
20
35
2
L
20
18
|3 ($1285)
In Stock: 5
0
1
M
20
1
|1 ($20)
In Stock: 5
Distinct Item Count: 1
1Item Array: 1
MSize Array: 1
300Price Array: 1
1Count Array: 1
Warning: Cannot use a scalar value as an array in /public_html/shop/helper/addtocart.php on line 97
Quantity Increased To
1
M
2
|1 ($0)
if (isset($_SESSION["item_id"]) && is_array($_SESSION["item_id"])){
echo "Distinct Item Count: " . count($_SESSION["item_id"]);
echo "<br/>";
echo "<br/>";
echo "Item Array: ";
print_r($_SESSION["item_id"]);
echo "<br/>";
echo "Size Array: ";
print_r($_SESSION["size"]);
echo "<br/>";
echo "Price Array: ";
print_r($_SESSION["price"]);
echo "<br/>";
echo "Count Array: ";
print_r($_SESSION["count"]);
echo "<br/>";
echo "<br/>";
}
//check for current product combination in visitor's shopping cart content
//find count in cart
if (!isset($_SESSION["item_id"])){
$count = 0;
}else{
$count = count($_SESSION["item_id"]);
}
echo $count;
echo "<br/>";
if ($count == 0){
//declare arrays
$_SESSION["item_id"] = array();
$_SESSION["size"] = array();
$_SESSION["price"] = array();
$_SESSION["count"] = array();
$_SESSION["total"] = array();
//add first item to cart
$_SESSION["item_id"][] = $item_id;
$_SESSION["size"][] = $size;
$_SESSION["price"][] = $price;
//fundraiser and corporate
if (($_SESSION["acctype"] == 2 || $_SESSION["acctype"] == 3) && isset($_SESSION['userid'])){
//update count, add 100
$_SESSION["count"][] = 100;
}
else{
$_SESSION["count"][] = 1;
}
}else{
$flag=0;
$i=0;
while ($i <= $count){
if( ($_SESSION["item_id"][$i] == $item_id) && ($_SESSION["size"][$i] == $size) ){
//fundraiser and corporate
if(!isset($_SESSION["acctype"]) || $_SESSION["acctype"] == 1){
//update by one
$_SESSION["count"][$i] +=1;
}
elseif(isset($_SESSION['userid']) && ($_SESSION["acctype"] == 2 || $_SESSION["acctype"] == 3)){
//update count, add 100
$_SESSION["count"][$i] +=100;
}
else{
echo "Hmm";
}
//update cart stats
echo notify('Quantity Increased To' . ' ' . $_SESSION["count"][$i]);
//was there combination match?
$flag = 1;
}
$i++;
}
if($flag == 0){
$_SESSION["item_id"][] = $item_id;
$_SESSION["size"][] = $size;
$_SESSION["price"][] = $price;
//fundraiser and corporate
if (($_SESSION["acctype"] == 2 || $_SESSION["acctype"] == 3) && isset($_SESSION['userid'])){
//update count, add 100
$_SESSION["count"][] = 100;
}else{
$_SESSION["count"][] = 1;
}
}
}
答案 0 :(得分:0)
我没有查看你的代码,但是我遇到了类似的问题,这是我的FTP客户端,不知何故,在传输过程中它只是改变了一些导致错误的文本,如上所示。
我停止使用FileZilla并开始使用CyberDuck,一切都很好,检查服务器上的代码并验证它是否已被更改。
答案 1 :(得分:0)
简答:使用var_dump(ini_get('register_globals'))
或phpinfo()
检查您的实时服务器上是否启用了register_globals。如果启用了register_globals,最好的解决方案是禁用寄存器全局 - 它会导致安全问题,并且不推荐使用PHP 5.3。
更长的答案:'不能将标量值用作数组'意味着您作为数组引用的变量中存在标量值(例如数字)。我没有看到你将标量直接分配给$_SESSION["count"]
的任何地方。
但是,如果register_globals已启用,$count
将成为$_SESSION["count"]
的引用,这意味着$count = 0
会将$_SESSION["count"]
设置为标量。同样,最好的解决方案是禁用register_globals,但解决方法是将$count
变量重命名为其他内容。