· 9 years ago · Mar 31, 2017, 05:44 AM
1<?php
2
3 $servername = "localhost";
4 $username = "mix";
5 $password = "hellogai";
6 $dbname ="mix";
7 $tablename ="sidescroller";
8
9 $name = $_POST['name'];
10
11 $recivedHash = $_POST['hash'];
12
13 // create conention to database
14 $db = new mysqli ($servername, $username , $password, $dbname);
15
16 //check connection
17
18 if($db->connect_error){
19
20 die("Connection Lost: " . $db->connect_error);
21 }
22
23
24 $sql = "SELECT Name, Time, Hp FROM " . $tablename . "WHERE Name = ". $name ;
25
26 //Query the database
27 $result = $db->query($sql);
28
29
30
31//show if there is a result
32if($result->num_rows > 0)
33{
34 //output data of each row
35 $numbRow =0;
36
37 while($row = $result->fetch_assoc())
38 {
39 echo $row['time'] . "-" . $row['hp'];
40
41 }
42
43
44}
45
46 $db->close();
47
48 ?>
49
50private string secretKey = "Maxil"; //password
51 string UsernamesURL = "http://localhost/Highscore/Unity/usernames.php";
52 string NameInfoURL = "http://localhost/Highscore/Unity/nameinfo.php";
53
54 string Allnames;
55 public List<string> IndividualUsers;
56 string[] vectorUsers;
57 string oldname;
58 public Dropdown dropdownlist;
59 public Text CurrentName;
60 public Text NameInfoText;
61 public static string PostingName;
62 // Use this for initialization
63 void Start () {
64 StartCoroutine(GetNames());
65 oldname = " ";
66 PostingName = " ";
67
68 }
69
70 // Update is called once per frame
71 void Update()
72 {
73 if (UserCreation.looper ==1)
74 {
75 StartCoroutine(GetNames());
76 UserCreation.looper = 0;
77 }
78
79 if (oldname != PostingName)
80 {
81 StartCoroutine(Postname(PostingName)); //Postingname
82 oldname = PostingName;
83 StartCoroutine(GetNameInfo());
84 }
85
86
87
88
89 }
90 public void Dropdown_index(int index)
91 {
92 CurrentName.text = IndividualUsers[index];
93 PostingName = CurrentName.text;
94 }
95
96 IEnumerator Postname(string name)
97 {
98 string hash = Md5sum(name+ secretKey);
99 //create form with the info connected to webpage POST
100 WWWForm form = new WWWForm();
101 form.AddField("name", name);
102 form.AddField("hash", hash);
103 //connect and send the form, to POST on webpage
104 WWW www = new WWW(NameInfoURL, form);
105 yield return www; //wait intill connection complete;
106 if (www.error != null)
107 {
108 Debug.Log("Error: " + www.error);
109 }
110 else
111 {
112 NameInfoText.text = www.text;
113 }
114 }
115 IEnumerator GetNameInfo()
116 {
117 WWW nameinfo_get = new WWW(NameInfoURL);
118 yield return nameinfo_get;
119 if (nameinfo_get.error != null)
120 {
121 Debug.Log("There was an error getting the score: " + nameinfo_get.error);
122 }
123 else
124 {
125
126 NameInfoText.text = nameinfo_get.text;
127 }
128 }
129
130
131 IEnumerator GetNames()
132 { //split string
133 WWW names_get = new WWW(UsernamesURL);
134 yield return names_get;
135
136 if (names_get.error != null)
137 {
138 Debug.Log("There was an error getting the score: " + names_get.error);
139 }
140 else
141 {
142 Allnames = names_get.text;
143 vectorUsers = Allnames.Split(',');
144 IndividualUsers = new List<string>(vectorUsers);
145 dropdownlist.ClearOptions();
146 dropdownlist.AddOptions(IndividualUsers);
147
148
149
150 }
151
152 }
153 public string Md5sum(string strToEncrypt)
154 {
155 System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
156 byte[] bytes = ue.GetBytes(strToEncrypt);
157
158 //encrypt
159 System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
160 byte[] hashBytes = md5.ComputeHash(bytes);
161 string hashString = "";
162 //convert to encrypted string
163 for (int i = 0; i < hashBytes.Length; i++)
164 {
165 hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
166 }
167 return hashString.PadLeft(32, '0');
168 }
169
170}