Reputation: 5755
I've got a snippet in my ModX Evo. The problem is that on my local this shippet is working ok,but when I upload it to the host it returns only blank space. The code is a mess, but I need to get figured that out. Any ideas?Thx.
<?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
}
Upvotes: 1
Views: 1358
Reputation: 722
session_register() and session_is_registered() are deprecated in PHP 5.3 and removed in PHP 5.4, according to the docs. I'd definitely take that out.
As OptimusCrime says, you can't use <?php
and ?>
in snippets; the ENTIRE snippet will be evaluated in parse time and doing that results in parse errors. May find some evidence of that in the error log.
Also all the references to session_start really shouldn't be there - MODX handles the sessions for you and you should not be re-starting them again. I'm not sure if that will cause issues, but if anything it can help to clear up your code even just a tiny bit ;)
Upvotes: 0
Reputation: 14863
You should put all your functions in:
If (!function_exists('yourfunction')) { [....]
EDIT: does your snippet work in a local modx install? Or does it work as a normal php-script? I dont think you can stop/start php (?> and
You could check your error-log within Modx. If it displays blank errors might be turned off
Upvotes: 1