Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The code below should be on your VPS where your gaming server is.
- Now lets say your gaming server ip is 1.2.3.4 and lets say this file name is getPlayerInfo.php
- so place the file in web server folder so that its can be accessed by path like http://1.2.3.4/getPlayerInfo.php
- */
- <?php
- 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
- $id = mysqli_escape_string($con, $_GET['id']); // escape to prevent SQL injection
- $con = mysqli_connect(...);
- $res = mysqli_query($con , "SELECT * FROM tableName WHERE id='$id'");
- $res = mysqli_fetch_array($res);
- echo json_encode($res); // encodes string in JSON format which can be decoded on main website
- mysqli_close($con);
- ?>
- /* MAIN WEBSTIE PART : */
- /* Now to get information from server on your main website on other host, you can do as follows: */
- <?php
- $id = SomePLayerID?;
- $dataInString = file_get_contents('http://1.2.3.4/getPlayerInfo.php?id=' . id);// note the URL we pass ID as a $_GET parameter
- $decodedData = json_decode($datainString, true); // decode the encoded data
- // now you can access result here same as you did when you got result from MySQL, like this:
- echo "PLayer name is " . $decodedData['playerName'];//assuming there was a column named playerName in the table
- ?>
Add Comment
Please, Sign In to add comment