Purpose: Players online with a remote connection and no mysql!
Difficulty: 6/10
Tested On: Devolution
Requirements: An FTP client, I suggest Filezilla or SmartFTP. You can get your FTP details from your website's host.
Add this method and imports to the client class (took it from Devolution v7 ):
Code:
import java.net.URL;
import java.net.URLConnection;
import java.io.DataInputStream;
public void savePlayers() {
try {
// NOTE: Change password to your own password.
URL page = new URL("http://filthscape.net76.net/players_online.php?password=ap2572hfbh5fd&players= "+PlayerHandler.getPlayerCount());
URLConnection conn = page.openConnection();
DataInputStream in = new DataInputStream(conn.getInputStream());
String source, pageSource = "";
while ((source = in.readLine()) != null) {
pageSource += source;
}
} catch (Exception e) {
e.printStackTrace();
}
}
Basically it just opens a page. The URL should be in this format:
Code:
http://yourwebsite.com/players_onlin...layers=PLAYERS
Call this method whenever someone logs in, or is disconnected.
Now upload these two files to your website:
players.txt:
Code:
0
The next part is important!!!!!!! In your FTP client, connect to your website and right click on players.txt. You should see something like 'permissions'. Click it. There should be checkboxes or something like that.
CHECK THE BOXES UNDER 'write', 'writable', or w/e it's called EXCEPT for public! This makes it so that players.txt can be written to by everyone except the public (like from another website).
So you should check owner and owner's group.
Add players_online.php:
Code:
<?php
$password = ap2572hfbh5fd; // change this to your password
$rsc = fopen("players.txt", 'r') or die("Failed to open file!");
$players = fread($rsc, filesize("players.txt"));
if ($password == $_GET['password']) {
$wsc = fopen("players.txt", 'w') or die("Failed to open file!");
fwrite($wsc, $_GET['players']);
header('Location:
http://filthscape.net76.net/players.php');
}
?>
Don't forget to change the password to your own! Basically, $rsc loads the file 'players.txt' in a reading format, hence the 'r', then $players reads the file. Then it checks if the passwords match (so other people can't edit this). If they match, it opens the file in a writable format, hence the 'w'. Then it writes to the file the players. Then, finally it redirects you to your home page (you should change that redirect to your homepage.)
This is how you retrieve the players:
Code:
<?php
include "players_online.php";
echo "There are currently $players players online!";
?>
Include does what it says. It includes the php file so you can take variables from it. In this case, we want the $players variable. echo prints out the statement after it. If you use these quotes: 'text' it will print out the actual variable name. I.E
Code:
echo 'There are currently $players players online!';
WOULD APPEAR AS:
There are currently $players players online!
But if you use these quotes: "text"
Code:
echo "There are currently $players players online!";
WOULD APPEAR AS:
There are currently 100 players online!
You are done!
DON'T FORGET TO CHANGE PASSWORDS!!!!
Or you can do :: players
Jake

Please Rep++