【发布时间】:2019-11-24 01:03:48
【问题描述】:
我正在通过 MySQL 使用后端作为 php 在统一上开发简单的登录注册页面。我已经做到了,但它只在同一个网络上工作。我的意思是我可以在同一个无线网络上使用它。我怎样才能让它在任何地方都可以使用?
我正在使用 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;
}
}
【问题讨论】:
-
你需要公网IP——这看起来不像是编程问题,而是有一些基本的网络问题
-
不仅SQL注入..@Dharman
if($hash != $loginhash)也容易出现timing related attacks... topicstarter应该阅读PHP的关于Safe password hashing的手册 -
你能解释一下吗?也许我在移动设备上误解了该代码中的某些内容。
-
不,我的意思是公共 IP ...
-
致电您的 ISP 并要求提供 - 说真的,这不是编程问题,如果您无法从您的 ISP 获得公共 IP,那么您可以尝试设置 DDNS 或在某些托管服务提供商的网站上发布您的服务器端
标签: c# php mysql database unity3d