Snappy Notes: Resolving secure connection crashes (HTTPS)

Posted by admin at March 28, 2017

I was working on a small project that was hosted on site with SSL installed and enforced. However I noticed that the Secure text and lock icon does not appear, instead I get the Info or Warning sign at the address bar.

After a few minutes of combing through the code (using a manual select, skip and test technique), I discovered a code segment that crashes the connection.


<form name="frm_name" id="frm_id" method="post" action="http://link/to/site">
    // ...
</form>

To resolve this, I replaced the text http:// with https://, and the secure connection was OK. So I went about resolving the link string to use the HTTP protocol of the server.


<?php
    
    $http_str = 'http';
    if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on'))
    {
        // secure connection on
        $http_str = 'https';
    }
    $http_str .= '://'
        
        // the server name
        . $_SERVER['SERVER_NAME']
        
        // the php file and location
        . '/'.$_SERVER['PHP_SELF']
        
        // the GET variables and values
        . $_SERVER['QUERY_STRING']
    ;
?>
<form name="frm_name" id="frm_id" method="post" action="<?php echo $http_str; ?>">
    // ...
</form>
   1 likes

Suggested Read