Jump to content

Calling a function on another URL with query string


nkosinathi

Recommended Posts

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
*/
?>

 

 

 

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.