Setting environment variables for your Magento store through .htaccess

Once in a while i get the question, Martijn how can we select a storeview without editting the index.php file, as Magento is prepared for this?!

Well, the Magento index.php file is indeed prepared for this. The full Magento index.php for releases 1.4.2.0 and later is as below.

<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category   Mage
* @package    Mage
* @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*/

if (version_compare(phpversion(), '5.2.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;"><div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"><h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer. <a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a> Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);

/**
* Compilation includes configuration file
*/
$compilerConfig = 'includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = 'app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run($mageRunCode, $mageRunType);

On lines 66 you will find a conditional test that would allow you to turn on the Magento Developer-mode. On lines 75 and 78 you will see how the $mageRunCode and $mageRunType is populated by server values.

All three values can be set from the .htaccess files or vhost configurations of your server with the code below.

### Setting environment variables for your Magento store.
SetEnvIf Remote_Addr "your.ip.address.here" MAGE_IS_DEVELOPER_MODE=TRUE
SetEnvIf Host "your.domain.here" MAGE_RUN_CODE=storeview_code

### Next line is important for multi language stores on the same domain.
### When running multiple languages on one domain, the storeview code is
### stored in the frontend cookie. Without this line, your store would
### default back to the storeview set above
SetEnvIfNoCase ^Cookie$ "frontend=(.+)" MAGE_RUN_CODE=

With the code at line 2, you can turn on the developer mode for only the specified ip address. The code at line 3 allows you to set a specific storeview-code to be used while executing the Magento web-app.

However, setting always a specific storeview-code is a bad idea. In multilingual stores you could make it default back to the default language all the time. Therefor i recommend not to set a storeview if a cookie is set with a frontend-id.

I hope this is useful for all the Magento Developers out there. If you like my articles, please spread the word using the Tweet button or the Facebook-‘Recommend’-button.

By the way, don’t forget that Magento redirects by default to your base url. So be aware that you need to set this storeview url for a second store in the General Web section of the System config

.

Let Spamassassin learn about not recognised spam

Below there is a chart of email processing on my server.

Exim stacked stats (graph)

Exim stacked stats for 19-11-2011@15:55

I process statistics every 5 minutes, So above image will tell you that i get about 4 real emails every 5 minutes. I have about 203 emails every 5 minutes that do not comply with email rules (invalid sender, SPF checks fail, etc) About 24 emails get rejected based on recipient rules (specific rules for one of my mailboxes).

And only 1 email every 5 minutes that would be accepted was recognised as spam. Considering the fact that i get multiple messages per day in my mailbox that should be considered as spam i decided that it is time to train spamassassin again.

Training SpamAssassin is quite easy aslong as you follow some rules and are willing to automate this task. As my server works with DirectAdmin I followed the Knowledge Base article on How to create a cronjob to use sa-learn to teach spamassassin – Maildir

Memorising the OSI-layers

Some people have problem with remembering the OSI-layers, for those who can not memorise them i have this small trick i learned once back in college.

Just keep in mind that all people seem to need data processing.
Where each word corresponds with one of the layers of the OSI model below.

OSI Layers

OSI Layers

So all corresponds with Application, people with Presentation etc.

I hope it will help you as it did for me!

Extending the library, books for #CCDA and #CCNP Voice (#Cisco)

While i was looking for some books for my Personal Education Program i found that CiscoPress and Pearson IT Certifications had each a useful eBook Deal of the Day.

With CiscoPress i bought the book Implementing Cisco Unified Communications Manager, Part 1 (CIPT1) Foundation Learning Guideicon for only $ 9.99. And at the Pearson IT Certification website i bought Designing for Cisco Internetwork Solutions (DESGN) Foundation Learning Guideicon.

The first book is for my CCDA track, the second for the CCNP Voice track that i pursue.

Dennis Ritchie Passes Away At Age 70 (Father Of C And UNIX)

Dennis Ritchie?! Who is Dennis Ritchie? Will be the first tought of many.

Dennis Ritchie is the inventor of the computer programming language C. In my eyes he has done even more work for the world than Steve Jobs did. (Sure he had a good eye for how things should look.)

Next to his job for creating the programming language C he was also known as one of the key-developers for UNIX. From those two positions he has had quite some influence on how todays Operating Systems look like and function.

Wired News: Dennis Ritchie: The Shoulders Steve Jobs Stood On
Los Angeles Times: Dennis Ritchie dies at 70; computer scientist helped develop Unix
New York Times: Dennis Ritchie, Trailblazer in Digital Era, Dies at 70

Solving OAuth problems on my blog

Since yesterday it seemed that there occured some errors. Most likely when you tried to login or post a comment. This was due to the OAuth library included with several plugins and all tried to declare the same classes and functions. For now this is solved by adding a class_exist check in the library.

I will lookup the OAuth project and check how we can incorporate these suggestions in to the library.

Old:

class OAuthConsumer {
	public $key;
	public $secret;

	function __construct($key, $secret) {
		$this->key = $key;
		$this->secret = $secret;
	}

	function __toString() {
		return "OAuthConsumer[key=$this->key,secret=$this->secret]";
	}
}

New:

if (!class_exists("OAuthConsumer", false)) {
	class OAuthConsumer {
		public $key;
		public $secret;

		function __construct($key, $secret) {
			$this->key = $key;
			$this->secret = $secret;
		}

		function __toString() {
			return "OAuthConsumer[key=$this->key,secret=$this->secret]";
		}
	}
}

Note lines 1 and 15.

Lack of competition a bigger threat than piracy, says Miramax CEO

Giving a Media Mastermind keynote session, Lang reiterated Miramax’s strategy of enabling customers to access content anytime and anywhere across multiple platforms, from physical discs, to streaming services, to ultimately buying content in a digital cloud. Lang claimed that ultimately Miramax will load over 300 of its library of 700 titles—including Pulp Fiction, Chicago and Shakespeare In Love—each month for OTT service users.

“We believe that cross-platform is key to growing the digital transactions business,” Lang told his audience in Cannes. “We believe that all [the] different platforms can be complementary and co-exist together.”

via MIPCOM 2011: Lack of competition a bigger threat than piracy, says Miramax CEO | MIPCOM 2011 | Rapid TV News.