Posting to a PHP Script

I am new to Corona and have been working at it the last month trying to convert a game in the app store to Corona. I currently have the game Hairy Legs for sale and I figured a good way to learn Corona would be to try to convert Hairy Legs. I have got everything working except my web scores. I have looked in the forums and some other websites and I can not seem to get it. Any help would be greatly appreciated.

In the version that is out now it sends the name and high score using $_Get in the PHP script. I can not seem to figure out the right way to do this with Corona and Lua. All the samples code I have found do not seem to work when I make the changes to reflect the variables I am using.

Thanks Much in Advance,
Gary Gindlesperger [import]uid: 8533 topic_id: 5157 reply_id: 305157[/import]

Presumably the sample code you are looking at are the networking samples that come with Corona and use LuaSockets:
http://developer.anscamobile.com/content/network-0

I haven’t actually tried doing this yet myself, sorry. [import]uid: 12108 topic_id: 5157 reply_id: 17108[/import]

Thanks for the reply. I looked at that and some other LUA samples. The code on that link is for actually sending and receiving a file. I just want to submit a name and score, not really a file.

Thanks for the reply. [import]uid: 8533 topic_id: 5157 reply_id: 17125[/import]

The URL to connect to a PHP file is exactly the same as connecting to an HTML file only, y’know, ending in .php instead of .html So where the URL for a webpage looks like http://www.mysite.com/mypage.html the URL for a php script looks like http://www.mysite.com/myscript.php

Then variables are appended to the end of the URL like so
http://www.mysite.com/myscript.php?name=joe&score=2489

Many code frameworks will automate the appending of variables onto the URL (like, you say “here is my URL and here are my variables” and it returns the URL with the variables appeneded) but that’s all they’re really doing.

Then how to get the server to recognize this request as a PUT or POST instead of GET is not something I know off the top of my head. I haven’t done that in a long time. [import]uid: 12108 topic_id: 5157 reply_id: 17126[/import]

Thanks so much for your help. I have it half working. Here is the remaining problem. If I specify a value to submit it works, but I need it to be a variable.

With this:
http://www.mysite.com/myscript.php?name=joe&score=2489

Where name is joe and score is 2489 I need to change that so joe and the score are replaced by a variable.

So it would look something like this:
http://www.mysite.com/myscript.php?name=player1&score=highscore1 .

Now if I put that in as I have it above it does not work. It sets name to player1 instead of what the contents of the variable player1 is. The score just does not work because my PHP script is looking for a number. How do I designate this to use the actual variable?

Thanks so much for the help.
[import]uid: 8533 topic_id: 5157 reply_id: 17194[/import]

Don’t write out the entire string, build it from variables using … to append to a string. So like

url = "http://www.mysite.com/myscript.php?name="..player1.."&score="..highscore1  

It just occurred to me though that if you don’t already know the basics of how to send variables with a URL then I doubt you know how to implement security for your highscores. Notice how easy it is for a cheater to manually type in whatever number they want? You need to protect against those kinds of shenanigans. [import]uid: 12108 topic_id: 5157 reply_id: 17205[/import]

Thank you so much. I got it now. Works just like it does in the current version of the game. I was just lost on the format . My php section done and has been working for months tracking scores. This was the last hurdle I had in converting the game to Corona.

Thanks again jhocking. I really appreciate it. [import]uid: 8533 topic_id: 5157 reply_id: 17212[/import]