Have you ever needed to develop some functionality on your store but not wanted to put your store into maintenance mode? Did you know that you can enable segments of code that are not visible to anyone else but yourself? Today, we will talk about how you can easily accomplish this without disrupting your customer’s experience.

Enabling PHP error reporting for your IP address

Those of you reading this who have some knowledge of PHP will know all about PHP’s error reporting. This can be vital sometimes, providing crucial errors that show where the code is breaking and where the developer needs to start debugging. However, you do not want to display all of these errors to the rest of the world, this can be a huge security problem, putting your store and customer’s sensitive information at risk. So enabling these errors for just yourself can be really useful. Let’s take a look at how we can go about doing this;

Firstly, go to config/defines.inc.php.

In this file you should see a section of code around line 28 that will look like the following:


if (!defined('_PS_MODE_DEV_')) {
define('_PS_MODE_DEV_', false);
}

As you can see, error reporting has been set to ‘false’. We need to change this to ‘true’, but we are also going to add some code of our own:


if (!defined('_PS_MODE_DEV_')) {
 if ($_SERVER['REMOTE_ADDR'] === "32.432.112.543"){
 define('_PS_MODE_DEV_', true);
 } else {
 define('_PS_MODE_DEV_', false);
 }
}

 

We have added some simple logic that detects the client’s IP address and determines whether or not it matches the provided condition, if so; PHP’s error reporting will be enabled. The IP address given in the conditional statement will need to be changed accordingly to your IP address. If you do not know how to find your IP address, simply search Google; ‘what is my IP address’. 

Enabling Sections of code for your IP address utilizing Smarty

This same logical approach can be also be used for sections of code but is altered slightly as we will be working in .tpl files – utilizing the Smarty templating language. As you can see from the code snippet below, this will achieve the same desired effect of only allowing the code to be run when the IP address entered is visiting the site;


{if $smarty.server.REMOTE_ADDR == “32.432.112.543”}
// your code here...
{/if}

It is important to keep in mind that if you are not using a static IP address, your IP address can change which will cause this code to no longer work and will require you to change it to your new address. This code snippet needs to be used carefully, as some parts of your store may require code that is surrounded by this Smarty logic and will cause an error, disrupting your customer’s experience.

A short, simple, yet powerful nugget of information to help you develop your store further without the disruption of your user’s experience.

  • SBA 2016 Winner
  • chamber