Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------Login Handing PHP Script (Currently not setting the username or password from the unity POST---------
- <?php
- session_start(); //*****************ADDED THIS SESSION START METHOD MARCH 18. HAVE NOT TESTED IT YET but there's a chance it'll work*******************
- echo " <!--Begin some html code that will house any stuff that we want displayed by the php script-->
- <html>
- <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.
- include_once 'dbh-inc.php'; //Allow access to the users database for login information
- $username = mysqli_real_escape_string($conn, $_POST["usernamePost"]);
- $password = mysqli_real_escape_string($conn, $_POST["passwordPost"]);
- //$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
- //$password = $_POST["passwordPost"]; //Same idea. These are not getting set though. I wonder if we include a 'session_start()' method would they set.
- echo $username;
- echo $password;
- if (empty($username) || empty($password)) { //Exact same login information as when logging into the regular site
- //Behavior for empty unity input here.
- echo "<h3>Username or password empty</h3>
- </html>";
- exit();
- } else {
- $sql = "SELECT * FROM users WHERE Username='$username' OR Email='$username'";
- $result = mysqli_query($conn, $sql);
- $resultCheck = mysqli_num_rows($result);
- if ($resultCheck < 1) {
- //Behavior for incorrect username or password here.
- exit();
- } else {
- if ($row = mysqli_fetch_assoc($result)) {
- $hashedPwdCheck = password_verify($password, $row['Password']);
- if ($hashedPwdCheck == false) {
- //Behavior for incorrect username or password here.
- exit();
- } elseif ($hashedPwdCheck == true) {
- $_SESSION['u_id'] = $row['ID'];
- $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.
- $_SESSION['u_first'] = $row['First'];
- $_SESSION['u_last'] = $row['Last'];
- $_SESSION['u_email'] = $row['Email'];
- $_SESSION['u_username'] = $row['Username'];
- $_SESSION['u_status'] = $row['Status'];
- echo "
- <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-->
- </html>";
- exit();
- }
- }
- }
- }
- ---------C# Script used in unity to try to create a POST method to send to the above PHP Script----------
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class SignIn : MonoBehaviour {
- public string phpURL = "http://165.227.185.246/Logins/MickeyNewAttempt/includes/unityLogin.php"; //URL location where the PHP script is saved
- public InputField usernameField;
- public InputField passwordField;
- public static string username;
- string password;
- private string submitted;
- public Text errorLbl;
- public void Login()
- {
- username = usernameField.text;
- password = passwordField.text;
- submitted = "Check";
- WWWForm form = new WWWForm();
- form.AddField("unitySubmit", submitted);
- form.AddField("usernamePost", username);
- form.AddField("passwordPost", password);
- WWW www = new WWW(phpURL, form);
- Debug.Log("Username: " + username);
- Debug.Log("Password: " + password);
- }
- }
- ---------PHP Script to handle patient data that gets sent via POST method from Unity (Currently working and actually inserts in SQL----
- <?php
- if (isset($_SESSION['u_id'])) {
- include_once '/var/www/html/Logins/MickeyNewAttempt/includes/hdbh-inc.php';
- include_once '/var/www/html/Logins/MickeyNewAttempt/includes/unityLogin.php';
- $pinch = $_POST["pinchPost"]; //Pinch variable gets set when the POST is created in the dataInsert c sharp script in the game's assets
- $grab = $_POST["grabPost"]; //Grab variable set in the same way. Why aren't the username and password setting the same way??
- $height = $_POST["heightPost"];
- //echo $name;
- //echo $type;
- //echo $cost;
- //Checking the Connection
- if (mysqli_connect_error()) {
- die("Connection Failed.". mysqli_connect_error());
- } else if ($conn){
- echo("Connection was successful<br>");
- }
- //$sql = "INSERT INTO handData (PinchStrength, GrabStrength, Height) VALUES('".$pinch."','".$grab."','".$height."')";
- $sqlPinch = "INSERT INTO PinchStrength (userID, RightData) VALUES ('".$userID."','".$pinch."')"; //Insert the userID and the pinch value into the pinch data table
- $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
- $sqlHeight = "INSERT INTO Height (userID, RightData) VALUES ('".$userID."','".$height."')"; //in a search should they perform one
- $pinchResult = mysqli_query($conn, $sqlPinch); //Result for each query. Don't need to print the results or anything since we're just inserting data
- $grabResult = mysqli_query($conn, $sqlGrab);
- $heightResult = mysqli_query($conn, $sqlHeight);
- //$result = mysqli_query($conn,$sql);
- //$assoc = mysqli_fetch_assoc($result, true);
- //if(!$result) echo "There is an error";
- //else echo "Insert Complete";
- //Mickey Dummy Update-Insert Structure
- /*
- if (User doesn't exist) {
- INSERT INTO handData () VALUES();
- } else if (User does exist) {
- UPDATE handData SET PinchStrength = '', GrabStrength = '', Height = '' WHERE Username = $username;
- }
- */
- }
- ?>
- -------UNITY C# Script that's sending the POST method to the PHP script above (Currently working and creates POST method fine------
- using UnityEngine;
- using Leap;
- using Leap.Unity;
- using UnityEngine.Networking;
- using System.Collections;
- public class dataInserter : MonoBehaviour
- {
- public string phpURL = "http://165.227.185.246/TeamMembers/Lakshya/dataInsert.php"; //URL location where the PHP script is saved
- private float pinch; // = HandDataCollector.maxRightPinch;
- private float grab; // = HandDataCollector.maxRightGrab;
- private float height; // = HandDataCollector.maxRightHeight;
- void Start()
- {
- }
- void Update()
- {
- pinch = HandDataCollector.maxRightPinch;
- grab = HandDataCollector.maxRightGrab;
- height = HandDataCollector.maxRightHeight;
- //if (Input.GetKeyDown(KeyCode.Space))
- //{
- //createRecord();
- //}
- }
- public void createRecord()
- {
- WWWForm form = new WWWForm();
- form.AddField("pinchPost", pinch.ToString("F2"));
- form.AddField("grabPost", grab.ToString("F2"));
- form.AddField("heightPost", height.ToString("F2"));
- WWW www = new WWW(phpURL, form);
- Debug.Log("1. " + pinch + " " + grab + " " + height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement