- Home /
Unity php functions
Hello, I have a php check login function on my webserver that returns either true or false via a checklogin function. How do I go about calling the php function from within unity? Assuming I already have the two strings for username and password. Thanks.
Answer by flamy · Jul 10, 2012 at 06:14 AM
you have to use either WWW class or WWWForm Class for this.
private IEnumerator authorize()
{
// replace php path with the address to the php file
string post_url =phpPath+ "?username=" + WWW.EscapeURL(profileName) + "&password=" + WWW.EscapeURL(password);
// Post the URL to the site and create a download object to get the result.
WWW hs_post = new WWW(post_url);
yield return hs_post; // Wait until the download is done
if (hs_post.error != null)
{
Debug.Log("error"+);
}
else
{
if(hs_post.text=="true")
{
//logged in..
}
else
{
//not logged in
}
}
}
// and somewhere in the code call
StartCoroutine(authorize());
check this link , this will explain you in a much better way.
Hi thanks for the response. $$anonymous$$y question should be restated as, if I have a checklogin function in my php file, how do I access it from unity code?
that should be simple.... if the php file has a lot of functions, you can pass another argument like username or password for which function to be called...
and in the php file check if the argument is equal to login and call the respective function. there aint a direct way to call the function you need.
ref: http://stackoverflow.com/questions/4360182/call-php-function-from-url
Since this is an old question, the OP was last seen several weeks ago and he only accepted 1 of his 30 questions, I accepted this answer.
Sorry, I have been gone for a long time with school. I am back now and to be honest when I first started using this site I was using it more like a forum and didn't understand how everything worked. Although now, a year later and a lot more experience using similar sites like StackOverflow, I know how important it is to accept answers. I'm already going through all my old questions. Sorry again.
Your answer
Follow this Question
Related Questions
Retrieving data from a WWW php call? 1 Answer
Multistage Delete with WWW 1 Answer
Unity CrossDomain.xml Still Required? What is wrong? 0 Answers
How do I properly send binary data (byte[]) to a MySQL database? 4 Answers
Unity - MySQL data loss 0 Answers