MinecraftQuery.class.php not working

Discussion in 'Systems Administration' started by JSOReborn, May 27, 2015.

  1. Hello all!

    So all day I have been working on this and it is still not working. So here is my website: http://jsocraft.com/index.php now you can see "There are currently 0 players online"

    Here is the code:
    Now here is the part on the index.php

    Now it is not updating it is just staying on "0" even when someone joins the server, I want it to update even though people don't refresh the website. However it is not working and not changing from 0 to 1 when someone joins.

    Can someone help me?
     
  2. $e is never set because it is only inside the catch block. Move the code in the if statement to the try block and the else statement to the catch block.
     
  3. So what should I do? I am a little confused?
     
  4. The variable $e is only usable inside the catch block. So if(!isset($e)) will always return true.
     
    • Useful Useful x 1
  5. The way PHP is developed, this is untrue. Scope isn't what you'd expect in PHP development, variables defined inside the scope of a conditional or try-catch are indeed accessible outside of their scope. This is because any variable defined outside of a function is in global scope, making it accessible anywhere else within global scope (not inside a function).

    He wants it to update without people refreshing the page, since PHP is processed before the page actually appears (without getting into flushing), you would need to query the player count using JavaScript AJAX.

    Before you ask how, please google how to ajax.