0

I am working on a website that will automatically redirect Android users to a app page on Google Play. If the user is not using an Android device, it will redirect them to a website instead.

Current PHP code:

<?php
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$android = stripos($_SERVER['HTTP_USER_AGENT'],"android");

if ($Android || $android)
{
    header("Location: market://details?id=com.CompanyName.AppName");
}
else
{
    header("Location: https://CompanyName.com");
}
?>

Problem: While this code works perfectly, I am worried that some of the Android users without the installed Google Play store app wont be able to access neither of those links. Is there any way to check if Google Play is not installed to redirect those users to the website instead?

EDIT: As this is impossible to do (thanks to comments), I am looking for a solution that will detect that the URL (market://...) is invalid and will redirect the user to the website.

Miha M
  • 379
  • 1
  • 3
  • 14
  • 2
    I highly doubt you will be able to do this from a webpage, due to privacy reasons. https://stackoverflow.com/Questions/12856773/detect-if-android-app-has-been-installed-on-the-device-using-a-mobile-web-page – GrumpyCrouton Jun 19 '20 at 17:45
  • 1
    and you _definitely_ can't do it with a server-side language like PHP. – Sammitch Jun 19 '20 at 17:48
  • Thank you, I understand. Is there any try/catch variant that will work with that? Example: If *market://details?id=com.CompanyName.AppName* URL is invalid, open website? – Miha M Jun 19 '20 at 18:15
  • 1
    Nope. Once you redirect the client to the other URL, you've lost the connection. Why not redirect them to the online play store instead (play.google.com)? – Jason Jun 19 '20 at 23:41

0 Answers0