nkosinathi Posted December 14, 2010 Share Posted December 14, 2010 Thanks in advance for help. I have a PHP script that has a function called traverseXMLNodes and it passes an xml string. I want anyone with a username and password to be able to call this function from his website or application or programming. In short i want my site to act as an API(Application Programming Interface). I am really stuck as to how to go about this. There are other functions i would like to call as well so traverseXMLNodes is not the only function i want to my "API" users to access. Below is the code I am using. the filename for my php i called remote.php. I am using the following query string to test and no results are returned. http://localhost/testfolder/remote.php?xmlstring=20 <?php $allowedfuncs = array('xmlstring','remotefunction2'); if(in_array($_get['xmlstring'], $allowedfuncs)) { $func = $_get['xmlstring']; $output = traverseXMLNodes($func); // This calls $_get['funccall']() echo $output; } else { exit(); } function traverseXMLNodes ($func) { echo "The XML string is"; echo "<br/>"; echo $func; echo "<br/>"; } /* More functions go here */ ?> Link to comment https://forums.phpfreaks.com/topic/221616-calling-a-function-on-another-url-with-query-string/ Share on other sites More sharing options...
Adam Posted December 14, 2010 Share Posted December 14, 2010 $allowedfuncs = array('xmlstring','remotefunction2'); if(in_array($_get['xmlstring'], $allowedfuncs)) { This condition makes no sense. You're defining "xmlstring" as a valid function, then checking if the xmlstring parameter's value is within the array? Going with the example URL you provided, that's equal to: if (in_array(20, array('xmlstring', 'remotefunction2')) { In which case you're always going to enter the else clause and kill execution. Link to comment https://forums.phpfreaks.com/topic/221616-calling-a-function-on-another-url-with-query-string/#findComment-1147147 Share on other sites More sharing options...
trq Posted December 14, 2010 Share Posted December 14, 2010 $_get should be $_GET. Link to comment https://forums.phpfreaks.com/topic/221616-calling-a-function-on-another-url-with-query-string/#findComment-1147152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.