我正在使用MySQL作为php后端开发统一的简单登录注册页面。我已经做到了,但它只能在同一网络上工作。我的意思是我可以在同一Wi-Fi上使用它。如何在全球范围内使用它?
我正在使用Xampp启动Apache和MySQL。
这是我的php代码
<?php
$con = mysqli_connect('localhost', 'anyname','anypassword', 'unityaccess');
//check connection
if(mysqli_connect_errno())
{
echo "1: Connection failed!"; //connection failed
exit();
}
$username=$_POST["name"];
$password=$_POST["password"];
$namecheckquery = "SELECT username, salt, hash, score FROM players WHERE username='" . $username . "';";
$namecheck= mysqli_query($con, $namecheckquery) or die("2: Name Check Query failed!"); //namecheckquery failed
if(mysqli_num_rows($namecheck)!=1)
{
echo "5: Either no user with name or more than one";
exit();
}
//get login info from uery
$existinglogininfo = mysqli_fetch_assoc($namecheck);
$salt=$existinglogininfo["salt"];
$hash=$existinglogininfo["hash"];
$loginhash=crypt($password, $salt);
if($hash != $loginhash)
{
echo "6: Incorrect password";
exit();
}
echo "0\t" . $existinglogininfo["score"];
?>
这是我的C#代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Login : MonoBehaviour
{
public Button login;
public InputField nameinput;
public InputField passinput;
public void CallLogin()
{
StartCoroutine(LoginPlayer());
}
public IEnumerator LoginPlayer()
{
WWWForm form = new WWWForm();
form.AddField("name", nameinput.text);
form.AddField("password", passinput.text);
WWW www = new WWW("http://localhost/sqlconnect/login.php", form);
yield return www;
}
}
答案 0 :(得分:-1)
您可以通过键入ipconfig
从cmd查找本地IP
键入ipconfig后,您将看到一个包含IPv4地址的列表,该列表将类似于192.168.x.x,您可以从本地网络中的任何设备中键入此IP地址来访问它