WordPress.org

Ready to get started?Download WordPress

Forums

Request: modify is_ssl() function to check for HTTP_X_FORWARDED_PROTO (6 posts)

  1. Bombdogs
    Member
    Posted 2 years ago #

    Hi,

    the is_ssl() function in wp-includes/functions.php should be modified to include a check for HTTP_X_FORWARDED_PROTO. This is required if you are operating behind a load balancer that terminates the SSL connection and then forwards to the machines behind it on port 80 (common set-up on the Amazon cloud).

    Suggest the following...

    function is_ssl() {
    	if ( isset($_SERVER['HTTPS']) ) {
    		if ( 'on' == strtolower($_SERVER['HTTPS']) )
    			return true;
    		if ( '1' == $_SERVER['HTTPS'] )
    			return true;
    	} elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
    		return true;
    	}
    	if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' ) {
    		return true;
    	}
    	return false;
    }

    Currently I need to hand edit this function (and more importantly remember to!) every time we update WordPress.

    Thanks.

  2. Marventus
    Member
    Posted 2 years ago #

    Hi there,

    It would be more useful to post this in Trac or under the Ideas section. I'll try to get a moderator's attention see what can be done.

    Cheers!

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 2 years ago #

    The requests forum is a fine place for this.

  4. josy1024@gmail.com
    Member
    Posted 2 years ago #

    this worked for me in case of a varnish and https configuration:

    if (req.http.X-Forwarded-Proto == "https" ) {
    		set req.http.X-Forwarded-Port = "443";
    	} else {
    		set req.http.X-Forwarded-Port = "80";
    	}

    wp-includes/functions.php

    function is_ssl() {
            if ( isset($_SERVER['HTTPS']) ) {
                    if ( 'on' == strtolower($_SERVER['HTTPS']) )
                            return true;
                    if ( '1' == $_SERVER['HTTPS'] )
                            return true;
            } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
                    return true;
            } elseif ( isset($_SERVER['HTTP_X_FORWARDED_PORT']) && ( '443' == $_SERVER['HTTP_X_FORWARDED_PORT'] ) ) {
                    return true;
            }
            return false;
    }
  5. snackd
    Member
    Posted 2 years ago #

    any word on this being absorbed by wp core?

  6. Mvied
    Member
    Posted 1 year ago #

    I've been wanting to submit this for a while. We'll see what happens.

    http://core.trac.wordpress.org/ticket/20567

Topic Closed

This topic has been closed to new replies.

About this Topic