Getting steamid and username

I want to make a JavaScript function that gets the streamid and then the username of the player so I can make it being shown in the loadingscreen. Can you help me with that?

The player’s SteamID can be received by adding %s to a $_GET variable on your Loading URL

Use PHP to query the Steam API with their SteamID to get the user’s name.

Okay, but then I have to add it with an echo, right?
I just want to be able to use it like this: <span id=“player_name”>


  <table>
            <tbody>
              <tr>
                <td><img src="assets/img/playername.png" class="table-icon" alt=""></td>
                <td><b>Name:</b></td>
                <td><span id="player_name"></span></td>
              </tr>
              <tr>
                <td><img src="assets/img/playerid.png" class="table-icon" alt=""></td>
                <td><b>SteamID:</b></td>
                <td><span id="player_steamid"></span></td>
              </tr>
              <tr>
                <td><img src="assets/img/music.png" class="table-icon" alt=""></td>
                <td><b>Song:</b></td>
                <td><span id="player_song"></span></td>
              </tr>
            </tbody>
          </table>

Is this possible?

Yes, use json_decode with:

api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=<yourapikey>&steamids=76561197960435530

get your apikey here

You’d need to combine JS & PHP if you want it to look nice aka having it as SPAN class, its way simpler just making a span and then echoing the info, without giving it a class(You still can give it a class, so it got CSS) if you didn’t understand what I mean, some loadingscreens(I think also TCBs one) use span classes for JS innerHTML function.

Billy, That’s quite a good way I think, but I have no idea how to do that.

whitestar, my loadingscreen is based on TCBs, but I don’t know hat you mean with JS innerHTML function. I really want to just be able to use HTML instead of PHP, because I want to keep the css.

You have to use PHP to convert the SteamID to the owners name. and if you dont know what innerHTML is then you really should learn a bit of HTML and JS

and PHP is just an “addition” (but ran on the server; that’s a hugely simple explanation) to HTML. you can obviously keep your stylesheets.

This section isn’t for spoonfeeding code, learn PHP for example before asking how to do things

Okay, I have read about php and I have decided to use that too, for getting the information from the link Billy gave me. I got this php file:


<php>

  $api_key = "XXX";
  $steamid = "";
  $api_url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$api_key&steamids=$steamid";


  $json = json_decode(file_get_contents($api_url), true);


</php>

and I use this for displaying it:


<?=$json["response"]["players"][0]["personaname"];?>

But the problem I am having is that I don’t know how I can get a steam id from the user, because that should be in here


$steamid = "";

$_GET[“steamid”]; right?

it doesnt has to be steamid, it can be w/e is set in the url, the default only is “?steamid=%s”

Also, OP, change " to ', works better on PHP

Okay, thank you.
I have now found my problem.
I have 3 seperate files:
Loading.html <- main page
GetInfo.js <- gets map and other info
GetPlayerInfo.php <- Should get player steam id
But my main page has to be an php. Is there for this a different solution, so I can just use html?

Double quotes parse variables inside strings, while single quotes don’t. If he changes them on $api_url, it is going to ignore the steamid and literally search for ‘$api_key&steamids=$steamid’, dollar signs and all.

You can just change .html to .php and it’ll work exactly the same. PHP only modifies stuff inside <?php ?> tags, if it’s not inside them, it gets passed straight away.

I changed it to php, but the whole layout is gone. and the other info from javascript is gone too.

Just to be sure… You didn’t edit anything *inside *the file, and you only renamed .html for .php, right?
Can you pass the URL you’re trying to use and the code for Loading.php?
You should also check your hosting’s error_logs, just in case.

Okay here is my Loading.php:


<!DOCTYPE html>
<html lang="en">
<head>
  <title>PerfectRP loading screen</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="shortcut icon" href="assets/img/favicons/favicon.ico">
  <link rel="stylesheet" href="assets/css/main.css" />

  <?php

    $api_key = "43F0EED5DA650D4B8386A831D852BCF3";
    $steamid = $_GET["steamid"];
    $api_url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$api_key&steamids=$steamid";


    $json = json_decode(file_get_contents($api_url), true);


  ?>

