HTTP_HOST not found #228

Closed
juanjolainez opened this Issue Jun 5, 2014 · 7 comments

Projects

None yet

3 participants

@juanjolainez

Hello, after a composer update, I am getting this error:

{"error":{"type":"ErrorException","message":"Undefined index: HTTP_HOST","file":"/home/clipster/development/vendor/hybridauth/hybridauth/hybridauth/Hybrid/Auth.php","line":388}}

Do you know what is for?

Thank you! :D

@StorytellerCZ StorytellerCZ added this to the 2.2.x milestone Jun 6, 2014
@StorytellerCZ StorytellerCZ added the 2.2.x label Jun 6, 2014
@StorytellerCZ StorytellerCZ removed this from the 2.2.x milestone Jul 11, 2014
@StorytellerCZ
Contributor

I think it references this:
$url = $protocol . $_SERVER['HTTP_HOST'];
But why that would create an error I don't know.

@StorytellerCZ StorytellerCZ added 2.3.x and removed 2.2.x 2.3.x labels Jul 16, 2014
@mbardelmeijer

@juanjolainez can you check with a print_r($_SERVER) of the HTTP_* variables are set on your configuration?

@juanjolainez

Nope, HTTP_HOST is not set when I make a print_r($SERVER)....

@mbardelmeijer

@juanjolainez on what kind of environment are you running? i.e. PHP version, Windows / Linux, used browser to test etc

@juanjolainez

It only fails when I do composer update.

I've test it in both Linux and MAC with PHP 5.5.3. No browser. If I comment from that line to the end of the function it works just fine, but it's pretty annoying to do so every time.

It works when I use it by doing API calls or browser calls

@juanjolainez

It happens when I do some job in a queue (actually I am syncing friends using social networks) and I am getting the very same error.

Do you have any thoughts about this?

Thank you

@juanjolainez

Actually I figured out the issue.

The point is as I am doing a cli call instead of a browser call, some variables are not set (it's the very same case as when you do it with PHPUnit).

I commented this lines in the file Auth.php (line 388):

$url = $protocol . $_SERVER['HTTP_HOST'];

    // use port if non default
    if( isset( $_SERVER['SERVER_PORT'] ) && strpos( $url, ':'.$_SERVER['SERVER_PORT'] ) === FALSE ) {
        $url .= ($protocol === 'http://' && $_SERVER['SERVER_PORT'] != 80 && !isset( $_SERVER['HTTP_X_FORWARDED_PROTO']))
            || ($protocol === 'https://' && $_SERVER['SERVER_PORT'] != 443 && !isset( $_SERVER['HTTP_X_FORWARDED_PROTO']))
            ? ':' . $_SERVER['SERVER_PORT'] 
            : '';
    }

    if( $request_uri ){
        $url .= $_SERVER['REQUEST_URI'];
    }
    else{
        $url .= $_SERVER['PHP_SELF'];
    }

and everything seems to work fine.

A fix would be adding an isset httphost just like this:

if (array_key_exists('HTTP_HOST', $_SERVER) {
     ....
} 

or

if (php_sapi_name() == cli) {
      ....
}

What do you think? Thank you!

@borNfreee borNfreee added a commit to borNfreee/hybridauth that referenced this issue Dec 24, 2014
@borNfreee borNfreee Fixes #228 - HTTP_HOST not found
Do not try to get `current url` when it's called from CLI. Fixes #228
19f4ab9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment