- Home /
Question by
davidflynn2 · Nov 27, 2012 at 09:02 PM ·
login
Login script Problem
I have found the following login scrit but for some reason no matter what you type in it lets you login.
private var formNick = ""; //this is the field where the player will put the name to login
private var formPassword = ""; //this is his password
var formText = ""; //this field is where the messages sent by PHP script will be in
var URL = "http://mywebsite/check_scores.php"; //change for your URL
var hash = "yourpassword"; //change your secret code, and remember to change into the PHP file too
private var textrect = Rect (10, 300, 200, 75); //just make a GUI object rectangle
var username = "test";
var userpassword="test";
var areaHeight = 240;
var areaWidth = 200;
var areaHeightReg=240;
var areaWidthReg=200;
var background: Texture2D;
var gui : GUISkin;
function OnGUI() {
GUI.TextArea( textrect, formText );
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height), background);
GUI.skin = gui;
var ScreenX = ((Screen.width / 2) - (areaWidth / 2));
var ScreenY = ((Screen.height / 2) - (areaHeight/ 2));
GUILayout.BeginArea (new Rect (ScreenX, ScreenY, areaWidth, areaHeight),"Login","Window");
GUILayout.Space(15);
GUILayout.Label("Username: ");
GUILayout.Space(40);
GUILayout.Label("Password: ");
formNick = GUI.TextField ( Rect (38, 110, 225, 20), formNick ); //here you will insert the new value to variable formNick
formPassword = GUI.PasswordField ( Rect (38, 200, 225, 20), formPassword, "*"[0] ); //same as above, but for password
GUILayout.Space(4);
if ( GUI.Button ( Rect (80, 235, 150, 30) , "Login" ) ){ //just a button
Login();
}
GUILayout.EndArea();
}
function Login() {
var form = new WWWForm(); //here you create a new form connection
form.AddField( "myform_hash", hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file
form.AddField( "myform_nick", formNick );
form.AddField( "myform_pass", formPassword );
var w = WWW(URL, form); //here we create a var called 'w' and we sync with our URL and the form
yield w; //we wait for the form to check the PHP file, so our game dont just hang
if (w.error != null) {
print(w.error); //if there is an error, tell us
} else {
print("Test ok");
formText = w.data; //here we return the data our PHP told us
w.Dispose(); //clear our form in game
// Application.LoadLevel("fgdf");
}
formNick = ""; //just clean our variables
formPassword = "";
}
Comment
Best Answer
Answer by Collapse · Nov 28, 2012 at 12:32 AM
It is probably a mistake in your php file since you can always login and the php file in your script stops you from logging in when there is an error... (that it lets you log in means that there are no w.error's)