here is my ajax_handle file:
if ($_SERVER['HTTP_X_REQUESTED_WITH'] !== "XMLHttpRequest")
{
echo "Error";
exit();
}
$req = explode("_",$_POST['req']);
$className = $req[0] . "Controller" ;
$methodName = $req[1];
$file = "application/controllers/" . $className . ".php" ;
require_once $file;
if ($_POST['data']) {
var_dump($_POST['data']);
}
$controller = new $className;
$result = $controller->$methodName();
echo json_encode($result);
I send the arguments as any array in the $_POST['data'] variable. i have no idea what would be the best way to pass them to the (dynamic) $methodName function.
"../../WhateverPath/Any_xxx"in$_POST['req']. I can call ANY public method in the controller. Do check that the required file really is inside the path you think. Userealpath()to expand any relative path you might get, or forbid those characters entirely that might be "file path" relevant. Is there a reason the controller name can be ANY character on this planet? ASCII letters should be enough.