Main Page | Class Hierarchy | Class List | Directories | Class Members | Related Pages | Examples

small_example.php

This is a simple example of how to use gsQuery

<?php header("Content-type: text/html", TRUE); // application/xhtml+xml normally, but M$ does not know what web standards are... 
?>
<?php
/*
 *  gsQuery - Querys game servers
 *  Copyright (c) 2004 Jeremias Reith <jr@terragate.net>
 *  http://gsquery.terragate.net
 *
 *  This file is part of the gsQuery library.
 *
 *  The gsQuery library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  The gsQuery library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with the gsQuery library; if not, write to the
 *  Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 */
?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>Small gsQuery Example</title>
    <link rel="stylesheet" type="text/css" href="style.css"/>
  </head>
  <body>
    <div id="basicInfo" class="block">
      <?php 
        // include gsQuery (adjust path if necessary) 
        include_once("../src/gsQuery.php"); 

        // adjust host, port and protocol
        $gameserver=gsQuery::createInstance("gameSpy", "terragate.net", 7787);
        
        // query server and check for success 
        if($gameserver && $gameserver->query_server(FALSE, FALSE)) {
          echo "<table><caption>Server info</caption>";

          // show servertitle
          echo "<tr><td>Servername:</td><td>".$gameserver->htmlize($gameserver->servertitle)."</td></tr>\n";
          
          // show gamever if available
          if($gameserver->gameversion!="") {
            echo "<tr><td>Version:</td><td>".htmlentities($gameserver->gameversion)."</td></tr>\n";
          }
          
          // show current/max players
          echo "<tr><td>Players/Max Players:</td><td>".htmlentities($gameserver->numplayers)."/".htmlentities($gameserver->maxplayers)."</td></tr>\n";
          
          // show mapname/maptitle
          echo "<tr><td>Mapname/Maptitle:</td><td>".htmlentities($gameserver->mapname);
          if($gameserver->maptitle) {
            echo "/ ".htmlentities($gameserver->maptitle)."</td></tr>\n";
          } else {
            echo "</td></tr>";
          }

          // show gametype
          echo "<tr><td>Gametype:</td><td>".htmlentities($gameserver->gametype)."</td></tr>\n";
          
          echo "</table>";
        } else {
          echo "Could not query server";
        }
      ?>
    </div>
    <div id="footer">
      <a href="http://validator.w3.org/check/referer"><img
         src="http://www.w3.org/Icons/valid-xhtml10"
         alt="Valid XHTML 1.0!" height="31" width="88"/></a>
      <a href="http://jigsaw.w3.org/css-validator/">
        <img style="border:0;width:88px;height:31px"
             src="http://jigsaw.w3.org/css-validator/images/vcss" 
             alt="Valid CSS!"/></a>
    </div>
  </body>
</html>

Generated on Sat Oct 15 16:51:55 2005 for gsQuery by  doxygen 1.4.4