gzanitti
gzanitti

Reputation: 117

There are any form to know if a POST is coming from an android application?

I have a file in PHP receiving a POST from an Android application and it works correctly but it also works correctly if loaded from a browser. What would be the most correct and efficient way to prohibit this from happening?

Upvotes: 0

Views: 105

Answers (3)

alanboy
alanboy

Reputation: 379

Try testing for the user agent in the request $_SERVER["HTTP_USER_AGENT"]. With PHP you can use the get_browser() for more information given the user agent.

Note that any client could send fake a user agent, so this information is good hint, but as any user input, it must not be trusted completely.

If you own the Android application I would suggest sending a security token generated on the android app via HTTPS to your PHP app where it would be validated.

Upvotes: 3

Jitender Dev
Jitender Dev

Reputation: 6925

Add header while making the HTTP request.

e.g. Application Type

 httppost.setHeader("Application-Type", "ANDROID");

This will differentiate between your calls and server may get to know if call is made from mobile with having this header while Browser doesn't.

Upvotes: 1

amir beygi
amir beygi

Reputation: 1272

Take a look at a page with phpinfo() on that from the android

You can check the Browser and OS, based on that you can chose what to do

Upvotes: 0

Related Questions