Jump to content


Photo

GM-PHP Communication


  • Please log in to reply
34 replies to this topic

#1 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 06 October 2011 - 04:59 AM

GM-PHP Communication

Using PHP as an extension in this manner (or any other language used with AJAX) has tremendous advantages. Database manipulation, date and time functions, and file compression procedures are just a few of the many systems that are now accessible through GM. I have authored an article outlining a procedure to communicate between GM and PHP using AJAX (JavaScript) as an auxiliary language. Small amounts of PHP, JavaScript and SQL are assumed, but not needed. This is in a sense an "upgrade" from my short tutorial about using GM to manipulate a MySQL database containing apples, just abstracted to a more general guide and is much more thorough.

Please notify me of any errors I missed while proofreading. Suggestions or general comments are always welcome.

Download the PDF here.

Posted Image

For the sake of completeness, I have created a simple example using the method outlined in my article to create a highscore table. View the live demo or download the editable .GMZ file.

Enjoy.
  • 3
Posted ImagePosted Image

#2 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 06 October 2011 - 09:21 AM

Excellent, can't wait to take a read through this. I hope there's some form of data validation this time! :)
  • 0

html5ebook20.png


#3 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 06 October 2011 - 01:04 PM

Excellent, can't wait to take a read through this. I hope there's some form of data validation this time! :)

Not too much data validation this time, when when I find the time, I'm planning on writing a few more sections and this will be one of them. Another being a more detailed look at SQL statements.
  • 0
Posted ImagePosted Image

#4 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 06 October 2011 - 09:37 PM

Ah, I see. I figure it's good to have at least some basics there so people know the system is vulnerable :)
  • 0

html5ebook20.png


#5 OMGCarlos

OMGCarlos

    GMC Member

  • GMC Member
  • 329 posts
  • Version:GM:HTML5

Posted 06 October 2011 - 10:57 PM

Awesome write up, probably one of the best documented articles for GM I've seen recently - felt like I was reading from a text book which is a good thing! Definitely saving this for reference later. The links at the end was an excellent touch, didn't know w3 schools had a php tutorial series. My only criticism is that you should probably have stressed a bit more the fact that there are security risks involved with using php like True Valhalla said. Otherwise awesome work!
  • 0

#6 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

Posted 06 October 2011 - 11:15 PM

It's short but very well done. Consider also placing this on the tutorials section (probably with a [HTML5] tag in the topic name to allow it to be moved if they change the forum structure).
  • 0
"Let's leave the classics for your parents." - KC LC

#7 rukiskiller

rukiskiller

    GMC Member

  • GMC Member
  • 5 posts

Posted 07 October 2011 - 07:12 AM

That's just what i need. Thanks for the excellent work. In this way, GM can also work with database without any .dll files.

And a question, javascript can also communicate with database. why didn't you use javascript to do the work directly?
  • 0

#8 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

Posted 07 October 2011 - 08:01 AM

And a question, javascript can also communicate with database. why didn't you use javascript to do the work directly?


How so? The only way I know for a client-side javascript to access the database is through a server-side language like PHP using AJAX, which is used in this tutorial.
  • 0
"Let's leave the classics for your parents." - KC LC

#9 tomasart

tomasart

    GMC Member

  • GMC Member
  • 269 posts

Posted 07 October 2011 - 08:43 AM

Thanks a lot, works very fine.
  • 0

#10 goresoft

goresoft

    GMC Member

  • GMC Member
  • 132 posts
  • Version:GM:Studio

Posted 07 October 2011 - 09:09 AM

good work!! You made an excellent pdf!

It seems a part of university degree thesys. :biggrin:

But i 've a problem with your gmz. When i open it nothing seems to load. No objects, no extensions, no backgrounds.

Please check it!
  • 0
My games : ASTRO n. z. o.--||||--Fly Chris Fly!!(Android)
 
my facebook page : Blue Vessel Games Fan Page!
 
my twitter : @bluevesselgames
 
my Website : Blue Vessel Games 

#11 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 07 October 2011 - 10:55 AM

Even if it were possible to connect to a database directly, it would be silly as that means the username and password would be on the clients computer. Big security no no.
  • 0

Game Maker HTML5 Extensions
Mouse Extension | HTML Extension


#12 Destron

Destron

    GMC Member

  • GMC Member
  • 1251 posts
  • Version:GM:Studio

Posted 08 October 2011 - 07:09 AM

That's just what i need. Thanks for the excellent work. In this way, GM can also work with database without any .dll files.

And a question, javascript can also communicate with database. why didn't you use javascript to do the work directly?


JavaScript cannot directly communicate with an SQL database. You have to use Ajax or PHP to connect to a db. Javascript is client side only.
  • 0

HTML5 INI Saving Example | HTML5/GMS Saving/Loading/User Login with PHP/MySQL/Async | GameMaker Examples/Tutorials
Those who try to do something and fail are infinitely better than those who try to do nothing and succeed.


#13 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 11:56 AM

