log in account system?

How can I make a account/register system for my aplication?

I need that the user register an account

so I need to send the login and password to an server in web to store this values

and how to make the log in after registration? how to get the new user from server?
thanks [import]uid: 23063 topic_id: 16358 reply_id: 316358[/import]

I’m building a PHP based API that can run on a typical web hosting account with a MySQL database. I have all the logging in and registering working. I even have web based forms to create the account and manage logging in and out. What I don’t have working yet is the iPhone/iPad screens to accept the login information and account creation information and verify that it works. With a hard coded login/password, I’m able to login, retrieve a session ID from my Corona App.

Its no where near being bundled up yet as a package and since my game is in development if I bundled up what I had, it would give others too much of an ability to steal my game plan.

So I can basically tell you this:

You need a hosted database.
You need some scripts on the backend that can respond to HTTP GET or PUT requests that take the login information and post it to the database/look up information in the database.

You can maybe google and see if there’s a canned package that does this, or perhaps there are some examples using Amazon’s hosted cloud service too.

But on the Lua side, you do network.requests like this:

function login(username, password, callback)  
 print("login")  
 network.request( "http://mysite.com/api/login.php?playername=" .. mime.b64(username) .. "&password=" .. mime.b64(password), "GET", callback )  
end  

This system uses HTTP GET requests and uses the require(“mime”) to encode the password and login ID so they are not transmitted in clear text.

This is an async call, so you have to have a function for the request to call back to. You’re script on the server side simply outputs a JSON string and then you decode it in your call back function.
[import]uid: 19626 topic_id: 16358 reply_id: 60991[/import]

thank you @robmiracle
but I don’t know how to do this :S

anyone else knows how make it?

and another question… how can I save informations to my database from my aplication?

thanks [import]uid: 23063 topic_id: 16358 reply_id: 61305[/import]

You really have 3 options:

  1. Learn that part of the system so you can do it yourself. You get marketable skills out of it too.

  2. Partner with someone who knows that part of the puzzle and work out whatever kind of deal you can with them.

  3. Pay someone to do your backend work for you.

[import]uid: 19626 topic_id: 16358 reply_id: 61341[/import]

I will pick the first one but can you show the direction?
where I can find this part of code to study

thanks [import]uid: 23063 topic_id: 16358 reply_id: 61346[/import]

http://developer.anscamobile.com/code/upload-binary-corona-php-script

maybe I can use that?

and modify my .php to make the registration for me

[import]uid: 23063 topic_id: 16358 reply_id: 61348[/import]

Try using google and search for “php mysql web service” or “php mysql login service”

http://davidwalsh.name/web-service-php-mysql-xml-json
This article gives some basics, their example fetches a list of blog posts from its database.

This one is a bit more complex, but has some good information:

http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app

http://www.roseindia.net/tutorial/php/phpdatabase/PHP-MySQL-Login-Form.html

http://tutorialzine.com/2009/10/cool-login-system-php-jquery/

http://www.phpeasystep.com/phptu/6.html

That should get you started. [import]uid: 19626 topic_id: 16358 reply_id: 61352[/import]

Thank you for your assistence
realy [import]uid: 23063 topic_id: 16358 reply_id: 61355[/import]

@robmiracle

can you help me with “callBack” function please?

I don’t know how to return a string to my app from php

I tryed to use “event.response” but don’t work right :T

thanks [import]uid: 23063 topic_id: 16358 reply_id: 62376[/import]

Well have you tried calling your PHP script from the brower’s location bar? What is it actually outputting?

What is the URL and expected parameters? Do you have a test account/password I can try? [import]uid: 19626 topic_id: 16358 reply_id: 62380[/import]

I’m trying to do a register account first

so this is the code:

local mime = require "mime"  
  
local login = "larila"  
local senha = "12345abc"  
local funcLogin  
funcLogin = function( username, password, callback )  
 print( "login" )  
  
 local function callBack( event )  
 if ( event.isError ) then  
 print ( "Network error - download failed" )  
 else  
 print( "bla" )  
 end  
  
 print ( "RESPOSTA DO SERVIDOR: " .. event.response )  
 end  
  
 network.request( "http://www.universopositivo.com.br/iphone/pesquisa.php?login=" .. mime.b64( username ) .. "&senha=" .. mime.b64( password ), "GET", callBack )  
