xxZeus

zain

Aug 26th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1.  
  2. /*  The code below should be on your VPS where your gaming server is.
  3.     Now lets say your gaming server ip is 1.2.3.4 and lets say this file name is getPlayerInfo.php
  4.     so place the file in web server folder so that its can be accessed by path like http://1.2.3.4/getPlayerInfo.php
  5. */
  6. <?php
  7.     if(!isset($_GET['id']))die('No ID specified!'); // stop if no ID is specified, you can pass the id like this: getPLayerInfo.php?id=55
  8.    
  9.     $id = mysqli_escape_string($con, $_GET['id']); // escape to prevent SQL injection
  10.    
  11.     $con = mysqli_connect(...);
  12.    
  13.     $res = mysqli_query($con , "SELECT * FROM tableName WHERE id='$id'");
  14.     $res = mysqli_fetch_array($res);
  15.    
  16.     echo json_encode($res); // encodes string in JSON format which can be decoded on main website
  17.    
  18.     mysqli_close($con);
  19. ?>
  20.  
  21. /* MAIN WEBSTIE PART : */
  22.  
  23. /* Now to get information from server on your main website on other host, you can do as follows: */
  24. <?php
  25.    
  26.     $id = SomePLayerID?;
  27.    
  28.     $dataInString = file_get_contents('http://1.2.3.4/getPlayerInfo.php?id=' . id);// note the URL we pass ID as a $_GET parameter
  29.    
  30.     $decodedData = json_decode($datainString, true); // decode the encoded data
  31.    
  32.     // now you can access result here same as you did when you got result from MySQL, like this:
  33.    
  34.     echo "PLayer name is " . $decodedData['playerName'];//assuming there was a column named playerName in the table
  35. ?>
Add Comment
Please, Sign In to add comment