Archive
This post is archived and may contain outdated information. It has been set to 'noindex' and should stop showing up in search results.
How to Put Magento CE Store in Maintenance Mode Based on IP
May 19, 2014ProgrammingComments (0)
Magento Community Edition does not have a convenient maintenance mode and the "maintenance.flag" file method is too heavy-handed. You may want to put the store into maintenance mode but still give yourself access. Here is a quick and dirty way to do it using PHP.

In the root directory of your Magento store, open the index.php file. You'll be adding this code above the Magento code (but after the starting PHP tag). This will block access to anything not from your IP address that isn't accessing a file directly.

/**
* MAINTENANCE MODE
*/
$maintenanceMode = true;
if ($maintenanceMode) {
if (!isset($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] != '12.34.56.78') {
echo 'Store is undergoing maintenance.';
exit;
}
}

Be sure to change the sample IP address to yours. You can find your public IP address here.


CloudFlare


What if your store is behind CloudFlare? The REMOTE_ADDR will reflect CloudFlare's IP regardless of the user. Thankfully, CloudFlare inserts an http request parameter that contains the real client's IP. Just replace REMOTE_ADDR with HTTP_CF_CONNECTING_IP in the examples above.

You may also want to block access if the HTTP_CF_CONNECTING_IP property is missing, as this could indicate someone trying to access your site directly by going around CloudFlare.


ShipStation


If you use ShipStation and want it to continue to have access, be sure to allow users that have the HTTP_USER_AGENT "ShipStation".
Comments (0)
Add a Comment
No comments yet