Generic selectors
Exact matches only
Search in title
Search in content
Search in project

远程PHP帐户连接器


远程PHP帐户连接器允许您拥有自己的Atavism服务器与之通信的PHP页面以验证帐户登录。这样就可以选择使用网站上的帐户来登录您的游戏。

帐户连接器系统期望从PHP代码接收帐户ID,因此它现在看起来更像:


<?php

// CONNECTIONS =========================================================
mysql_connect("localhost", "db_user", "db_pass") or die("Cant connect into database");
mysql_select_db("db_name")or die("Cant connect into database");

$user = $_POST["user"];
$password = $_POST["password"];

function checkUser($user, $password) {
  $user_name = htmlspecialchars($user,ENT_QUOTES);

  // get user_name's hashed password from wordpress database
  $queryx = "select * from account_table where username='$user'";
  $Resultx = mysql_query($queryx);

  while($row = mysql_fetch_array($Resultx)){
     $passnya = $row['password'];
  }
  
  if ($password === $passnya) {
    echo $row['id'];
  } else {
    echo "-1";
  }
}

checkUser($user, $password);

// Close mySQL Connection
mysql_close();
?>

通过在Web服务器上放置PHP文件,填写数据库连接详细信息并更改行:



$queryx = "select * from account_table where username='$user'";

为了匹配您的表名和列名,您可以在Atavism中验证登录帐户。

替换“echo $ row [‘id’];”中的“id”列名称,以匹配帐户表中的id列名称。

为了启用外部验证器,您应该在Atavism Server / bin目录中编辑auth_server.py文件,取消注释几行,并调整connector.setUrl中的值以指向您之前准备的PHP脚本。

connector = RemotePhpAccountConnector()
connector.setUrl("http://www.yourdomain.com/verifyAccount.php")
ms.setRemoteConnector(connector)

WordPress integration example

<?php
//CONNECTION INFORMATION - Change HOSTNAME, DBUSERNAME, DBUSERPASSWORD & DBNAME accordingly, advisable to make a new user with read only access to the WordPress DB for this.
$con = mysqli_connect("HOSTNAME", "DBUSERNAME", "DBUSERPASSWORD") or die("Cant connect into database");
$con->select_db("DBNAME")or die("Cant connect into database");

//VARIABLES - Do NOT change anything of this
$email = $_POST["user"];
$password = $_POST["password"];

function checkCustomer($con, $email, $password) {
  error_log("checking customer: " .$email);
  $SQL = "SELECT id, user_pass FROM USERTABLENAME WHERE user_email = '" .$email ."' or user_login = '" .$email ."'"; //Change USERTABLENAME to your Users Table Name from WordPress DB
  $result_id = $con->query($SQL) or die("Cannot invoke SQL command");
  $total = $result_id->num_rows;
  if ($total) 
  {
    require_once $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/class-phpass.php';
    $data = mysqli_fetch_array($result_id);
    error_log("Got account with password: " .$data['user_pass']);
    $wp_hasher = new PasswordHash(8, TRUE);
    $password_hashed = $data['user_pass'];
    $plain_password = $password;
    if ($wp_hasher->CheckPassword($plain_password, $password_hashed))
    {
    echo $data['id'];
    } 
    else 
    { 
    echo "-1";
    }
  }
}
checkCustomer($con, $email, $password);
?>