</head>
<body>

  <div class="page-home">

    <div class="container">
      <div class="box-top overflow">
        <span class="banner-text overflow">Perfect RP</span>
      </div>
      <div class="box-left">
        <div class="box-title">Server Info</div>
        <div class="table-holder overflow">
          <table>
            <tbody>
              <tr>
                <td><img src="assets/img/name.png" class="table-icon" alt=""></td>
                <td><b>Name:</b></td>
                <td><span id="server_name">Perfect RP</span></td>
              </tr>
              <tr>
                <td><img src="assets/img/map.png" class="table-icon" alt=""></td>
                <td><b>Map:</b></td>
                <td><span id="server_map"></span></td>
              </tr>
              <tr>
                <td><img src="assets/img/slots.png" class="table-icon" alt=""></td>
                <td><b>Slots:</b></td>
                <td><span id="server_slots"></span></td>
              </tr>
              <tr>
                <td><img src="assets/img/mode.png" class="table-icon" alt=""></td>
                <td><b>Mode:</b></td>
                <td><span id="server_mode"></span></td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="box-title box-title-top">Player Info</div>
        <div class="table-holder overflow">
          <table>
            <tbody>
              <tr>
                <td><img src="assets/img/playername.png" class="table-icon" alt=""></td>
                <td><b>Name:</b></td>
                <td><?=$json["response"]["players"][0]["personaname"];?></td>
              </tr>
              <tr>
                <td><img src="assets/img/playerid.png" class="table-icon" alt=""></td>
                <td><b>SteamID:</b></td>
                <td><?=$json["response"]["players"][0]["steamid"];?></td>
              </tr>
              <tr>
                <td><img src="assets/img/music.png" class="table-icon" alt=""></td>
                <td><b>Song:</b></td>
                <td><span id="player_song"></span></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="box-right">
        <div class="box-title">Rules</div>
        <div class="table-holder overflow">
          <table>
            <tbody>
              <tr class="table-rules">
                <td><b>01.</b></td>
                <td><span id="rule_01">Respect staff and other players!</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>02.</b></td>
                <td><span id="rule_02">Don't kill players without a reason (RDM)</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>03.</b></td>
                <td><span id="rule_03">Don't kill players with cars (CDM)</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>04.</b></td>
                <td><span id="rule_04">Don't abuse your job in any way or form!</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>05.</b></td>
                <td><span id="rule_05">Don't break new life rule (NLR)</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>06.</b></td>
                <td><span id="rule_06">Don't mic spam or spam in chat.</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>07.</b></td>
                <td><span id="rule_07">Don't propkill, proppush, propsurf.</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>08.</b></td>
                <td><span id="rule_08">Don't spawnkill!</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>09.</b></td>
                <td><span id="rule_09">Don't troll, shit talk or anything like that.</span></td>
              </tr>
              <tr class="table-rules">
                <td><b>10.</b></td>
                <td><span id="rule_10">NLR Time - 5 Min.</span></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="box-bottom">
      </div>
    </div>

  </div>

  <script src="assets/js/jquery-2.1.4.min.js"></script>
  <script src="assets/js/functions.js" type="text/javascript"></script>
  <script src="assets/js/getInfo.js" type="text/javascript"></script>
  <iframe src='//www.youtube.com/embed/FjNdYp2gXRY?rel=0&controls=0&showinfo=0&autoplay=1&loop=1' frameborder='0' style='height:1px;width:1px;overflow:hidden;'></iframe>
</body>
</html>

and: http://theperfectrp.esy.es/loading.php/?steamid=%s

It works fine. You’re entering the URL with a slash on the end of .php.

http://theperfectrp.esy.es/loading.php?steamid=76561198040894045

I love the fact he actually ripped TCBs loadingscreen, and just removed the copyright box(which is easy to do, did it once too to try and see how loadingscreens work)

Billy: Thank you very much! It’s suddenly working.
Whitestar: I am doing this also the learn and after that I am going to create my own layout, thanks for the help though.