0

Basically I have a PHP page where I want to display some data, I also want the page to be downloadable and people can display it locally. But! I want to add a feature where I can check for an internet connection, connecting to the page's origin to see if resources are available such as external style sheets etc. I was checking for a connection like this:

public function connection(){
    const location='http://myResource.co.uk/';
    $curl=curl_init(location);
    $result=curl_execute();
    curl_close();
    return($result==='I exist')?true:false;
}

Now I'm a bit stuck because I want my resources index to display information. But I also want to use it to say 'I exist' when checking for the resource. Is this possible? Or should I just use an additional file like a normally sane person? XD

bashleigh
  • 8,813
  • 5
  • 29
  • 49

2 Answers2

0

This isn't going to practically work because users typically aren't going to have PHP installed. You can allow them to download a PHP file.. sure but unless they have a web server running it's not going to work. On top of that they'll then need to have the curl extension etc..

See here to check if an extension is loaded: http://php.net/manual/en/function.extension-loaded.php

EM-Creations
  • 4,195
  • 4
  • 40
  • 56
  • yea the idea is that it's a PHP file that they can run locally. :) so should I also check to see if they have curl installed? – bashleigh Jul 14 '15 at 15:44
  • Yes that's a good start see here: http://stackoverflow.com/questions/14626262/retrieve-extension-version-in-php/14626296#14626296 to get the extension (should be able to work out if it's installed or not). And: http://php.net/manual/en/function.extension-loaded.php – EM-Creations Jul 14 '15 at 15:45
0

From what you've described, I'd really recommend using JS and AJAX to run the front-end of things. Making it, essentially, a HTML5-application. Using PHP to run things client side is almost never going to work, and if you do get it to work there's a huge investment cost on both yours and your users behalf.

Use PHP on the server side to generate said data, pre-populate the HTML-page with the results, and then have a AJAX-call to the server to refresh the contents. This could be based upon a timestamp, a meta-tag with a cache timeout or similar techniques.
Then you could use the same AJAX-API to check for stylesheets and such, and then just append/replace the DOM nodes as necessary.

ChristianF
  • 2,068
  • 9
  • 14