way to communicate with php pages?

New releases and general discussions.

Post » Mon May 12, 2008 9:37 am

Will there ever be a way to make a game communicate with a php file.

For instance i am making a web-rpg and it would be so much more awesome if i could make a desktop game that can communicate with it.
B
3
S
2
G
5
Posts: 301
Reputation: 2,302

Post » Mon May 12, 2008 10:49 am

You could try using the Download object to download a page such as myfile.php?data=1234...
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,554

Post » Mon May 12, 2008 10:51 am

[quote="Ashley":1x81r3z7]You could try using the Download object to download a page such as myfile.php?data=1234...[/quote:1x81r3z7]

But that wouldn't actually do anything useful, i wouldn't be able to send anything back to the page so the database gets updated with what i do on the desktop version?
B
3
S
2
G
5
Posts: 301
Reputation: 2,302

Post » Mon May 12, 2008 10:52 am

You can pass information to the server in the query string, and return values from the server in the page that is generated. That's two way communication. What else do you need?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,554

Post » Mon May 12, 2008 11:10 am

So if i tell it on startup to download "text.php?name=test"

And have my php file add "test" to a database field if it is there, it should work then your saying?

But there is no way to check if something was right, for example if i wanted the user to login, i can't check if username or password is wrong from the one in the database.
B
3
S
2
G
5
Posts: 301
Reputation: 2,302

Post » Mon May 12, 2008 11:28 am

Yes you can,

"SELECT * FROM `login` WHERE user='" urlencode($_GET['user']) . "';'"
(note this is an example.. there's much better tutorials on this all over the internet)

then see if the login was successful, and if so

echo "LOGGEDIN";

The download object could be modified to download a file into memory, to make this easier, but communication with PHP and ASP is possible.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Mon May 12, 2008 11:30 am

That is fine but how do i let the desktop app now if they have been able to login, echoing "loggedin" is fine on the script, but it doesnt exactly tell the desktop app that they are ok now does it?
B
3
S
2
G
5
Posts: 301
Reputation: 2,302

Post » Mon May 12, 2008 11:31 am

I think you misunderstand how PHP works. If the download object requests a page then it'll execute the script on it and download the result, in this case LOGGEDIN.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Mon May 12, 2008 11:47 am

Ah i didn't know that, i will give it a go then see what i can come up with.

What would be a good way to check the login then, do i need to open the downloaded file and check it for a string saying "loggedin" ?
B
3
S
2
G
5
Posts: 301
Reputation: 2,302

Post » Mon May 12, 2008 11:58 am

I think you are getting confused between server side and client side applications.

Using an external PHP page to check if someone is logged in to allow access to a desktop application is possible but an awkward way to solve a problem.

I had a similar problem once, and all you need to do is create a file (or a collection of files) that return results to specific queries and then your desktop application would parse the output.

As rich and ashley have said, if you download the file the server will be downloading it much in the same way a web user would download it. The server is still executing the script before it uploads it to the client.

Tom
Image Image
Scirra Founder
B
124
S
37
G
25
Posts: 3,945
Reputation: 44,897

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests