【问题标题】:Using application from anywhere从任何地方使用应用程序
【发布时间】: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注入..@Dharmanif($hash != $loginhash)也容易出现timing related attacks... topicstarter应该阅读PHP的关于Safe password hashing的手册
  • 你能解释一下吗?也许我在移动设备上误解了该代码中的某些内容。
  • 不,我的意思是公共 IP ...
  • 致电您的 ISP 并要求提供 - 说真的,这不是编程问题,如果您无法从您的 ISP 获得公共 IP,那么您可以尝试设置 DDNS 或在某些托管服务提供商的网站上发布您的服务器端

标签: c# php mysql database unity3d


【解决方案1】:

你可以在cmd中输入ipconfig找到你的本地IP 输入 ipconfig 后,您将看到一个列表,其中包括 IPv4 地址,类似于 192.168.x.x ,从本地网络中的任何设备您都可以通过输入此 IP 来访问它

【讨论】:

  • "我的意思是我可以在同一个 wi-fi 上使用它。"
  • @RaymondNijland 英语不好)
  • @AB' 你能用代码解释一下吗?因为我试过了,我用 c# 代码写了我的 ip 地址,但它也不起作用
  • 查找本地 IP 如何有助于如何使其在任何地方都可以在全球范围内使用? ?
猜你喜欢
  • 1970-01-01
  • 2015-02-23
  • 1970-01-01
  • 2021-08-06
  • 2018-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多