muttley91
muttley91

Reputation: 12674

Check if Page is being Accessed by a Browser vs. HTTP Request

Like the title says, is it possible to detect whether a particular page is being accessed via a web browser as opposed to an HTTP request? I'm aware that accessing via a web browser is performing an HTTP request, so I'm curious if it's at all possible to differentiate.

I ask because I'd like a certain page to only be accessible via my own application and it should not be browsed to directly.

Upvotes: 0

Views: 824

Answers (2)

ɹɐqʞɐ zoɹǝɟ
ɹɐqʞɐ zoɹǝɟ

Reputation: 4370

Try to use get_browser and check for isMobileDevice field. you can check it using if condition and retrict the access of that page if request comes from web browser.

It might help only, of course, if the path to browscap.ini is set up in php.ini. If not, you can use php classes like https://github.com/garetjax/phpbrowscap

Upvotes: 1

deceze
deceze

Reputation: 522081

If it's a publicly accessible URL, there's no way to fundamentally differentiate between "your app" and "anybody else". It's only an HTTP request, whichever way you access it. If you set the right headers, there's no way to differentiate one request from another identical one. If you want to limit access to "your app" only, set some specific secret authentication headers which only "your app" knows. However, if "your app" is Javascript in a webpage, anyone will be able to inspect and see those "secret" headers.

Upvotes: 0

Related Questions