You just gotta love what php/javascript has to offer.

http://syntaxgames.com/game/

The link above is to an example of a level editor that uploads levels online for all to play. Very rushed and unfinished.
  • 1

Game Maker HTML5 Extensions
Mouse Extension | HTML Extension


#14 OMGCarlos

OMGCarlos

    GMC Member

  • GMC Member
  • 329 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 04:00 PM

Whao Schalk very nice example, that could be very useful if you work on it a bit more!
  • 0

#15 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:28 PM

Thanks for the feedback!

I'm hesitant about creating a section about security, because it won't easily be abstracted to the general procedure, i.e. it would have to be specific to what the PHP is doing. But I'll come up with some way-perhaps restructuring the document.

I'm also thinking about adding in a few, less formal sections with examples and whatnot.

Interesting implementation, Schalk.
  • 0
Posted ImagePosted Image

#16 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:46 PM

It might be nice to add something about caching. For example instead of doing /highscore.php you would do /highscore.php?rand=41209 so it doesn't retrieve the cached stuff
  • 0

Game Maker HTML5 Extensions
Mouse Extension | HTML Extension


#17 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:50 PM

Good idea. I was also thinking about including jQuery, which if I'm not mistaken, has a parameter to handle caching in the .ajax method.
  • 0
Posted ImagePosted Image

#18 OMGCarlos

OMGCarlos

    GMC Member

  • GMC Member
  • 329 posts
  • Version:GM:HTML5

Posted 08 October 2011 - 10:56 PM

It does, and its as easy as using $(element).ajax();
  • 0

#19 cerberus150

cerberus150

    GMC Member

  • New Member
  • 33 posts
  • Version:GM:HTML5

Posted 09 October 2011 - 04:08 AM

good work!! You made an excellent pdf!

It seems a part of university degree thesys. :biggrin:

But i 've a problem with your gmz. When i open it nothing seems to load. No objects, no extensions, no backgrounds.

Please check it!

Same here, it gives me nothing.
  • 0

#20 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 873 posts
  • Version:GM:Studio

Posted 09 October 2011 - 04:24 AM

You just gotta love what php/javascript has to offer.



The link above is to an example of a level editor that uploads levels online for all to play. Very rushed and unfinished.

