<?php
//Email and password
$Email = $_REQUEST("Email");
$Password = $_REQUEST("Password");
//php Only
$Hostname = "";
$DBName = "";
$User = "";
$PasswordP = "";
mysql_connect($Hostname,$User,$PasswordP) or die ("Can't connect to DB");
mysql_select_db($DBName) or die ("Can't connect to DB");
if(! $Email || !$PasswordP){
echo "Empty";
}else {
$SQL = "SELECT * FROM accounts WHERE Email = '" . $Email ."'" ;
$Result = @mysql_query($SQL) or die ("DB Error");
$Total = mysql_num_rows($Result);
if($Total == 0){
$insert = "INSERT INTO 'accounts' ('Email','Password') VALUES ('" . $Email . "', MDS('" . $Password . "'))";
$SQL1 = mysql_query($insert);
echo "Success";
}else{
echo"AlreadyUsed";
}
}//End Main Else
mysql_close();
?>
[C#]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class LogIn : MonoBehaviour
{
#region Variables
//Static Variable
public static string Email = “”;
public string Password = “”;
//Public Variable
public string CurrentMenu = “Login”;
//Private Variable
private string CreateAccountUrl = “http://127.0.0.1/CreateAccount.php”;
private string LogInUrl = “”;
private string ConfirmPass = “”;
private string ConfirmEmail = “”;
private string CEmail = “”;
- private string CPassword = “”;
//GUI Text Section
public float X;
public float Y;
public float Width;
public float Height;
#endregion
// Start is called before the first frame update
void Start()
{
}//End Start Method
//Main GUI Function
void OnGUI()
{
//If our current menu is = login,the display the login menu
//By calling our Login GUI function,Else,display the
//Create account GUI by calling its function
if (CurrentMenu == “Login”)
{
//Call login GUI
LoginGUI();
}else if (CurrentMenu == “CreateAccount”)
{
//Call create account GUI
CreateAccountGUI();
}
}//End OnGui
#region Custom methods
//This method will login the account
void LoginGUI()
{
//Create box to simulate window
GUI.Box(new Rect(260,120,400,350), “Log Masuk Akaun Anda”);
//Create account button and login button
//Open Create Account Window
if (GUI.Button(new Rect(415,400,100,25) , “Daftar Akaun”))
{
CurrentMenu = “CreateAccount”;
}//End Button
//Log User In
if (GUI.Button(new Rect(400,365,125,25), “Log Masuk Akaun”))
{
}//End Button
//Email
GUI.Label(new Rect(300, 214, 285, 23), "Email : ");
Email = GUI.TextField(new Rect(342,214,285,23) , Email);
//Password
GUI.Label(new Rect(276, 255, 285, 23), "Password : ");
Password = GUI.TextField(new Rect(342,255,285,23), Password);
}//End Login GUI
//This method will be the GUI for creating the account
void CreateAccountGUI()
{
//Create box to simulate window
GUI.Box(new Rect(260, 120, 400, 350), “Daftar Akaun Anda”);
//Email and password,plus confirmation
GUI.Label(new Rect(300, 214, 285, 23), "Email : ");
CEmail = GUI.TextField(new Rect(342, 214, 285, 23), CEmail);
GUI.Label(new Rect(276, 255, 285, 23), "Password : ");
CPassword = GUI.TextField(new Rect(342, 255, 285, 23), CPassword);
GUI.Label(new Rect(305, 292, 224, 23), "Confirm Email : ");
ConfirmEmail = GUI.TextField(new Rect(404, 291, 224, 23), ConfirmEmail);
GUI.Label(new Rect(290, 330, 285, 23), "Confirm Password : ");
ConfirmPass = GUI.TextField(new Rect(405, 330, 224, 23), ConfirmPass);
//Create random int field for bot protection
//Create Account button,and login button
//Open Create Acccount Window
if (GUI.Button(new Rect(415, 400, 100, 25), “Daftar Akaun”))
{
if (ConfirmPass == CPassword && ConfirmEmail == CEmail)
{
StartCoroutine(“CreateAccount”);
}
else
{
//StartCoroutine();
}
}//End create account button
//Log User In
if (GUI.Button(new Rect(400, 365, 125, 25), “Kembali”))
{
CurrentMenu = “Login”;
}//End Button
}//End Creating Account GUI
#endregion
#region CoRoutines
//Actually Create Account
[System.Obsolete]
IEnumerator CreateAccount()
{
//This is what sends messages to our php scripts.
WWWForm Form = new WWWForm();
//The fields are the variable we are sending.
Form.AddField(“Email”, CEmail);
Form.AddField(“Password”, CPassword);
WWW CreateAccountWWW = new WWW(CreateAccountUrl, Form);
//Wait for php to send something back to unity
yield return CreateAccountWWW;
if(CreateAccountWWW.error != null)
{
Debug.LogError(“Cannnot Connect to Account Creation”);
}
else
{
string CreateAccountReturn = CreateAccountWWW.text;
if(CreateAccountReturn == “Success”)
{
Debug.Log(“Success : Account Created”);
CurrentMenu = “Login”;
}
}//End else
}//End Create Account
#endregion
} //End Class[/code]