Created
December 20, 2012 19:48
-
-
Save atomize/4348025 to your computer and use it in GitHub Desktop.
/** * AJAX API FOR PHP FUNCTION LIBRARY * Place your functions below the header and then call them by posting to the script with any kind of ajax : * $('#test').load('base/ajax/ajaxapi.php',{method:'sha256',params:"'batman','gargamelhatessmurfs'"}); for example. */
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* AJAX API FOR PHP FUNCTION LIBRARY | |
* Place your functions below the header and then call them by posting to the script with any kind of ajax : | |
* $('#test').load('base/ajax/ajaxapi.php',{method:'sha256',params:"'batman','gargamelhatessmurfs'"}); for example. | |
*/ | |
if(function_exists(stripslashes(trim($_POST['method'])))){ //IF THE FUNCTION EXISTS (IN THIS SCRIPT) | |
$method = stripslashes(trim($_POST['method'])); | |
$params = str_replace("'", '',stripslashes(trim($_POST['params']))); //strip single quotes if used | |
$opts= explode(',',$params); //turn the parameters string into an array | |
$function = new ReflectionFunction($method); //instantiate the function as an object | |
$function->invokeArgs($opts); //invoke the function with an array of arguments (if given) | |
}else{ //ELSE THE FUNCTION DOES NOT EXIST | |
echo "error the function you called : ".$_POST['method']."(".$_POST['params'].")"." does not exist"; | |
exit; | |
} | |
exit; | |
///////////////////////////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////////////////////////// | |
// PLACE YOUR FUNCTIONS BELOW HERE. // | |
///////////////////////////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment