0

我正在尝试设置一个将 Steam 用户 ID 转换为身份验证 ID 的网站。它会要求访问者输入他们的常规 Steam ID,然后点击按钮将其转换为身份验证 ID。Steam 为我们提供了从一种类型到另一种类型的 ID 转换功能。

用于转换 ID 的 Steam 功能:

function convert_steamid_to_accountid($steamid) 
     { 
        $toks = explode(":", $steamid); 
        $odd = (int)$toks[1];   
        $halfAID = (int)$toks[2]; 

        $authid = ($halfAID*2) + $odd;
        echo $authid;
      }

下面是我尝试设置一个基本的 HTML 页面,该页面获取用户输入,然后使用该函数将该输入转换为其他内容。

 <INPUT TYPE = "Text" VALUE ="ENTER STEAM:ID" NAME = "idform">

<?PHP
$_POST['idform'];
$steamid = $_POST['idform'];
?>

此外,这是默认 Steam 用户 ID 的样子:

STEAM_0:1:36716545

谢谢大家的帮助!

4

1 回答 1

1

如果你可以把它分成两个单独的文件,那么就这样做。

foo.html

<form method="POST" action="foo.php">
  <input type="text" value="ENTER STEAM:ID" name="idform" />
  <input type="submit" />
</form>

foo.php

<?php
  function convert_steamid_to_accountid($steamid) 
  { 
    $toks = explode(":", $steamid); 
    $odd = (int)$toks[1];   
    $halfAID = (int)$toks[2]; 

    $authid = ($halfAID*2) + $odd;
    echo $authid;
  }

  $id = $_POST['idform'];
  convert_steamid_to_accountid($id)
?>

如果您没有制作两个单独文件的选项,您可以将 php 代码添加到“foo.html”文件并让表单提交到同一个文件。但是,如果您这样做,请在调用 convert_steamid_to_accountid() 函数之前检查文件是否是第一次被请求,或者是因为提交了表单而被请求。您可以通过以下方式做到这一点:

if ($_SERVER['REQUEST_METHOD']=='POST'){
  // your php code here that should be executed when the form is submitted.
}
于 2013-02-27T08:21:35.500 回答