Question about PHP

Connect with other users about what to run on your webhosting (and how to run it) here.
Post Reply
ForrestMarkX
New to forums
New to forums
Posts: 14
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Sat May 03, 2014 9:01 pm

Question about PHP

Post by ForrestMarkX »

I recently made a basic PHP script that accesses the SteamAPI to get a players steam avatar URL but I've run into a issue.

I can't seem to find any info on how to send the string back as a reply to the FETCH request other than just forcing it to redirect to the new URL (I need it to not redirect as the game I'm trying to make this for does not support 200 response codes and nor does it support HTTPS which is why I have to use this PHP script)

This is what I have as the script, it's pretty basic https://pastebin.com/r3e23cSh
User avatar
Spray
Former staff
Former staff
Posts: 630
Joined: Wed Dec 28, 2011 10:41 pm
Location: Oregon

Re: Question about PHP

Post by Spray »

Can you elaborate on this a bit further? What is it that you're wanting the script to return? Are you just wanting the script to print out the URL for the avatar?
ForrestMarkX
New to forums
New to forums
Posts: 14
Joined: Sat May 03, 2014 9:01 pm

Re: Question about PHP

Post by ForrestMarkX »

I want it to reply to the FETCH request with the URL basically, instead of replying with a 200 redirect response code
User avatar
Spray
Former staff
Former staff
Posts: 630
Joined: Wed Dec 28, 2011 10:41 pm
Location: Oregon

Re: Question about PHP

Post by Spray »

If I understand correctly, then you should just need to be returning a string as output from your script. Something like the following would work:

Code: Select all

<?php
    $Avatar  = 'http://bmtwebsite.site.nfoservers.com/UserAvatar/noavatar.jpg';
   
    if (isset($_GET['steamid']))
    {
        $SteamAPI = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $_GET['apikey'] . '&steamids=' . $_GET['steamid'];
       
        $SteamAPI_Returned = file_get_contents($SteamAPI);
       
        $steamAPI = json_decode($SteamAPI_Returned, true);
       
        if (isset($steamAPI['response']['players'][0]['avatar']))
        {
            $Avatar = $steamAPI['response']['players'][0]['avatar'];
        }
       
        echo $Avatar;
    }
?>
ForrestMarkX
New to forums
New to forums
Posts: 14
Joined: Sat May 03, 2014 9:01 pm

Re: Question about PHP

Post by ForrestMarkX »

That worked, I saw echo but from what I read on it, it just seemed to be like print is where it just outputs a string to the server console. Guess I should of just tried it first to make sure
Post Reply