-1

I was wondering what is the most widely used method for calling PHP functions from within an Android app? The method I was thinking of doing was using a variable in the URL and retrieve it using $_GET from my 'functions.php' and deciding what function to run that way. I just wanted to know if this is the best way of doing it or is there another way people typically accomplish this?

Thanks!

DanielRead
  • 1,379
  • 13
  • 27

2 Answers2

2

The best way to do this is creating an "API" on your PHP website or app, at this point, you could call an URL using your Android app on the web app, which would execute the method requested.

For example, you could call an URL like this:

www.mywebapp.com/api/call?method=executeCrons&param1=1

Then you'd have in your PHP code something like this:

if ($_REQUEST['method'] == 'executeCrons')
{
    executeCrons($_REQUEST['param1']);
}

It's simplified and you may want to add more validations and safeties, but you get the point.

You can also make these functions return a JSON string if you require a result.

There are other ways, such as using eval, but as mentioned already it can be unsafe.

Dany Caissy
  • 3,158
  • 13
  • 21
0

I would take a look at SLIM (http://www.slimframework.com/) for PHP, it makes it super quick to set up a reasonably versatile, secure PHP REST API. I tend to use it to throw together server side pieces because it allows me to change implementation very quickly.

wblaschko
  • 3,222
  • 1
  • 17
  • 23