- Home /
How to use php login Form [POST] with c#
Hello, so i want o make user loins in unity. I saw a tutorial on this, and they used WWW, but however the php script used method 'GET' instead of mehtod 'POST'. For all the programmers out there you know why this is bad. How do i have a c# scirpt that uses a php code with Post method instead of a get method? LINKS to tutorials, or an example code would be most helpful, thanks
PHP login script
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="check_login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Current c# code using UnityEngine; using System.Collections;
public class LoginMenu : MonoBehaviour {
string loginUrl = "";
string username ="";
string password ="";
string label ="";
void OnGUI(){
GUI.Window(0,new Rect(Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height /2 - 70), LoginWindow,"Login");
}
void LoginWindow(int windowID){
GUI.Label (new Rect (140,40,130,100), "____________username____________");
username = GUI.TextField(new Rect(25,60,375,30),username);
GUI.Label (new Rect (140,92,130,100), "____________password____________");
password = GUI.PasswordField (new Rect (25,115, 375, 30),password, "");
GUI.Button ( new Rect (25,160,375,50), "Login"); //turn to button with if statment
}
IEnumerable HnaldeLogin(string username, string password){
label = "Checking username and password...";
string loginUrl = this.loginUrl+"?username="+username+"&password="+password ;
WWW loginReader = new WWW(loinUrl);
yield return loginReader;
if(loginReader.error != null){
label="Error connecting to database server";
} else {
if(loginReader.text =="success"){
label = "Successfully logged in";
} else{
label = "invalid Username or password ";
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Send an integer array through WWWForm 1 Answer
WWWForm always returning Internal Server Error 1 Answer
WWW form isn't working in Build 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers