Comment to 'UNA installer still forgot to detect http or https'
  • Maybe in your or other server support $_SERVER['HTTPS'], but my server not support that.

    So, when we install Dolphin or UNA, we will see the wrong URL. please see install01 and install02.

    I writing this program to display the environment variables supported by my server:

    < ? php
    echo '<PRE>';
    print_r($_SERVER);
    echo '</PRE><br />';

    please see install03 for Server A and install04 for Server B.

    You can see that there is no $_SERVER['HTTPS'] in the server variable.

    therefore I use $_SERVER['HTTP_X_FORWARDED_PROTO'] to rewrite this proto()

        protected function proto()
        {
            if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']))
                return $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://';
            elseif ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) || getenv('UNA_HTTPS'))
                return 'https://';
            else
                return 'http://';
            //return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) || getenv('UNA_HTTPS') ? 'https://' : 'http://';
        }

    OR

        protected function proto()
        {
            if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']))
                return $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://';
            else
                return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) || getenv('UNA_HTTPS') ? 'https://' : 'http://';
        }
    
    

    Please see install5 for the execution result of the installation.

    This is the dolphin installer's index.php:

    $confFirst['site_url']  = array(
        'name'    => "Site URL",
        'ex'      => "http://www.mydomain.com/path/",
        'desc'    => "Your site URL (slash at the end is required)",
        'def'     => "http://",
        'def_exp' => function () {
                $str = $_SERVER['HTTP_X_FORWARDED_PROTO'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
                return preg_replace("/install\/(index\.php$)/", "", $str);
        },
        'check'   => function ($arg0) { return strlen($arg0) >= 10 ? true : false; }
    );

    P.S. When I re-edited the article iin Dolphin  (of blog) and UNA, some words in PHP and HTML disappeared and could not be used! for example:

    ' < PRE > ' ;

    < ? php

    But there is no such problem in the Dolphin Forum!

    💓0 😆0 😲0 😥0 😠0 0
    • Thank you for the explanation and sample code:

      https://github.com/unaio/una/issues/2062

      💓0 😆0 😲0 😥0 😠0 0

    UNA - Network Infrastructure for Communities

    Close