1

I'm searching for a way to detect in PHP if the site/page is currently running as PWA or web.

I hoped that something inside the $_SERVER var can be used for that, but it seems to me like there is nothing that helps.

My secondary approach would be to set a cookie via appstart parameter and use that for PHP conditions. Is there any good way of detecting PWAs or a best practice?

UPDATE: Just tested setting a cookie based on the start url parameter. But it seems like PWA and Web share cookies so that is not an option.

GDY
  • 2,872
  • 1
  • 24
  • 44
  • https://stackoverflow.com/questions/41742390/javascript-to-check-if-pwa-or-mobile-web – bill.gates Aug 03 '20 at 13:13
  • 1
    Actually this question was never asked anywhere on stackoverflow. I also couldn't find anything about that anywhere else. I specifically asked about a detection inside PHP for use in conditions. I don't need a JS solution. – GDY Aug 03 '20 at 13:22
  • Probably a duplicate of https://stackoverflow.com/questions/54905002/detect-webrequest-coming-from-pwa-on-the-server-side – GDY Aug 03 '20 at 18:02
  • I've tried a bunch of different things but it seems that right now there is now way of finding out in php if it is a pwa or not. – GDY Aug 06 '20 at 06:36
  • Why not read the initial index.php / index.html file and look for the `` tag? Am I missing something here in your request? – Volomike Nov 12 '21 at 05:11

1 Answers1

0

Although the answer in this post is a JS answer, you can apply the same mechanism to your code in PHP. Modify your manifest file to

"start_url": "./?mode=standalone"

and check on the PHP side the $_GET array.

print_r($_GET);

will get you:

Array
(
    [mode] => standalone
)
Carsten
  • 45
  • 8
  • Thats what im doing right now, but thats only an option for the front page and not all areas – GDY Aug 12 '22 at 06:06
  • You could add `?mode=standalone` to the URLs of your calls if it is in _standalone_ mode and check it in the called PHP files, again. I'm calling other pages via the `submit` action in forms with `method=post`. Within the form I'm using a hidden (`style="display:none; "`) text field to pass the standalone mode. Whichever way you are calling the other pages, there are possibilities with GETs and POSTs to pass that information and retrieve it from `$_GET` or `$_POST`. – Carsten Aug 12 '22 at 11:13