Вопрос

I have a php login script thats executed from the top of my html file. Is there a way to NOT execute this php code when using it offline?

The goal is: I have a webapp that can be cached on the mobile phone. When the user has no network it should still be possible to open and use the app. But when offline it can't connect to the user database for authentication.

So:

  • When online: Execute the login script
  • When offline: "skip" the loginscript

I was thinking something like this:

<?php

function getStatus($ip,$port){
   $socket = @fsockopen($ip, $port, $errorNo, $errorStr, 3);
   if(!$socket) return "offline";
     else return "online";
}

echo getStatus("sitename.com", "80");
?>

But then instead of "echo online" it should execute the php script, when offline "do nothing" But you cant "echo" php code within php code.

Any ideas on how to handle this?

Это было полезно?

Решение 2

PHP works on server side so It will not be able to login when user is offline. The caching is done only of output files such as

html,js,css,images

etc but Cookies can not be edited*(actully they can be by javascript)* without connecting to server.

Другие советы

PHP is executed on the server side, not the client side. If a website is cached, you might not even contact the webserver at all.

In fact, making the server execute the PHP code while offline is impossible, since you won't be in contact with the server at all!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top