Category: PHP

Magento – Stuck in Maintenance Mode

After upgrade magento to, my client’s website was stuck in magento maintenance mode. I wasn’t able to easily find a way to fix it by looking in the normal database tables, but did locate a file called “maintenance.flag” in the magento root.

So, to fix maintenance mode look for the maintenance flag and remove it and your shop will be back online!

PHP MS SQL Truncated VarChar(255)

I don’t often have fields much longer than 256 char, but a web application I am working on makes use of varchar 512. I’m not really able to change the field to text as the PHP Docs suggest. MS SQL doesn’t allow the equal operator, and grouping on text fields, and it’s also very slow compared to a varchar which can make advanced queries very difficult. “Due to a limitation in the underlying API used by PHP (MS DBLib C API), the length of VARCHAR fields is limited to 255”

Basically, it appears that PHP is using some old C API from Microsoft and to get around this need to convert from varchar to text. Text by default, allows about 8,000 characters but changing this fairly simple in the php.ini

mssql.textlimit = 65536
mssql.textsize = 65536

Of course, you can also set it dynamically using ini_set.

ini_set("mssql.textlimit", '65536' );
ini_set("mssql.textsize", '65536' );

Hope this helps.

Resolving Session Not Saving

Tonight, I’ve encountered a very strange situation where the session data was empty after each page reload. Have you ever had an issue with the session data not being set after a page refresh and the session has been for sure been started using session_start() ?

I modified the php.ini file located on the server for the line containing session.save_path to a temporary directory on the server.

session.save_path = /tmp

After making the change, sessions were now available and working again.

How do I upgrade magento?

Before you upgrade magento you should be sure to make a complete back up of your files and your database. (It also isn’t wise to test the upgrade on a production store!)

To upgrade the easiest way is to make use of downloader, using a user with permissions, sign in, and then use the following extension key:

For more information and alternative methods visit the wiki article.

Magento – Adding Feaured Products to Front Page

The owner of Nature Bumz wanted to be able to add featured products to the home page of their magento store each day without having to modify to edit the content.

Inchoo has created a great extension, called Featured Products, that features a great backend allowing the admins to choose featured products from a simple grid. (Catalog -> Featured Products.)For the front end, it’s very easy to add the required code to the content:
{{block type="featuredproducts/listing" template="inchoo/block_featured_products.phtml"}}

Don’t forget to refresh the cache after you install through downloader or you might get some errors. 😉

Magento – Setting Paypal to Redirect Back

Quick steps on how to redirect back to your magento store upon a successful purchase. Unfortunately, you can only redirect to one page.

      Sign into Paypal account
      Click directly on Profile -> Website Payment Preferences
      Change Auto Return to on.
      Fill Return URL to
      Save and then go test it!

After a successful paypal payment the customer will be redirected back to the magento order success page. Hope this helps!

WordPress – Auto Tweeting

A couple of visitors have asked me how I am automatically tweeting my post title to twitter: I’m of course using a plugin that required very little configuration and making sure that I always use Posts -> Add New because the quick post functionality doesn’t work. The plugin I’ve been using that has worked so far without a hitch is called Just Tweet That Shit.

I chose Just Tweet That Shit because it uses the oAuth API, doesn’t include features I don’t want to use, and it can properly shorten urls.Configuration took less than five minutes which was also extremely simple and to the point: the hardest point was actually getting a Twitter API Key.

Overall, I really only have two complaints with Just Tweet That Shit: I don’t like that it doesn’t auto tweet on scheduled posts, and that it doesn’t current auto tweet on quick posts. If you have found an auto tweeter that can auto tweet on scheduled posts and on quick posts I would love to hear.

Hope this helps!

BRCline Consulting – 1st Magento Site

BRCline Consulting has been busy working on its first ecommerce site to create Niagara Fall’s Natue Bumz Cloth Diaper Shop.

The owner, Crystal Cline, needed to accept paypal, credit cards, and be able to create her own blog along with adding inventory, and all of the traditional sort of business functions. I chose magento to take advantage of the large exploding community and realized I would really only need to create a theme along with doing some configuration to give Crystal exactly what she needed.

Check it out.
Nature Bumz - Cloth Diapers - Niagara Falls

Magento – How to Enable Logging

