I’m writing a simple AJAX/jquery CMS for a website i’m building. To simplify everything, I want to simply make requests to URLs to perform actions (much like what Magento has – but I have my reasons not to use Magento/other existing options)
The problem is that the while loop doesn’t end (and at the time of writing the PHP docs are timing out where I am so I can’t access them).
<?php
$query = explode('/',parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$qs = array();
foreach ($query as $key=>$value) $qs[$key] = urldecode(htmlspecialchars($value));
# /action/{$class-name}/{$action}/{$field1}/{$param1}/{$field2}/{$param2}/.../{$fieldN}/{$paramN}
# e.g.
# /action/QuickOverview/get/internal_name/value
# /action/QuickOverview/update/internal_name/value1/title/value2/
$params = array();
array_shift($qs);
switch ($val = array_shift($qs)) {
case "action":
$className = array_shift($qs);
$action = array_shift($qs);
$field = true;
while ($val=array_shift($qs)!==false) {
if ($field) $params[-1] = $val;
else $params[$params[-1]] = $val;
$field = !$field;
}
unset($params[-1]);
break;
default:
var_dump("Unknown value: ".$val);
break;
}
var_dump($params);
?>
The page times out (probably looping forever), how can I end this while loop correctly?
=is an assignment operator and shouldn’t be used for a condition check, this case in thewhileloop.Try: