SmItH197 / SteamAuthentication

A simple PHP Authentication that enables steam users to log into their steam account to access content!
MIT License
446 stars 147 forks source link

steamauth.php need exit() after header #223

Open corke opened 6 years ago

corke commented 6 years ago

Hello guys !

I m using your component, it's was working well since today where I would like show my work and use the login steam, but this one doesnt want working like always, it's just redirect me on the site without doing the header to steam, after adding an exit(); after the header() that reworks fine, but I would like to understand why...

if (isset($_GET['login'])){
    require 'openid.php';
    try {
        require 'SteamConfig.php';
        $openid = new LightOpenID($steamauth['domainname']);

        if(!$openid->mode) {
            $openid->identity = 'https://steamcommunity.com/openid';
            echo "lol";
            echo $openid->identity;
            echo $openid->authUrl();
            header('Location: ' . $openid->authUrl());
            exit();
        } elseif ($openid->mode == 'cancel') {
            echo 'User has canceled authentication!';
        }

thanks

BlackCetha commented 6 years ago

Are you overwriting the header somewhere later in your script?

corke commented 6 years ago

Yes later in the code, I have an other header I used for recheck data.

  1. Login Steamauth =>Header : go on steam
  2. Back on mysite => Recheck => Header : refresh page

Something like this

BlackCetha commented 6 years ago

In PHP, you set your HTTP header values by using the header() function. HTTP headers need to be sent before the payload, in your case probably HTML. PHP will accumulate the values you set for different headers and once you send content it will bundle them up and send them to the client first. After that, it is no longer possible to modify them. Additionally, only the last value set for a header is kept.