Yeah I know, quite the title. Allow me to explain,
For my school exams I am tasked with making a game which has to be playable in a browser, to do this, I’m using unity’s webplayer.
The game needs to keep track of highscores and such so I made a MySQL database which holds the scores.
To connect to the database and read out the scores and other such data, I have written a PHP script.
The PHP script is on an FTP server.
The PHP script echo’s the data it reads form the database, so if you’d run it in your browser, u’d get some text back like: “username;score”.
Now here comes the problem,
I used to use a C# script to read the output form the PHP file(the username + score). I did this using unity’s WWW class, however, sicne the PHP file has recently been placed onto the FTP server, a WWW request wont work anymore.
I’ve managed to get as far as connecting to the FTP server and reading the actual PHP file (the actual PHP code), but that’s of course useless to me! I need the html output it would give.
Here’s the code for all my scripts:
The PHP code:
<?php
$user_name = “someName”;
$password = “somePass”;
$database = “someDB”;
$server = “someIP”;
$dorpNaam;
$dorpX;
$dorpY;
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if (!$db_handle) {
die('Could not connect: ' . mysql_error());
}
$dorpNaam;
if (isset($_GET['dorpNaam'])){
$sql = "SELECT dorpNaam,dorpOmtrek,dorpX,dorpY FROM dorpen_en_steden";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) // loop to give you the data in an associative array so you can use it however.
{
echo $row['dorpNaam']."-".$row['dorpOmtrek']."-".$row['dorpX']."-".$row['dorpY'].';';
}
}else {
$sql = "SELECT dorpNaam FROM dorpen_en_steden";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) // loop to give you the data in an associative array so you can use it however.
{
echo $row['dorpNaam'].';';
}
}
mysql_close($db_handle);
?>
The C# code:
void ftp() {
string serverPath = "ftp://ndc38.colo.bit.nl/map/ReadCities.php";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);
request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential("helidrop", "5c1tLuae");
// Read the file from the server & write to destination
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
using (StreamWriter destination = new StreamWriter("hoi.txt"))
{
destination.Write(reader.ReadToEnd());
destination.Flush();
}
}
If any one has any advice on what to do, either how to get the echo form the PHP file or an alternative maybe? (as long as it doesn’t take to much time to implement).
I’d be incredibly grateful ![]()
PS: I hope the post is kinda clear ![]()
from ftp cO??? Can you FTP Server Proccess PHP files? Normaly you need something like Apache running on your Server.
– NachtmahrI don't think it can, I'm not really in charge of the serve, Everything I want to change, I have to request from the server maintenance guy. But are you saying that if I get apache running on the server, I could run the PHP script? How would I do that? PS: I DO have WAMP installed(and apache) on my own PC. Thanks for your awnser.
– IronFurball