Reputation: 117
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
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
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
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