ERROR
When I run the game and want to login it will give me error:
could not locate page but when you go there, you see it work…
So here is C# code and Php code:
C#
using UnityEngine;
using System.Collections;
public class Login : MonoBehaviour {
string loginURL = "http://www.disease.g6.cz/game/login.php";
string userName = "";
string passWord = "";
string problem = "";
void OnGUI() {
GUI.Window (0, new Rect (Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height / 2 - 70),
LoginWindow, "Login");
}
void LoginWindow( int windowID ) {
GUI.Label (new Rect (140, 40, 130, 100), "--- Username ---");
userName = GUI.TextField (new Rect (25, 60, 375, 30), userName);
GUI.Label (new Rect (140, 92, 130, 100), "--- Password ---");
passWord = GUI.TextField (new Rect (25, 115, 375, 30), passWord);
if (GUI.Button (new Rect (20, 160, 175, 50), "Login"))
StartCoroutine (handleLogin (userName, passWord));
GUI.Label (new Rect (55, 222, 250, 100), problem);
}
IEnumerator handleLogin(string userNamez, string passWordz) {
problem = "Checking username and password...";
string login_URL = loginURL + "?username=" + userNamez + "&password=" + passWordz;
WWW loginReader = new WWW (login_URL);
yield return loginReader;
if (loginReader != null) {
problem = "Could not locate page";
} else {
if(loginReader.text == "right") {
problem = "Logged in";
} else {
problem = "Invalid username or invalid password";
}
}
}
}
Php
<?php
$username = $_REQUEST["username"];
$password = $_REQUEST["password"];
include "sql_connect.php";
md5($password);
$query="SELECT * FROM users WHERE websiteName='$username' AND password='$password'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
if($num > 0) {
echo "right";
}
else {
echo "wrong";
}
?>