Post by damoks » Thu Mar 27, 2008 3:46 pm

Hey community.

I have found a way to set up the HTTPS usage properly. Now here's the complete step by step solution. Sorry if its a repost, but i didnt found it anywhere.

Note that both of step 1 to 3 is neccessary to set up the SSL usage properly.

Step 1.

Theres two of the config.php files. One in the root folder, another in the /admin folder.
Open up both then set up the HTTPS_SERVER constant variable. (dont forget the httpS)

define('HTTPS_SERVER', 'https://www.my.server/');
define('HTTPS_IMAGE', ''https://www.my.server/image/');

in admin/config.php:

define('HTTPS_SERVER', 'https://www.my.server/admin');
define('HTTPS_IMAGE', ''https://www.my.server/image/');

Replace the www.my.server/ to your actual server url.
update: Dont forget to set the HTTPS_IMAGE, because it produces the url for the images. The admin and cart's config.php must point to the same url, because they sharing this folder.

Step 2.

open up index.php in the / root folder.
find the comment: // Base URL

the following is checks that the request is came thru https or not. Thats right.
if (@$_SERVER['HTTPS'] != 'on')

Ok. I've created a config setting here, that holds the https status.

Code: Select all

// Base URL

if (@$_SERVER['HTTPS'] != 'on') {
  $config->set('OPENCART_HTTPBASE',HTTP_SERVER);
  $template->set('base', HTTP_SERVER);
} else {
  $config->set('OPENCART_HTTPBASE',HTTPS_SERVER);
  $template->set('base', HTTPS_SERVER);
}
For the first look it may looks suspicous, but this config setting is necessary because of the later fix. (see down below)

Step 3

open up library/environment/url.php

function href($controller, $action = NULL, $query = array()) {

this function sets the http:// url. This is buggy, that because it forgot to check that the actual page is came thru ssl or not, so it generates non ssl urls, while you are on an ssl page. The result is, that you'll go to non ssl pages if you click on any of the generated urls, imediately. (Yayy...)

So here's the fix:

Code: Select all

  	function href($controller, $action = NULL, $query = array()) {
  	  	if ($this->config->get('OPENCART_HTTPBASE') == HTTPS_SERVER) {
          	  	return $this->ssl($controller,$action,$query);
  	  	} else {
          	  	return $this->create(HTTP_SERVER, $controller, $action, $query);
  	  	}
  	}
Do you see? We have to use the previously set OPENCART_HTTPBASE (in index.php) that holds the actual status. Theres no way to use the @$_SERVER['HTTP'] php constant here, because the page is generated thru SSL, so it sets up a https:// url for the logout button also. So we are always stay in ssl mode (after logout also). But if you just use the new config variable from index.php, we can do some tricks to generate non-ssl urls also. (explanation below)

Logout button Fix
Well.. Im still thinking on better ways. But heres a fix, that will helps you to manage the non-ssl usage on the logout form.

in /catalog/extension/module/header.php:

$view->set('logout', $url->href('account_logout'));

If you modified the href function of url.php (above) theres you get a https:// url for the account_logout button. That is because you are actually logged in while it generates the button, so it will place the https:// url for it. At this point, you can 'FORCE' the non-ssl url generating by placing an ugly variable setting. Like this:

Code: Select all

            //forszoljuk a non ssl link elkeszitest
            $temp = $config->get('OPENCART_HTTPBASE'); // backup the status
            $config->set('OPENCART_HTTPBASE',HTTP_SERVER); // forcing the non ssl usage here
            
            $view->set('logout', $url->href('account_logout'));
      			
            // visszaallitjuk az allapotot
            $config->set('OPENCART_HTTPBASE',$temp); // restore here
Well. This way is sucks (i know) but it successfully forces the url generating to use non-ssl.

If you have better solutions any of the above sniplets, please place/discuss here.

Thanks.
Last edited by damoks on Thu Mar 27, 2008 8:07 pm, edited 1 time in total.

Newbie

Posts

Joined
Fri Mar 14, 2008 12:00 am

Post by lev » Wed Apr 30, 2008 10:49 pm

Thank you very much! i had just configured ssl on apache2 and the admin section lost its layout. as soon as i stepped though your guide, all problems were solved  :)

lev
New member

Posts

Joined
Wed Apr 30, 2008 10:47 pm
Who is online

Users browsing this forum: No registered users and 4 guests