Magento is an excellent project that so far hasn’t been too difficult to program for. Initially learning how to use magento has been fairly tough: there are a lot of settings and fields that should be set before the site becomes visible to visitors and of course indexed. I won’t touch on magento seo right now, but I will say that so far my impression is that magento was designed with seo in mind.

By default, logging is turned off in magento. Logging for magento should be turned off by default because the logs can rapidly increase; when programming on magento I turn the logging on to try and catch those occasional bugs or errors that occur. I always shut the logging off after I have completed any programming tasks.

We should always make sure that we do not make the logs visible to the normal user either because of the potential for database names or credentials to be spewed out in the log.

Steps to turn on logging:

      Go to your admin area usually:
      Go To Configuration
      Scroll to the bottom of the screen, look on the left for Advanced and click Developer
      Expand Log Settings and change Enabled drop down list to Yes
      Click Save config.

Note that magento stores log files by default in: var/log/system.log and var/log/exception.log.

Hope this helps!

jQuery + PHP to parse XML

jQuery is very well suited for cross browser JavaScript development, but I bet you didn’t know jQuery is also fairly well suited to parsing XML. I often use jQuery to send XMLHttpRequests and then parse the XML returned by a PHP script on the server and then manipulate the return in some way. I won’t really cover exactly what to do with it because this is so dependent on the purpose of your data.

Parsing the XML isn’t overly difficult with jQuery and will allow you to truly use the power of AJAX and eliminate a lot of the complexity with JavaScript. Of course, getElementByTagName and getAttribute aren’t exactly 100% cross browser compatible, and jQuery is pretty much 100% of the time.

Things to Remember

  • PHP must set the content-type to be specified as text/xml or application/xml as seen in the following code example.
  • If you are using .ajax() you must ensure that the dataType is “xml” or you won’t be able to parse the data returned.

header ("Content-Type: text/xml");

<site ID="1" >
<Title>BRCline Consulting</Title>

<script type="text/javascript" >
type: "GET",
url: "yourURLHere.php",
dataType: "xml",
success: function(xml) {


Further Reading
jQuery often has a ton of plugins that can increase the flexibility and decrease the amount of time you spend on writing your own “utility” code. One such plugin available to reduce the amount of time spent on writing utility code for parsing XML/RSS feeds is jFeed.

MODx – Evolution – 1st Impressions

I haven’t been using MODx for very long, but I have worked with several other content management systems previously and experienced both the good and the bad with them. MODx appears to be a fairly simple MVC style content management system with a bit of a pluggable architecture. I haven’t written any plugins for MODx, but it appears that hooks are used just like WordPress does.

I have found MODx to be very easy for creating fully tableless XHTML compliant sites and creating very search engine friendly websites. Very easily, it is also possible to hide what cms is running the site by using the easily created pretty urls. (There’s just a couple of simple settings and a file renaming.)

I found the templating system to be extremely frustrating because the template is actually stored in the database instead of in the file system like done in most traditional CMS. I really find editing the templates, snippets, and larger chunks extremely frustrating to edit in the manager because of the lack of syntax highlighting, and issues with formatting.

Of course, the manager does offer the advantage of being able to edit content and site structure from pretty much anything that can access the internet and doesn’t mind some fairly heavy javascript use. MODx’s requirements for webhosting aren’t exactly hard to find either although there is a forum of reviews and suggestions.

Overall, MODx doesn’t appear to be too bad for smaller boutique websites which are a large chunk of my current business. I believe I would recommend it to fellow freelancers for smaller websites that don’t have much need for plugins or high amounts of customization.

PHP Object/Variable Life Time

Many junior PHP developers seem to feel that PHP objects and variables are retained between requests. In PHP4 and PHP5, no variables are retained outside of the contents of $_SESSION and other stores between requests.

Continue reading

Learning Drupal

For the last couple of weeks, I have began playing around with Drupal because I’m so sick of fighting proprietary CMS. The proprietary CMS suffers from the vendor updating only updating the CMS when convenient for them and this ends up holding the purchaser hostage. Overall, I know that drupal has enough of the functionality that I need in modules and the core to significantly improve the efficiency of my programming and possibly offer a large learning opportunity on software architecture.

Continue reading

PHP Update Finally Depreciates PHP MSSQL driver

The biggest advantage of the change is being able to better take advantage of Microsoft SQL Server features that probably made you choose to use SQL Server in the first place.Making the change wasn’t overly difficult because I took time and wrote a simple Database Access Layer.

Continue reading