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

 

 

 

Link to comment
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.