Would you be as kind as to upload the source to that? (be sure to blank out any username's or passwords you have stored! ;) )
  • 0

#21 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 09 October 2011 - 06:37 PM


You just gotta love what php/javascript has to offer.



The link above is to an example of a level editor that uploads levels online for all to play. Very rushed and unfinished.

Would you be as kind as to upload the source to that? (be sure to blank out any username's or passwords you have stored! ;) )

I assume he just used text files stored on the server or a MySQL database. The program could write the level data into a text file with PHP and save it to a specific directory. To generate the list of levels, PHP would only have to iterate through that directory and return the list. It could also just write the level data into a SQL row entry, which I think would be much easier. Returning the list of levels would be as simple as SELECT * FROM levels LIMIT 0,10.
  • 0
Posted ImagePosted Image

#22 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 09 October 2011 - 11:00 PM

My code is too embarrassing to share sorry :P. But yeah I just had a ini file that had the names of all the levels then in the same directory there were the files 0.txt, 1.txt, 2.txt etc. Not very flexible at all.
  • 0

Game Maker HTML5 Extensions
Mouse Extension | HTML Extension


#23 Joe H

Joe H

    GMC Member

  • GMC Member
  • 354 posts
  • Version:GM:Studio

Posted 17 October 2011 - 04:45 PM

I cannot find the "import" option under the File menu. The help file says that it should be there, but I do no see it. Am I looking in the wrong place? Where is the import function for the .gmz file?

After referring to THIS THREAD I attempted to import the gmz file in the manner suggested. It still appears to be a blank file and no resources are imported. Any suggestions?

Edited by Joe H, 17 October 2011 - 05:05 PM.

  • 0

Independent Games by Joe and Matt:
evg_logo_header_125h.png

Spoiler

#24 Joe H

Joe H

    GMC Member

  • GMC Member
  • 354 posts
  • Version:GM:Studio

Posted 19 October 2011 - 06:33 AM

Anyone have any information on this?
  • 0

Independent Games by Joe and Matt:
evg_logo_header_125h.png

Spoiler

#25 Zeond Games

Zeond Games

    Tactical Recon Developer

  • GMC Member
  • 115 posts
  • Version:GM8

Posted 19 October 2011 - 01:41 PM

You're amazing....
  • 0


Lead Programmer of-
Posted Image
Contributes to-
Posted Image
Develops in-
Posted ImagePosted Image


#26 Psalms23

Psalms23

    GMC Member

  • New Member
  • 163 posts

Posted 05 November 2011 - 03:23 AM

How to open .gmz?
  • 0
The LORD is my shepherd; I shall not want. He makes me lie down in green pastures.
He leads me beside still waters.
He restores my soul. He leads me in paths of righteousness
for his name’s sake. Even though I walk through the valley of the shadow of death,I will fear no evil,
for you are with me;... - Psalms 23

#27 123tomek

123tomek

    GMC Member

  • New Member
  • 14 posts

Posted 23 November 2011 - 10:11 AM

How to open .gmz?



There is description.
  • 0

#28 azcodon

azcodon

    GMC Member

  • GMC Member
  • 224 posts
  • Version:Unknown

Posted 24 November 2011 - 02:24 AM


How to open .gmz?



There is description.

**** **** ****
gm html5 can not read data of function as we call function
eg.
//in javasript
function sum(a,b)
{ return a+b; }
//in gm
add extension with function sum
c=sum(2,3) <-------unknown **** **** ****
  • 0

#29 Psalms23

Psalms23

    GMC Member

  • New Member
  • 163 posts

Posted 24 November 2011 - 06:49 PM

Nice.. Could this be used to read the time, so the game knows what time it is in real life, and then do checks on the time and execute events.

For example, say I want an object to appear in the room at 11.00am new york time, could I somehow read that off a site like this:http://www.timeanddate.com/worldclock/city.html?n=179

and then do checks on the time?
  • 0
The LORD is my shepherd; I shall not want. He makes me lie down in green pastures.
He leads me beside still waters.
He restores my soul. He leads me in paths of righteousness
for his name’s sake. Even though I walk through the valley of the shadow of death,I will fear no evil,
for you are with me;... - Psalms 23

#30 tangibleLime

tangibleLime

    Lunatic

  • GMC Elder
  • 2520 posts
  • Version:GM:HTML5

Posted 26 November 2011 - 08:50 PM

Yes, PHP can easily echo the time and date in regards to a particular time zone. In fact, you can do it with just JavaScript too.

About the editable: I probably exported it wrong. I'll eventually get a working version up.
  • 0
Posted ImagePosted Image

#31 fortfun

fortfun

    GMC Member

  • New Member
  • 5 posts
  • Version:Unknown

Posted 20 December 2011 - 10:32 PM

Any chance of writing a tutorial that shows how Gamemaker and Javascript could populate an HTML form for those of use using a language other than PHP? I'm using Coldfusion to talk with MySQL. If I knew how to populate a generic HTML form, I could do the rest.
Thanks!

GM-PHP Communication

Using PHP as an extension in this manner (or any other language used with AJAX) has tremendous advantages. Database manipulation, date and time functions, and file compression procedures are just a few of the many systems that are now accessible through GM. I have authored an article outlining a procedure to communicate between GM and PHP using AJAX (JavaScript) as an auxiliary language. Small amounts of PHP, JavaScript and SQL are assumed, but not needed. This is in a sense an "upgrade" from my short tutorial about using GM to manipulate a MySQL database containing apples, just abstracted to a more general guide and is much more thorough.

Please notify me of any errors I missed while proofreading. Suggestions or general comments are always welcome.

Download the PDF here.

Posted Image

For the sake of completeness, I have created a simple example using the method outlined in my article to create a highscore table. View the live demo or download the editable .GMZ file.

Enjoy.


  • 0

#32 beatson

beatson

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 05 January 2012 - 08:32 AM

I'd just like to point out to anyone interested: If you're wanting to host your game elsewhere to the server that the php file is located, you might need to add this to the top of the file:
header('Access-Control-Allow-Origin: *');
In TangibleLime's example, it should still add the score to the database, but it won't return anything and you'll be given an access allow error.
  • 1

VIS Design - Quality Web Design & Development


#33 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 550 posts
  • Version:GM:Studio

Posted 12 January 2012 - 04:15 AM

I'm implementing something very similar to this in one of my games. I noticed on the highscore list in this example that someone managed to give themselves an absurdly high score via exploitation of some sort of security hole.

Could somebody explain how this could have (potentially) happened? The only security risk that I see is on the javascript side of things if the user pretended to be the client...

I'm not well versed in online communication security, so a detailed explanation and/or a pointed finger in a more secure direction would be very much appreciated!

Edited by Oracizan, 13 January 2012 - 12:11 AM.

  • 0

#34 beeproductions

beeproductions

    Helping gmc users

  • GMC Member
  • 1321 posts
  • Version:GM:Studio

Posted 21 January 2014 - 03:42 AM

You could call me a noob.and this noob wanna use this but can't figure out how?!

 

Haven't seen the php file..read the pdf..made a php file with the code inside pdf..nada..zero snap..a bit of guidance pls?:Dthanks


  • 0

col-img1.pngcol-img4.png

bannersig.png

 

 


#35 Nic0demus

Nic0demus

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 20 November 2014 - 04:38 PM

Guys, I need to get this working, but then asynchronous, so I can load it while the player is playing. Other wise the code would wait for the database to do the query and then continue and I don't want that. Although I don't know where to "catch" the callback that is generated. I was trying to use http_get and the Asynchronous-HTTP event but it doesn't work in HTML5. Can someone tell me what I should do to make it work async?


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users