-
How would I get data from a php script?
In my new game it requires users to register to submit their scores. I want the registration process to happen in the game and check the MySQL database on my web server and if a username doesn't already exist for what they have chosen insert it in to the database.
If the query is successful then I want the game to display a message to that effect and likewise if the query fails.
Any ideas anyone?
Many thanks in advance!
Steve
-
Re: How would I get data from a php script?
The download object lets you specify a URL to download from; just include the usual HTTP headers in the URL and have the PHP generate the info you need.
Basically, you would tell the Download Object "Download 'HTTP://www.whatever.com/highscores.php?myusername=username&mypassword=pass word&myhighscore=highscore'"
Then write the PHP script to take that information and output a file which you can then read from inside MMF using either the .ini object or another file extension. That file will be downloaded and you can give the user the appropriate message.
-
Re: How would I get data from a php script?
That's a decent idea, actually - I hadn't thought of doing it that way, but outputting a file readable by INI might be a lot easier than directly calling the PHP page with the MooSock object if you need to return a lot of information.
My high score tutorial describes the MooSock method of communicating with MySQL databases through PHP pages.
http://www.clickteam.com/eng/resources/online_score/onlinescoreboards.html
http://www.clickteam.com/eng/resources/online_score/dxn-scoreboards.zip
-
Re: How would I get data from a php script?
The download object doesn't let you download any dynamic URL? There was a post in the bugs forum and i'm having the same problem.
-
Re: How would I get data from a php script?
Ah... that would spoil it a bit. Nice idea, though.
-
Re: How would I get data from a php script?
Yeah, that would pooch it. Is that a bug or is it a security feature? I was planning to use it that way myself in the future...
-
Re: How would I get data from a php script?
MooSock or another socket extension would be easy to use.
I think DavidN's tutorial goes thru all of that.
-
Re: How would I get data from a php script?
MooSock does the job quite well but its stability is questionable on some machines from the testing I have done. Sometimes after extended use the extension just stops responding. The best answer I have been able to come up with is a possible memory leek that creeps up over time. Is there anyone we can report MooSock bugs to now that 3ee is gone?
-
Re: How would I get data from a php script?
Moosock worked a treat, thanks DavidN.
@ Maggott: I'm not sure to be honest but it was posted as a bug somewhere on here.
I found that if you don't include any HTML stuff like <head> <body> etc in the PHP script then you don't even have to do any parsing.
-
Re: How would I get data from a php script?
Even if you get no Html headers, you'll get HTTP, don't you ?
-
Re: How would I get data from a php script?
I think it depends on the get/post method that you're using, or some other small factor - it's definitely possible to get a plain PHP script to return a simple easily-parsed string without having to pare off a heap of tags, as the tutorial covers that.
-
Re: How would I get data from a php script?
I'm fairly sure you get a plain return if you use "GET /file.php" without a http version number or headers. It's a left-over from http 0.9 iirc and web servers don't all support it, so it's kind of stupid to use.
-
Re: How would I get data from a php script?
Oh... should I change it then? Or not as it's already working on my web server?
-
Re: How would I get data from a php script?
-
Re: How would I get data from a php script?
I hope not, as I've just taught people to use something remarkably similar.
-
Re: How would I get data from a php script?
Quote:
Originally Posted by Steven
Is that code not right then?
Doesn't look right to me. It never connects, and for some reason it attempts to host a server. If I were coding it, it'd also fully adhere to the HTTP 1.1 standard. I'm sure there are many examples on the old CT forum at least.
-
Re: How would I get data from a php script?
I see a listen command up above, I have never needed that to send or recieve from a PHP page using MooSock.
-
Re: How would I get data from a php script?
Quote:
Doesn't look right to me. It never connects, and for some reason it attempts to host a server.
Quote:
I see a listen command up above, I have never needed that to send or recieve from a PHP page using MooSock.
How comes it works in my game? :confused: It actually works flawlessly. I've heard that some people have lots of trouble with Moosock, but I haven't had 1 after following DavidN's tutorial.
Would you guys like to upload a .mfa of it working? Might help me to see if it works on everyones PC.
-
Re: How would I get data from a php script?
Quote:
Originally Posted by Joshtek
Quote:
Originally Posted by Steven
Is that code not right then?
Doesn't look right to me. It never connects, and for some reason it attempts to host a server. If I were coding it, it'd also fully adhere to the HTTP 1.1 standard. I'm sure there are many examples on the old CT forum at least.
I'm quite familiar with networking terminology. Listening on a port means that your application is waiting for another computer to connect to yours on that port, just like a server program. So that line is completely unnecessary.
-
Re: How would I get data from a php script?
It seems that's right - I saw that in the first MooSock tutorial I ever read and just assumed that it meant "wait for a response coming back on port 80". This requires quite a major edit.
-
Re: How would I get data from a php script?
I took it out and it still works :cool:
-
Re: How would I get data from a php script?
there is no need for the listen part, you need an event though, "on can" something, it recieves or something, dont have MMF open so cant check
it may work but firewalls will block your app and a/v might report it as a trojan
-
Re: How would I get data from a php script?
Yes, but I don't think it would matter. HTTP can transfer files that aren't HTML. In fact, the only real difference between HTTP and FTP is that is that HTTP does not maintain a connection whereas FTP does.
-
Re: How would I get data from a php script?
Actually from http 1.1 there is the "connection: keep-alive" option to keep the connection open. The REAL difference between http and ftp is ftp has separate command and data connections.
-
Re: How would I get data from a php script?
@ neat_Kliker2: I've got that part done and as i've mentioned previously it works a treat. Only trouble im going to have is getting people who aren't too technically minded to get the game to work through their firewall (if they have one)
-
Re: How would I get data from a php script?
That's always going to be very difficult, as non-technical people are continually told to be paranoid of everything that even touches their network connection - though if everything goes through port 80, it should be avoided.