end  
funcLogin( login, senha )  

and in the terminal I get this:

[php]RESPOSTA DO SERVIDOR:

Untitled Document Jw Metais

[/html]

[/html]
[/php] [import]uid: 23063 topic_id: 16358 reply_id: 62387[/import]

Well for one thing you never pass a call back function to your login function. Secondly, your call back function is inside your login function.

Try this:

[lua]local mime = require “mime”

local login = “larila”
local senha = “12345abc”
local funcLogin

local function callBack( event )
if ( event.isError ) then
print ( “Network error - download failed” )
else
print( event.response )
end
end

funcLogin = function( username, password, callback )
print( “login” )
network.request( “http://www.universopositivo.com.br/iphone/pesquisa.php?login=” … mime.b64( username ) … “&senha=” … mime.b64( password ), “GET”, callBack )
end

funcLogin( login, senha, loginCallback )[/lua]

[import]uid: 19626 topic_id: 16358 reply_id: 62401[/import]

same thing in event.response

can I put a variable in my php and print her with event.response?

I need to return a string from my php but I don`t know how to call her back

I have tried to put

 print( event.response.test ) 

and I get NIL

I have “test” in my php as an variable [import]uid: 23063 topic_id: 16358 reply_id: 62415[/import]

another thing… if I use “mime.b64( username )” and “mime.b64( password )” I get grap in my server

you sure that I need to put “mime.b64” ?
[import]uid: 23063 topic_id: 16358 reply_id: 62416[/import]

mime.b64 encodes your username and password so they are not sent in clear text across the internet. You have to in your PHP script un-encode them.

In your php script, do something like this;

 $login = base64\_decode($\_GET["login"]);  
 $senha = base64\_decode($\_GET["senha"]);  

If you don’t care about encoding the login and password, just skip the mime.b64 stuff completely.
In your call back, you get an event structure/table called “event” (based on your setup above) and that table has a member called response (event.response). The contents of that is the entire data returned from the PHP script. So if your script outputs “It’s a beautiful day in the neighborhood”, you should expect your app to print on the console:

It’s a beautiful day in the neighborhood

when you do a print(event.response).

Building this system is two part, first making sure your app works and is communicating with the server and secondly making sure the server side is doing what is expected.

I don’t know what you want your PHP script to tell your mobile app when an account is successfully registered or when it successfully logs in. In my case, I have the PHP script print some JSON structure out:

<?php <br> $results = array();  
 $results["sessionID"] = sessionID;  
 $results["message"] = "Success";  
 echo json\_encode($results);  
?\>  

I don’t print any additional information, like HTML tags and I get that JSON structure as the contents of my event.response, which I can pass to json.decode to get a Lua table to use.

But you are your own programmer and what your login/register.php spits out is up to you. though I would think that if you’re getting a bunch of HTML somethign else is going on. Your results is getting a blank HTML document that is executing a script to say “Success” and then redirecting you to some other page. Which is what you get if you actually run that page on your own directly in the browser.

So you are successfully capturing what the server is sending. You just are not getting what you want. [import]uid: 19626 topic_id: 16358 reply_id: 62421[/import]

I know I’m a bit late to this thread but it’s been a massive help and I finally managed to get a login working correctly. For those interested, I used a combination of
what Robmiracle suggests (the lua and “base64_decode” on the php size),
more lua:     http://www.coronalabs.com/blog/2012/11/20/how-to-download-json-data-from-mysql-using-corona-sdk/
and the php (example 3)     http://www.w3schools.com/php/func_mysql_real_escape_string.asp
 
Also note: The php code “mysql_real_escape_string” must be placed AFTER a database connection is established otherwise it will return false.

I know I’m a bit late to this thread but it’s been a massive help and I finally managed to get a login working correctly. For those interested, I used a combination of
what Robmiracle suggests (the lua and “base64_decode” on the php size),
more lua:     http://www.coronalabs.com/blog/2012/11/20/how-to-download-json-data-from-mysql-using-corona-sdk/
and the php (example 3)     http://www.w3schools.com/php/func_mysql_real_escape_string.asp
 
Also note: The php code “mysql_real_escape_string” must be placed AFTER a database connection is established otherwise it will return false.