Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // CONNECTIONS =========================================================
- $host = "localhost"; //put your host here
- $user = 'root'; //in general is root
- $password = ''; //use your password here
- $dbname = "times_table_game"; //your database
- mysql_connect($host, $user, $password) or die("Cant connect into database");
- mysql_select_db($dbname)or die("Cant connect into database");
- // =============================================================================
- $unityHash = $_POST["myform_hash"];
- $phpHash = "hashcode"; // same code in here as in your Unity game
- $nick = $_POST["myform_user"];
- $pass = md5($_POST["myform_pass"]); // md5 hashes the password
- $ans = md5($_POST["myform_ans"]);
- if(!$nick || !$pass || !$ans)
- {
- echo "Username or password or Security Question cant be empty.";
- }
- else
- {
- if ($unityHash != $phpHash)
- {
- echo "HASH code is diferent from your game";
- }
- else
- {
- $checkuser = mysql_query("SELECT username FROM users WHERE username = '$nick'");
- $username_exist = mysql_num_rows($checkuser);
- if($username_exist > 0)
- {
- echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
- unset($nick);
- exit();
- }
- if($username_exist = 0)
- {
- $query = "INSERT INTO users (username, password,security_question_ans)
- VALUES('$nick', '$pass','$ans')";
- mysql_query($query) or die(mysql_error());
- mysql_close();
- echo "You have successfully Registered";
- }
- }
- }
- private var username = ""; //this is the field where the player will put the name to login
- private var password = ""; //this is his password
- private var confpass = ""; //This is for confirrming their password
- private var security_question_id = ""; // This is for their security question
- private var security_question_ans = ""; // THis is for Security answers
- var formText = ""; //this field is where the messages sent by PHP script will be in
- var URL = "http://localhost/FYP_PHP/ConnectionR.php"; //change for your URL
- var hash = "hashcode"; //change your secret code, and remember to change into the PHP file too
- private var textrect = Rect (10, 150, 50, 50); //just make a GUI object rectangle
- function OnGUI() {
- GUI.Label( Rect (60, 10, 90, 20), "Register" );
- GUI.Label( Rect (10, 40, 80, 20), "Username:" ); //text with Username
- GUI.Label( Rect (10, 70, 80, 20), "Password:" ); //text with password
- GUI.Label( Rect (10, 100, 70, 70), "Confirm Password: "); //text with confirm password
- GUI.Label( Rect (10, 135, 70, 70), "Security Question:"); //security question answer
- GUI.Label( Rect (10, 180,80, 20), "Answers: ");
- GUI.Label ( Rect (75, 150, 250, 20), "What is your mother middle name?"); // Security Question
- username = GUI.TextField ( Rect (75, 40, 100, 20), username ); //here you will insert the new value to variable formNick
- password = GUI.TextField ( Rect (75, 70, 100, 20), password ); //same as above, but for password
- confpass = GUI.TextField ( Rect (75, 110, 100, 20), confpass); // to confirm password
- security_question_ans = GUI.TextField (Rect(75,180,150,20), security_question_ans);
- if ( GUI.Button ( Rect (10, 210, 80, 20) , "Register" ) ){ //just a button
- Register();
- }
- if ( GUI.Button (Rect (100,210, 80, 20), "Back") ){
- Back();
- }
- }
- function Register() {
- var connection = new WWWForm(); //here you create a new form connection
- connection.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
- connection.AddField( "myform_user", username );
- connection.AddField( "myform_pass", password );
- connection.AddField( "myform_cpass", confpass );
- //connection.AddField( "myform_Sques", Security );
- connection.AddField( "myform_ans", security_question_ans);
- var B = WWW(URL, connection); //here we create a var called 'w' and we sync with our URL and the form
- yield B; //we wait for the form to check the PHP file, so our game dont just hang
- if (B.error != null) {
- print(B.error); //if there is an error, tell us
- } else {
- print("Register Successful");
- formText = B.data; //here we return the data our PHP told us
- B.Dispose(); //clear our form in game
- Application.LoadLevel(2);
- }
- username = ""; //just clean our variables
- password = "";
- confpass = "";
- security_question_ans = "";
- }
- function Back() {
- Application.LoadLevel (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement