문제

I am trying to setup a website that converts a Steam user ID into an auth ID. It will ask for the visitor to input their regular Steam ID and then hit a button to convert it to auth ID. Steam provides us with the function for ID conversion from one type to the other.

Steam function for converting IDs:

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

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

Below is my attempt at setting up a basic HTML page that gets user input and then uses the function to convert that input to something else.

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

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

Also, this is what the default Steam user ID looks like:

STEAM_0:1:36716545

Thank you for all the help!

도움이 되었습니까?

해결책

If you can make it into two seperate files, then do so.

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)
?>

if you don't have an option of making two seperate files, you can add the php code to 'foo.html' file and make the form to submit to the same file. However if you do this, check if the file is getting requested the first time, or it is requested because the form is submitted, BEFORE you call convert_steamid_to_accountid() function. You can do this by:

if ($_SERVER['REQUEST_METHOD']=='POST'){
  // your php code here that should be executed when the form is submitted.
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top