Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by IronFurball · Apr 04, 2013 at 12:45 PM · c#webrequestphpsqlftp

Get echo output from PHP script which is on an FTP server with C#

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:

     $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 :P

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nachtmahr · Apr 04, 2013 at 12:53 PM 1
Share

from ftp cO??? Can you FTP Server Proccess PHP files? Normaly you need something like Apache running on your Server.

avatar image IronFurball · Apr 04, 2013 at 12:58 PM 0
Share

I 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 WA$$anonymous$$P installed(and apache) on my own PC. Thanks for your awnser.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Dave-Carlile · Apr 04, 2013 at 01:29 PM

An FTP server doesn't process PHP, or any other language - it simply serves up files. You need a web server in order to process/execute the PHP scripts. Setting up a web server is out of the scope of Unity Answers. You should have no trouble finding assistance using Google. But, I would hope your server maintenance guy would already have a web server set up, or would be able to do it for you.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IronFurball · Apr 08, 2013 at 09:16 AM 0
Share

Thanks for your reply it cleared things up a little bit. I told the the server maintenance guy that i needed a webserver to run the php files, and he told me that the ftp server already is a webserver , running php5, and that I just need to put the website on it.

I'm still a bit confused as to how to do this though, because I simply have the php files, no webesite build around it or anything.

avatar image Dave-Carlile · Apr 09, 2013 at 12:06 AM 1
Share

Ins$$anonymous$$d of ftp://ndc38.colo.bit.nl/map/ReadCities.php, try http://ndc38.colo.bit.nl/map/ReadCities.php

And use Http response ins$$anonymous$$d. This should go through the http protocol rather than ftp, and the web server will execute the PHP to produce the web page. This is assu$$anonymous$$g the web server is configured correctly.

Also, you might look into use Unity's WWW class rather than the .NET classes.

avatar image IronFurball · Apr 09, 2013 at 07:49 AM 0
Share

Thanks dave I've got it all working now, I got some extra help from the server guy too :P

I was already actually using the WWW class but I got so confused witht the whole ftp thing, I thought maybe i needed a diferent way of connecting to it :P

Thanks everyone for the help, this question can be closed :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

When built for web player, my php doesn't return the datatable. Works just fine in standalone build and while editing. 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Download multiple files from server 2 Answers

Is it possible to create GameObjects dinamically from a server? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges