- Home /
[Closed] www.data help
okay so basically I have a Database server up and online storing people's usernames and passwords. then I have another server PHP that is sending and retrieving that information form the database to unity's application to verify the username and password is correct. I found this script online but the problem is when I click login and it does if(w.data == "Correct") it doesn't do what it is suppose to do or for any of the other if(w.data) statment's pls help I need this to work. PS. I removed the URL Text so you don't know where my server is and how to access it.
Code:
private var formNick = ""; //this is the field where the player will put the name to login
private var formPassword = ""; //this is his password
private var RformNick = ""; //this is the field where the player will put the name to login
private var RformPassword = "";
private var Remail = "";
private var TRformPassword = "";
public var guiSkin : GUISkin;
public var pdata = "";
var LoadOut : System.Boolean;
var LoadOutText = "";
var formText = ""; //this field is where the messages sent by PHP script will be in
var URL = ""; //change for your URL
// var hash = "812ca28212be5705ad52010bccc9ea3f"; //change your secret code, and remember to change into the PHP file too
var DoLogin : System.Boolean;
private var textrect = Rect (10, 150, 500, 500); //just make a GUI object rectangle
function Start (){
PlayerPrefs.DeleteAll();
}
function Load(){
Debug.Log("Load");
//if(w.text == "Correct"){
// Debug.Log("Work");
// }
}
function OnGUI() {
if(LoadOut){
GUI.skin = guiSkin;
GUI.Box (new Rect(Screen.width/2 - 150, Screen.height/2 - 30, 300, 60), LoadOutText);
}else{
GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 400),Login, "");
}
}
function Login (id : int){
if(DoLogin){
GUILayout.BeginVertical();
GUI.skin = guiSkin;
GUILayout.Box (/* new Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 400),*/"Login");
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label( "Username:" ); //text with your nick
formNick = GUILayout.TextField ( formNick , 15, GUILayout.Width(345), GUILayout.Height(35));
GUILayout.EndHorizontal();
GUILayout.Space(10);
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label( "Password:" );
formPassword = GUILayout.TextField (formPassword , 15, GUILayout.Width(345), GUILayout.Height(35) ); //same as above, but for password
GUILayout.EndHorizontal();
GUILayout.Space(10);
GUILayout.BeginHorizontal();
GUILayout.Space(5);
if ( GUILayout.Button ("Login" ) ){ //just a button
Action("Login");
}
if ( GUILayout.Button ( "Sign Up" ) ){ //just a button
DoLogin = false;
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}else{
GUI.skin = guiSkin;
GUILayout.Box ("Register");
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("Username:" );
RformNick = GUILayout.TextField (RformNick, 15,GUILayout.Width(300) ,GUILayout.Height(35) );
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("Password:" );
RformPassword = GUILayout.TextField (RformPassword , 15,GUILayout.Width(300) , GUILayout.Height(35) );
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("Password:" );
TRformPassword = GUILayout.TextField (TRformPassword , 15,GUILayout.Width(300) , GUILayout.Height(35) );
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("Email:" );
Remail = GUILayout.TextField (Remail, 75,GUILayout.Width(300) , GUILayout.Height(35) );
GUILayout.EndHorizontal();
if ( GUILayout.Button ("Finish" ) ){ //just a button
Action("Register");
}
if ( GUILayout.Button ("Back" ) ){ //just a button
DoLogin = true;
}
}
//GUI.TextArea( textrect, formText );
}
function Action(Act : String) {
var form = new WWWForm(); //here you create a new form connection
//add your hash code to the field myform_hash, check that this variable name is the same as in PHP file
var tempURL : String;
if(Act =="Login"){
tempURL = URL + "?User="+formNick+"&Pass="+formPassword+"&Act="+Act;
}else{
tempURL = URL + "?User="+RformNick+"&Pass="+RformPassword+"&Act="+Act+"&Email="+Remail;
}
var w = WWW(tempURL); //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 {
pdata = w.text;
if(w.data == " Correct"){
print("Logging In...");
LoadOut = true;
LoadOutText = "Signing In...";
yield WaitForSeconds(5);
PlayerPrefs.SetString("RegUser",formNick);
Load();
Application.LoadLevel(1);
}
if(w.data == " Wrong"){
LoadOut = true;
LoadOutText = "Wrong Password";
yield WaitForSeconds(3);
LoadOut = false;
}
if(w.data == " No User"){
LoadOut = true;
LoadOutText = "No Registered User Found";
yield WaitForSeconds(3);
LoadOut = false;
}
if(w.data == " ILLEGAL REQUEST"){
LoadOut = true;
LoadOutText = "Server Error";
yield WaitForSeconds(3);
LoadOut = false;
}
if(w.data == " Registered"){
print("Account Created. Logging In.");
LoadOut = true;
LoadOutText = "Creating Account & Logging In...";
PlayerPrefs.SetString("RegUser",RformNick);
yield WaitForSeconds(5);
Application.LoadLevel(1);
}
if(w.data == " ERROR"){
LoadOut = true;
LoadOutText = "Login Error. Restarting.";
yield WaitForSeconds(3);
Application.LoadLevel(0);
}
print(w.data);
LoadOut = true;
LoadOutText = w.data;
Load();
//formText = w.data; //here we return the data our PHP told us
w.Dispose(); //clear our form in game
}
formNick = ""; //just clean our variables
formPassword = "";
}
function Update(){
}
sorry, but " it doesn't do what it is suppose to do" isn't exactly a great problem description.. what exactly happens?
What I mean it is like unity skips over the if statement checking whether it is correct or not when the Database return's correct or false.
if you need any more information contact me at mastertrolrs@gmail.com or here and I would be glad to give you more information.
I found this script online
There's your problem, you shouldn't use scripts that you just find online. $$anonymous$$ost people write stuff tailored to their own projects and very rarely will they work "out of the box" in yours.
There are too many issues with this script to even begin. I'm not trying to sound mean or anything, but it would be best to just delete this file and code your own.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
C# Capture Keypress 3 Answers
Expansion/Database help 2 Answers
php, sql security 3 Answers
In-Game GUI buttons don't work 2 Answers