我的 ModX Evo 中有一个片段。问题是,在我的本地这个 Shippet 工作正常,但是当我将它上传到主机时,它只返回空白。代码是一团糟,但我需要弄清楚这一点。有什么想法吗?谢谢。
<?php
$action=$_GET['action'];
switch ($action){
case('add'):_add();break;
case('view'):_view();break;
case('order'):_order();break;
case('del'):_del();break;
}
/////////////////////////////////////////////////////////////////
function _add()
{
global $modx;
session_start();
if(!session_is_registered('things')){session_register('things');}
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
$break=false;
$i=0;
if($ar_size>=0)
{
while ($i<=$ar_size):
$buf=$ar[$i];
if($buf['id']==$_GET['thing']){$_SESSION['things'][$i]['count']=$buf['count']+1;$break=true;}
$i++;
endwhile;
}
if($break==false){
$_SESSION['things'][($i)]=array('title' => $_GET['title'],
'id'=>$_GET['thing'],
'price'=>$_GET['price'],
'count'=>1);}
$modx->sendRedirect("/index.php?id=".$_GET['return']);
}
function _view()
{
if (!isset($_GET['zakaz'])){
session_start();
if(!session_is_registered('things')){session_register('things');}
if (isset($_GET['del']))
{
$buf=array();
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
if($ar_size>=0)
{
$i=0;
while ($i<=$ar_size):
if(($i+1)!=$_GET['del']){$buf[sizeof($buf)]=$ar[$i];}
$i++;
endwhile;
}
$_SESSION['things']=$buf;
}
if (isset($_GET['delall']))
{
$_SESSION['things']=array();
}
if (isset($_GET['cn']))
{
$c=$_GET['cn'];
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
if($ar_size>=0)
{
$i=0;
while ($i<=$ar_size):
$b=(int)$c[$i];
if($b>0)
{
$ar[$i]['count']=$b;
}else{$ar[$i]['count']=1;}
$i++;
endwhile;
}
$_SESSION['things']=$ar;
}
if((isset($_GET['peresh']))or(isset($_GET['del']))or(isset($_GET['delall'])))
{
global $modx;
$modx->sendRedirect("/index.php?id=10&action=view");
}
?>
<form action='index.php' method='GET'>
<input type="hidden" value="10" name="id">
<input type="hidden" name="action" value="view">
<table border=0 cellpadding=4 cellspacing=2 width='100%'>
<tr align='center'>
<td align=center colspan=5 bgcolor='#c5dcf8' class='table_title'>Ваша корзина</td>
</tr>
<tr align='center'>
<td bgcolor='#c5dcf8'>№</td>
<td bgcolor='#c5dcf8' >наименование товара</td>
<td bgcolor='#c5dcf8'><nobr>цена, руб.</nobr></td>
<td bgcolor='#c5dcf8'>кол-во</td>
<td bgcolor='#c5dcf8'>удалить</td>
</tr>
<?php
$ar=$_SESSION['things'];
$ar_size=sizeof($ar)-1;
$break=false;
$i=0;
if($ar_size>=0)
{
$summ=0;
while ($i<=$ar_size):
$buf=$ar[$i];
$i1=$i;
$i++;
$name=$buf['title'];
$id=$buf['id'];
$price=$buf['price']*$buf['count'];
$summ=$summ+$price;
$count=$buf['count'];
echo"<tr><td bgcolor=\"white\" style=\"color:black;\" align=\"center\">$i</td><td bgcolor=\"white\"style=\"color:black;\" align=\"center\">
<a style=\"color:blue\" href=\"/index.php?id=$id\">$name</td><td bgcolor=\"white\"style=\"color:black;\" align=\"center\">$price</td>
<td bgcolor=\"white\" style=\"color:black;\" align=\"center\"><input type=\"edit\" name=\"cn[$i1]\" value=\"$count\"SIZE=\"4\"></td>
<td bgcolor=\"white\" style=\"color:black;\" align=\"center\"><a href=\"/index.php?id=10&action=view&del=$i\" onclick=\"return confirm('Вы согласны?')\"><font color=\"Maroon\" style=\"color:Maroon;font-weight:bold;font-size:16px;text-decoration:none;\">X</a></td></tr>";
endwhile;
?>
<tr><td colspan="2" align="right" bgcolor="white"><b style="color:navy">Итого к оплате:</td><td style="color:blue;"bgcolor="white" align="center"><?php echo $summ; ?></td><td align="center"><input name="peresh" style="font-size:10px" type="submit" value="Пересчитать"></td><td align="center"><input style="font-size:10px" name="delall" type="submit" onclick="return confirm('Вы согласны?')" value="Удалить все">
</table><br><center><input type="submit" name="zakaz" value="Оформить заказ"></center></form>
<?php
}
else
{
?>
<tr><td colspan="5" align="center" valign="middle" height="60" style="color:blue" bgcolor="white">Корзина пуста</td></tr>
</table></form>
<?php
}
}
else
{
//////////////////////для заказа////////////////////////
}
?>
<?php
}