Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zak666 · Feb 01, 2017 at 11:03 AM · unity 5wwwphp

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges