- Home /
Connecting Unity game to wordpress..... ? (need help :D )
Hey gang, So i came up with this crazy idea to hook my game up to the wordpress database on my website, however I;',m getting an Error from my php when I'm trying o encode my password to mach that on my Mysql database.
Unsupported encoding: 'UTF-8,text/html' UnityEngine.WWW:get_text()
CS:
using UnityEngine;
using System;
using System.Collections;
using UnityEngine.UI;
public class LoginRegister : MonoBehaviour {
private string UserLoginURL = "http://www.mysite.club/loggin.php";
public string user = "";
public string pass = "";
// Current User -> may need to create its own class
private userData cUser = new userData();
//fetched from mysql
public string XPText;
public string GoldText;
public string LevelText;
public string UsernameText;
public string Recorcess;
//setactive when loggedin
public GameObject Logedin;
public GameObject Logedout;
//input by player
public Text InputUsername;
public Text InputPassword;
//------------------------------------------------------------------------------------
public void Loggin()
{
cUser.user = InputUsername.text;
cUser.pass = InputPassword.text;
//user = InputUsername.text;
//pass = InputPassword.text;
WWW wwwLogin = new WWW(UserLoginURL + "?user=" + cUser.user + "&pass=" + cUser.pass);
StartCoroutine(LoginRequest(wwwLogin));
//StartCoroutine(LoginUser(user, pass));
}
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// New Code
IEnumerator LoginRequest(WWW wwwLogin) {
yield return wwwLogin;
if (wwwLogin.error == null) {
cUser = JsonUtility.FromJson<userData>(wwwLogin.text);
// Assign all values
Debug.Log("Gold : "+cUser.Gold);
Debug.Log("Resources : "+cUser.Resources);
Debug.Log("Xp : "+cUser.Xp);
Debug.Log("Level : "+cUser.Level);
// Get all Items : from Item[1] -> Item[10]
for(int i=1; i<=10; i++) {
if (i < 10) {
Debug.Log("Item0"+i+" : "+cUser.Item[i]);
} else {
Debug.Log("Item10 : "+cUser.Item[10]);
}
}
XPText = cUser.Xp;
GoldText = cUser.Gold;
LevelText = cUser.Level;
Recorcess = cUser.Resources;
LevelText = cUser.Level;
} else {
Debug.Log ("Error: " + wwwLogin.error); // show me the echo
}
}
}
[System.Serializable]
public class userData {
public string user;
public string pass;
public bool success;
public string Gold;
public string Resources;
public string Xp;
public string Level;
// Ships, Items, Skills.....
//............................
public string[] Item;
}
PHP:
<?php
// CUSTROM LOGIN UNITY TO A WEBSITE THAT HAS A PAIDMEMBERSHIPS PRO ENABLED.
require_once ('wp-config.php'); //Informatioin for wordpress login.
require_once( '/wp-includes/class-phpass.php' ); // Wordpress Encrypton.
// Username and Password Posted by Unity, using WWW Call.
//...............................................................................................
$escapedName = mysql_real_escape_string($_POST['user']);
$escapedPW = mysql_real_escape_string($_POST['pass']);
//...............................................................................................
//WORDPRESS HASHING AND ENCRYPTING OF PASSWORD...................................................
$wp_hasher = new PasswordHash( 8, TRUE );
$password = $escapedPW;
$hashed_password = $wp_hasher->HashPassword( $password );
//...............................................................................................
// Create connection............................................................................
$mysqli = new mysqli($server, $serverUser, $serverPass, $database);
if ($mysqli->connect_error) {
die('Connect Error ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
//...............................................................................................
//...............................................................................................
$query = sprintf("SELECT login_user, login_pass FROM wppp_users WHERE user = '?' AND pass = '?'");
$sql->bindParam(1, $escapedName);
$sql->bindParam(2, $hashed_password);
$result = $mysqli->query($query) or die("Unable to select database");.
if ($mysqli->affected_rows > 0) {
$userData = $result->fetch_assoc();
$UserID['ID'] = "ID";
$mysqli->close(); // close connection to Wpp.
//...............................................................................................
// now open a connection to the Paid memebership pro to determan if we have a Active account.
// Create connection................................................
$mysqli = new mysqli($serverA, $serverUserA, $serverPassA, $databaseA);
if ($mysqli->connect_error) {
die('Connect Error ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
//...............................................................................................
//...............................................................................................
// we have users ID, check this against the Paidmemebrships pro table and see if they are active
$query = sprintf("SELECT active FROM wppp_pmpro_memberships_users WHERE user_id = '?'");
$sql->bindParam(1, $UserID);
$sql->execute();
$result = $mysqli->query($query) or die("Unable to select database");
$active = $result; // we have if they are active or not...
$mysqli->close(); // close connection to wppp_pmpro_memberships_users.
if ($mysqli->affected_rows > 0) {
$userData = $result->fetch_assoc();
$active ['Active'] = "Active";
if($active = 1){ // if the Account is Set Active....
//after conferirmation, login....
$query = sprintf("SELECT login_user, FROM wppp_users WHERE user = '?' AND pass = '?'");
$sql->bindParam(1, $escapedName);
$sql->bindParam(2, $hashed_password);
$sql->execute();
$result = $mysqli->query($query) or die("Unable to select database");
if ($mysqli->affected_rows > 0) {
$userData = $result->fetch_assoc();
$response['Success'] = "true";
// User Stats:
$response['SG'] = $userData['SG'];
$response['RS'] = $userData['RS'];
$response['Xp'] = $userData['Xp'];
$response['LVL'] = $userData['LVL'];
//Ships Unlocked:
$response['ShipSmall01'] = $userData['ShipSmall01'];
$response['ShipSmall02'] = $userData['ShipSmall02'];
$response['ShipSmall03'] = $userData['ShipSmall03'];
$response['ShipSmall04'] = $userData['ShipSmall04'];
$response['ShipSmall05'] = $userData['ShipSmall05'];
$response['ShipSmall06'] = $userData['ShipSmall06'];
//Ships Unlocked:
$response['ShipMedium01'] = $userData['ShipMedium01'];
$response['ShipMedium02'] = $userData['ShipMedium02'];
//Ships Unlocked:
$response['ShipCapital01'] = $userData['ShipHeavy01'];
$response['ShipCapital02'] = $userData['ShipHeavy02'];
$response['ShipCapital02'] = $userData['ShipHeavy03'];
$response['ShipCapital02'] = $userData['ShipHeavy04'];
//Ships Unlocked:
$response['ShipScience01'] = $userData['ShipScience01'];
$response['ShipScience02'] = $userData['ShipScience02'];
$response['ShipScience03'] = $userData['ShipScience03'];
$response['ShipScience04'] = $userData['ShipScience04'];
}else{
$response['Success'] = "false";
}
echo json_encode($response);
}
else
{
if($active = 0){
$NotActive = "Echo YOU NOT ACTIVE, ACTIVATE YOUR MEMBERSHIP....";
echo json_encode($NotActive);
}
}
$mysqli->close();
//...............................................................................................
?>
Comment
Your answer
Follow this Question
Related Questions
WWW in Unity returning empty string. 0 Answers
How to send securely scores to PHP backend 2 Answers
www request ienumerator function doesn't work 0 Answers
Remember currently logged in player 1 Answer
Method returning data from WWW 1 Answer