Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. -------Login Handing PHP Script (Currently not setting the username or password from the unity POST---------
  2.  
  3. <?php
  4. session_start(); //*****************ADDED THIS SESSION START METHOD MARCH 18. HAVE NOT TESTED IT YET but there's a chance it'll work*******************
  5. echo " <!--Begin some html code that will house any stuff that we want displayed by the php script-->
  6. <html>
  7. <h2>Test Page for Unity</h2>"; //Attempting to debug the unity login system with this page. Doesn't seem to work. This heading works but below html doesn't show up.
  8.  
  9. include_once 'dbh-inc.php'; //Allow access to the users database for login information
  10.  
  11. $username = mysqli_real_escape_string($conn, $_POST["usernamePost"]);
  12. $password = mysqli_real_escape_string($conn, $_POST["passwordPost"]);
  13.  
  14. //$username = $_POST["usernamePost"]; //When a POST is created with the name usernamePost which we do in the Unity assets in the Signin script, set this variable
  15. //$password = $_POST["passwordPost"]; //Same idea. These are not getting set though. I wonder if we include a 'session_start()' method would they set.
  16.  
  17. echo $username;
  18. echo $password;
  19.  
  20. if (empty($username) || empty($password)) { //Exact same login information as when logging into the regular site
  21. //Behavior for empty unity input here.
  22. echo "<h3>Username or password empty</h3>
  23. </html>";
  24. exit();
  25. } else {
  26. $sql = "SELECT * FROM users WHERE Username='$username' OR Email='$username'";
  27. $result = mysqli_query($conn, $sql);
  28. $resultCheck = mysqli_num_rows($result);
  29. if ($resultCheck < 1) {
  30. //Behavior for incorrect username or password here.
  31. exit();
  32. } else {
  33. if ($row = mysqli_fetch_assoc($result)) {
  34. $hashedPwdCheck = password_verify($password, $row['Password']);
  35. if ($hashedPwdCheck == false) {
  36. //Behavior for incorrect username or password here.
  37. exit();
  38. } elseif ($hashedPwdCheck == true) {
  39. $_SESSION['u_id'] = $row['ID'];
  40. $userID = $row['ID']; //Only thing I changed between login. Set a variable just for userID so that it can be used in the dataInserter.php script.
  41. $_SESSION['u_first'] = $row['First'];
  42. $_SESSION['u_last'] = $row['Last'];
  43. $_SESSION['u_email'] = $row['Email'];
  44. $_SESSION['u_username'] = $row['Username'];
  45. $_SESSION['u_status'] = $row['Status'];
  46. echo "
  47. <h2>Sessions are all set<h2> <!--Attempting to create a debugging pring statement. Can't get it to read into this area though becasue posts aren't setting-->
  48. </html>";
  49. exit();
  50. }
  51. }
  52. }
  53. }
  54.  
  55.  
  56. ---------C# Script used in unity to try to create a POST method to send to the above PHP Script----------
  57.  
  58. using System.Collections;
  59. using System.Collections.Generic;
  60. using UnityEngine;
  61. using UnityEngine.UI;
  62.  
  63. public class SignIn : MonoBehaviour {
  64.  
  65. public string phpURL = "http://165.227.185.246/Logins/MickeyNewAttempt/includes/unityLogin.php"; //URL location where the PHP script is saved
  66.  
  67. public InputField usernameField;
  68. public InputField passwordField;
  69.  
  70. public static string username;
  71. string password;
  72. private string submitted;
  73.  
  74. public Text errorLbl;
  75.  
  76. public void Login()
  77. {
  78. username = usernameField.text;
  79. password = passwordField.text;
  80. submitted = "Check";
  81.  
  82. WWWForm form = new WWWForm();
  83.  
  84. form.AddField("unitySubmit", submitted);
  85. form.AddField("usernamePost", username);
  86. form.AddField("passwordPost", password);
  87.  
  88. WWW www = new WWW(phpURL, form);
  89.  
  90. Debug.Log("Username: " + username);
  91. Debug.Log("Password: " + password);
  92. }
  93. }
  94.  
  95.  
  96. ---------PHP Script to handle patient data that gets sent via POST method from Unity (Currently working and actually inserts in SQL----
  97.  
  98. <?php
  99. if (isset($_SESSION['u_id'])) {
  100. include_once '/var/www/html/Logins/MickeyNewAttempt/includes/hdbh-inc.php';
  101. include_once '/var/www/html/Logins/MickeyNewAttempt/includes/unityLogin.php';
  102.  
  103. $pinch = $_POST["pinchPost"]; //Pinch variable gets set when the POST is created in the dataInsert c sharp script in the game's assets
  104. $grab = $_POST["grabPost"]; //Grab variable set in the same way. Why aren't the username and password setting the same way??
  105. $height = $_POST["heightPost"];
  106.  
  107. //echo $name;
  108. //echo $type;
  109. //echo $cost;
  110.  
  111. //Checking the Connection
  112.  
  113. if (mysqli_connect_error()) {
  114. die("Connection Failed.". mysqli_connect_error());
  115. } else if ($conn){
  116. echo("Connection was successful<br>");
  117. }
  118.  
  119. //$sql = "INSERT INTO handData (PinchStrength, GrabStrength, Height) VALUES('".$pinch."','".$grab."','".$height."')";
  120. $sqlPinch = "INSERT INTO PinchStrength (userID, RightData) VALUES ('".$userID."','".$pinch."')"; //Insert the userID and the pinch value into the pinch data table
  121. $sqlGrab = "INSERT INTO GrabStrength (userID, RightData) VALUES ('".$userID."','".$grab."')"; //The userID is the relation between these databases. It makes it so a physician could see all 3 parameters
  122. $sqlHeight = "INSERT INTO Height (userID, RightData) VALUES ('".$userID."','".$height."')"; //in a search should they perform one
  123.  
  124. $pinchResult = mysqli_query($conn, $sqlPinch); //Result for each query. Don't need to print the results or anything since we're just inserting data
  125. $grabResult = mysqli_query($conn, $sqlGrab);
  126. $heightResult = mysqli_query($conn, $sqlHeight);
  127.  
  128. //$result = mysqli_query($conn,$sql);
  129. //$assoc = mysqli_fetch_assoc($result, true);
  130.  
  131. //if(!$result) echo "There is an error";
  132. //else echo "Insert Complete";
  133.  
  134. //Mickey Dummy Update-Insert Structure
  135. /*
  136. if (User doesn't exist) {
  137. INSERT INTO handData () VALUES();
  138. } else if (User does exist) {
  139. UPDATE handData SET PinchStrength = '', GrabStrength = '', Height = '' WHERE Username = $username;
  140. }
  141. */
  142. }
  143. ?>
  144.  
  145.  
  146. -------UNITY C# Script that's sending the POST method to the PHP script above (Currently working and creates POST method fine------
  147.  
  148. using UnityEngine;
  149. using Leap;
  150. using Leap.Unity;
  151. using UnityEngine.Networking;
  152. using System.Collections;
  153.  
  154. public class dataInserter : MonoBehaviour
  155. {
  156. public string phpURL = "http://165.227.185.246/TeamMembers/Lakshya/dataInsert.php"; //URL location where the PHP script is saved
  157.  
  158. private float pinch; // = HandDataCollector.maxRightPinch;
  159. private float grab; // = HandDataCollector.maxRightGrab;
  160. private float height; // = HandDataCollector.maxRightHeight;
  161.  
  162. void Start()
  163. {
  164.  
  165. }
  166.  
  167. void Update()
  168. {
  169. pinch = HandDataCollector.maxRightPinch;
  170. grab = HandDataCollector.maxRightGrab;
  171. height = HandDataCollector.maxRightHeight;
  172.  
  173. //if (Input.GetKeyDown(KeyCode.Space))
  174. //{
  175. //createRecord();
  176.  
  177. //}
  178. }
  179.  
  180. public void createRecord()
  181. {
  182. WWWForm form = new WWWForm();
  183.  
  184. form.AddField("pinchPost", pinch.ToString("F2"));
  185. form.AddField("grabPost", grab.ToString("F2"));
  186. form.AddField("heightPost", height.ToString("F2"));
  187.  
  188. WWW www = new WWW(phpURL, form);
  189.  
  190. Debug.Log("1. " + pinch + " " + grab + " " + height);
  191. }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement