<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Design &#38; Development Talk &#187; PHP</title>
	<atom:link href="http://www.web-design-talk.co.uk/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-design-talk.co.uk</link>
	<description>Web Design &#38; Development Blog</description>
	<lastBuildDate>Thu, 29 Dec 2011 15:34:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Magento as an ECommerce Platform &#8211; A Case Study</title>
		<link>http://www.web-design-talk.co.uk/440/magento-ecommerce-case-study/</link>
		<comments>http://www.web-design-talk.co.uk/440/magento-ecommerce-case-study/#comments</comments>
		<pubDate>Sun, 06 Nov 2011 17:23:36 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ui design]]></category>
		<category><![CDATA[web companies]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=440</guid>
		<description><![CDATA[To date this year, I have inherited several Magento stores to perform web updates on. I thought I&#8217;d write a small post on my experience and thoughts in using the system and how that system translates to real world, non technical clients. As a bit of background, I&#8217;m by no means a fully fledged Magento [...]]]></description>
			<content:encoded><![CDATA[<p>To date this year, I have inherited several Magento stores to perform web updates on. I thought I&#8217;d write a small post on my experience and thoughts in using the system and how that system translates to real world, non technical clients.</p>
<p>As a bit of background, I&#8217;m by no means a fully fledged Magento developer in the least. After a few hours of experimenting I managed to get a template based upon my design, up and running.</p>
<p>It&#8217;s common knowledge that Magento is touted as the best thing since sliced bread &#8211; you constantly see companies selling the (what I call), &#8220;Magento experience&#8221;. Sales based pitches such as &#8220;you&#8217;ll never need to upgrade again&#8221;, &#8220;Magento can do everything out of the box&#8221; and &#8220;Magento will infinitely scale with your business&#8221; are very common from web companies. The latter does not apply to all businesses in my experience. To illustrate, I&#8217;ll use the example of a client who came to me in despair at their current web company and Magento based website &#8211; I won&#8217;t be using any real names.<br />
<span id="more-440"></span></p>
<h2>Magento &#8211; A Small Case Study</h2>
<p>My client has a small business consisting of 2-3 people, that sell hand made retro clothing. Their whole store contains 78 products &#8211; all with simple size and color attributes. Prior to using Magento, the client used oscommerce. Whilst oscommerce may be crap, the store did generate approximately £250.00 per day &#8211; which isn&#8217;t too bad at all for a small store. However, my client was approached by a web company (I&#8217;ll call them &#8220;Web Company ABC&#8221; going forward) proposing to upgrade their ecommerce platform. Web company ABC did sell them the whole Magento dream, albeit at the hefty price of £5,900.00 +vat. My client said they were impressed with the rich feature set and functionality. Hell, I am as Magento can literally do everything out of the box.</p>
<p>So, 4 months worth of delayed development later and Web company ABC had developed a rather standard looking Magento theme. Skip forward 7 months after the new site had been live on the internet and I was asked to look at doing some improvements due to it failing. Within 7 months, the store had taken ~ £450.00 &#8211; not good at all. The reason for this was clear from an SEO point of view &#8211; the site in question was total mess within Google. The upshot was that the site averaged 150 visitors per month. I promplty told my client to speak to her current web company about this, as they had paid £6,000.00 for a store and the SEO basics had not been applied. To summarise the main issues, there were lots of querystring based urls within Google and masses of duplicated content. Additionally, the company had allowed search results pages to be indexed (550 pages of them!) and all the customers login/info screens were indexed too. I suggested they install a small plugin for Magento that sets the correct canonical tag for each page.</p>
<p>The response from web company ABC: &#8220;Magento is industry leading software, as result we feel it needs no modification&#8221;. Industry leading maybe, but from what I saw it was extremely weak on the most basic SEO front. After 7 months, when Google hasn&#8217;t even indexed all your pages, something is wrong in my books.</p>
<p>Now, I haven&#8217;t looked at default SEO functionality of Magento out of the box, but a few things jumped out to me straight away:</p>
<ul>
<li>Far too many duplicated pages with no canonical tag</li>
<li>No canonical tag for category filter pages resulting in lots of additional pages indexed</li>
<li>Lots of issues with urls for products being in multiple categories, as discussed in a blog post about <a href="http://www.web-design-talk.co.uk/245/multiple-categorisation-seo/" target="_blank">multiple categorisation for seo</a></li>
<li>Unnecessary links indexed</li>
<li>Search results pages indexed</li>
</ul>
<p>Skip forward a few more weeks and the client was now asking me to design and customise some better transactional email templates as they don&#8217;t like the default Magento ones at all. They had previously spoken to their current web company (who used Magento to develop the site in question), who said it was not possible. I&#8217;m no Magento expert, but it is most definitely possible according to Google.</p>
<p>My client then asked the question that all clients who use Magento always ask &#8211; &#8220;Can you help me use the admin area, as it&#8217;s too complicated&#8221;. It&#8217;s also very common (as in this example with Web Company ABC), that full training had not been provided on how to use this area. I felt especially sorry for the client when they emailed me saying &#8220;I&#8217;ve been trying to add a new product for the last hour with no luck and no one has shown me how to do this&#8221;. Feeling very sorry for the client and knowing they had forked out close to £6,000.00 for a site I advised them to ask their current web company. The response was shocking in my opinion: &#8220;We can&#8217;t support your site to this level, there are lots of guides on the Magento official website&#8221;.</p>
<p>There are a few standout issues here when a web company has used Magneto as an ecommerce solution. Make sure you are actually Magento experts &#8211; know how the core files work, know how to customise core functionality and know more than being able to install a basic plugin. Whilst I agree Magento does have an impressive feature set, even in the community edition, it is inherently complicated and bloated. The latter is not a criticism, just something that naturally happens when a system is built that attempts to cater for a plethora of requirements.</p>
<p>Lots of web companies seem to hide behind the reputation of Magento and base their whole sales pitch around that. For the smaller clients I&#8217;ve dealt with they don&#8217;t need such a feature rich system &#8211; I&#8217;d go as far to say Magento is overkill for a lot of sites it&#8217;s used on. In my opinion, the whole system is geared towards larger companies and sites with complicated products. It is <em>not</em> geared towards small sized business with simple products. I put together a list of changes for web company ABC that would solve all the issues the client was experiencing, some involved installing small, third party plugins. The web companies response was simply: &#8220;we feel Magento works well of the box and doesn&#8217;t need any additional plugins&#8221;. Fail.</p>
<h2>The Infamous Magento Administration Area</h2>
<p>Now comes my major criticism about Magento &#8211; it&#8217;s insanely mammoth administration system. As a developer I personally like it &#8211; lot&#8217;s of functionality and settings to play with and lots of general control. For the end user, in my experience, this is the area that makes Magento fail as a platform for me &#8211; for a few reasons. For a normal user, there is simply too much functionality, and too many options to make even the most basic tasks extremely difficult. Does an end user really need functionality to control essential system settings for example? I felt really bad after accepting a small admin fee after the client emailed me the following out of pure frustration: &#8220;can you please add a discount code to my store as I&#8217;ve spent 20 minutes trying to get this to work&#8221;. All they wanted tom do was add a voucher code that knocked 20% off orders over £100, but due to the complexity they were unable to do this simple task. I personally liked this area, but can see why a non technical user would get confused.</p>
<p>If companies are going to push Magento as their platform of choice and tout it as the best thing to build your business on, they need to provide training on how to perform basic tasks within the administration area. It doesn&#8217;t matter the value of the project &#8211; the administration area remains complicated and end users need training. However good an ecommerce platform Magento may be, if end users have difficulty using it something is wrong. Web companies <em>should </em>realise this include training as part of the price.  Leaving a client with the advice of &#8220;go and read the Magento docs&#8221; (which are quite technical in their own right) is not acceptable and does little to help the client.</p>
<p>Please don&#8217;t misunderstand me here. I am not saying Magento is bad ecommerce platform. What I am saying, is that Magento does not have a place for every level of ecommerce store and that users require training. My advice, if you&#8217;re considering Magento for you platform, take note of the following:</p>
<ul>
<li>Don&#8217;t get caught up in the sales speak and try to ignore the shiny default template</li>
<li>Remeber you&#8217;ll need to set aside a great deal of time to learn the administartion area &#8211; you may need training here</li>
<li>Magento is not for every niche/business. The feature set and size of Magento implies you have a high volume of and complicated product variations</li>
<li>Remember that due to the complexity of Magento, you&#8217;ll no doubt pay a premium for updates where a plugin will not suffice</li>
</ul>
<p>What are your views on this matter?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/440/magento-ecommerce-case-study/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>How to Install CodeIgniter Within the Web Root</title>
		<link>http://www.web-design-talk.co.uk/432/install-codeigniter-web-root/</link>
		<comments>http://www.web-design-talk.co.uk/432/install-codeigniter-web-root/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 14:34:27 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=432</guid>
		<description><![CDATA[By default, when installing CodeIgniter (CI), all the important files i.e. all files withing the application and systems folders are installed within the main web directory, that is visible to anyone. This is fine to an extent because all folders have a htaccess file that denys all incoming requests. The CodeIgniter developers did this intentionally [...]]]></description>
			<content:encoded><![CDATA[<p>By default, when installing <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> (CI), all the important files i.e. all files withing the application and systems folders are installed within the main web directory, that is visible to anyone. This is fine to an extent because all folders have a htaccess file that denys all incoming requests. The CodeIgniter developers did this intentionally to make things easy for people trying the framework out.</p>
<p>However, a much more secure method is to store the application and systems folders within the server webroot. This location is not directly accessible and helps with all around application security. Personally, I feel a lot safer knowing core files are not directly accessible. The latter is doubly as important when using a well known PHP framework, as anyone has a starting point to figure out your folder structure, simply by downloading the framework.</p>
<p>Here is how a typical <strong>CodeIgniter install</strong> looks on a production server:</p>
<p><span id="more-432"></span></p>
<pre class="brush: plain; title: ; notranslate">
- CodeIgniter_2.0.3
---- application
---- system
- public_html
---- assets
---- index.php
---- .htaccess
</pre>
<p>The &#8220;public_html&#8221; directory will vary from host to host and has many names depending on the hosting setup &#8211; it is the files from which the live website is served from. The major benefit now, is the only file directly accessible is index.php. The assets folder is included in all my projects, for things such as images, css files and JavaScript. For additional security, directory browsing is disabled by means of adding the following to the main htaccess file:</p>
<pre class="brush: plain; title: ; notranslate">
Options -Indexes
</pre>
<p>To complete the move of the core CodeIgniter files there are a couple of other small tweaks:</p>
<p>Open index.php, go to line 59 (CodeIgniter v 2.0.3) and change (several lines of PHP comments have been removed here for readability)</p>
<pre class="brush: php; title: ; notranslate">
$system_path = 'system';
$application_folder = 'application';
</pre>
<p>to</p>
<pre class="brush: php; title: ; notranslate">
$system_path = '../CodeIgniter-2.0.3/system';
$application_folder = '../CodeIgniter-2.0.3application';
</pre>
<p>The latter change simply tells CodeIgniter to look for those core files in an alternative location. The absolute path to the file could have also been used.</p>
<p>The name of the CI directory has the following format: CodeIgniter-x.x.x, where x.x.x is the CI version. Naming directories this way allows different versions of CodeIgniter to be more easily upgraded, without affecting the current used version. For instance, CI version 2.0.4 would be placed in CodeIgniter-2.0.4 &#8211; $system_path and $application_folder would be adjusted accordingly.</p>
<p>The above method can be applied to any website, it doesn;t have to be CodeIgniter or a PHP Framework. For instance, say you had a vanilla PHP site that used a single configuration file and a bootsrap file &#8211; both containg lots of important settings and data. Simply place the two files within the webroot and adjust your include paths within you application pages. Another example is with third party caching systems. An application may make use of <a href="http://www.web-design-talk.co.uk/423/php-array-caching-pear-cache-lite/">PEAR Cache Lite to Cache Arrays</a> for example. It would be good practice to set the cache directory directly within the web root, meaning cache files are not directly accessible.</p>
<p>That&#8217;s it &#8211; within a couple of minutes you&#8217;ve just improved the security of your application!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.365itbackup.co.uk/faq.php">Why backup data?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/432/install-codeigniter-web-root/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP Array Caching with PEAR Cache Lite</title>
		<link>http://www.web-design-talk.co.uk/423/php-array-caching-pear-cache-lite/</link>
		<comments>http://www.web-design-talk.co.uk/423/php-array-caching-pear-cache-lite/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 20:04:55 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=423</guid>
		<description><![CDATA[In previous posts full page, block level caching with pear cache lite have been discussed. Full page level caching is fine under a lot of conditions. However, sometimes it is desirable to cache the contents of an array to a file. PEAR Cache Lite makes this very easy. The array used in the following example [...]]]></description>
			<content:encoded><![CDATA[<p>In previous posts full page, block level <a href="http://www.web-design-talk.co.uk/286/best-practices-with-pear-cache-lite/">caching with pear cache lite</a> have been discussed. Full page level caching is fine under a lot of conditions. However, sometimes it is desirable to cache the contents of an array to a file. PEAR Cache Lite makes this very easy.</p>
<p>The array used in the following example is for illustration only and very basic. On a real site the array may be the result of several database queries, or even a recursive function to display the full category structure on a website E.g. something a lot more database intensive and costly than a simple array!</p>
<p>The setup using PEAR Cache Lite is exactly the same, the only difference is within the constructor. There is an option called &#8216;automaticSerialization&#8217; (set to false by default) that enables the caching of none string data E.g. arrays. It is possible to achieve what following by using PHP&#8217;s <a href="http://php.net/manual/en/function.serialize.php" target="_blank">serialize</a> and <a href="http://php.net/manual/en/function.unserialize.php" target="_blank">unserialze</a> functions, but it&#8217;s preferable and neater to use what functionality the author of the PEAR Cache Lite class has provided. The code is very simple.</p>
<p>Firstly, include the PEAR Cache Lite class and pass the associative array of options (including the automaticSerialization key) to the class constructor (line highlighted):</p>
<p><span id="more-423"></span></p>
<pre class="brush: php; highlight: [6]; title: ; notranslate">
include 'Cache/Lite/Output.php';

$options = array(
    'cacheDir' =&gt; 'pear_cache/',
    'lifeTime' =&gt; 3600,
    'automaticSerialization' =&gt; true
);

$cache = new Cache_Lite_Output($options);
</pre>
<p>Secondly, for simplicity, include a function to generate the array to be cached. As previously mentioned, this array would come from some sort of database intensive operation under normal circumstances:</p>
<pre class="brush: php; title: ; notranslate">
function letters() {
    return range('A', 'Z');
}
</pre>
<p>Thirdly, check for a cache hit or miss. If there is a cache miss, generate the array and save it to a cache file (line 5). Otherwise, there is a cache hit and the cached data can be used directly (line 2):</p>
<pre class="brush: php; highlight: [2,5]; title: ; notranslate">
if( $data_array = $cache-&gt;get('array_of_letters') ) {
    $data =$data_array;
} else {
    $data = letters();
    $cache-&gt;save($data);
}
</pre>
<p>Lastly, use the array within your application normal (the following example simply outputs each letter with a semi colon after each item):</p>
<pre class="brush: php; title: ; notranslate">
$count = count($data);

for ( $i=0; $i    echo $data[$i];
    echo ($i != ($count-1)) ? ' : ' : null;
}
</pre>
<p>Looking at the actual cache file (open it using your PHP editor or Wordpad as it has no file extension), you can see the cached array has indeed been serialized (the letters at the beginning of the file are a timestamp and not part of your cached array):</p>
<pre class="brush: plain; title: ; notranslate">
715704231a:26{i:0;s:1:&quot;A&quot;;i:1;s:1:&quot;B&quot;;i:2;s:1:&quot;C&quot;;i:3;s:1:&quot;D&quot;; ... [removed for usability] ...   s:1:&quot;Z&quot;;}
</pre>
<p>That&#8217;s it! For reference, the full code can viewed below:</p>
<pre class="brush: php; title: ; notranslate">
include 'Cache/Lite/Output.php';

$options = array(
    'cacheDir' =&gt; 'pear_cache/',
    'lifeTime' =&gt; 3600,
    'pearErrorMode' =&gt; CACHE_LITE_ERROR_DIE,
    'automaticSerialization' =&gt; true
);

$cache = new Cache_Lite_Output($options);

function letters() {
    return range('A', 'Z');
}

if( $data_array = $cache-&gt;get('array_of_letters') ) {
    $data =$data_array;
} else {
    $data = letters();
    $cache-&gt;save($data);
}

$count = count($data);

for ( $i=0; $i    echo $data[$i];
    echo ($i != ($count-1)) ? ' : ' : null;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/423/php-array-caching-pear-cache-lite/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Appreciating Your Chosen Web Host</title>
		<link>http://www.web-design-talk.co.uk/410/appreciating-your-web-host/</link>
		<comments>http://www.web-design-talk.co.uk/410/appreciating-your-web-host/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 14:29:44 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web companies]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=410</guid>
		<description><![CDATA[Sometimes, you have small experiences that really make you appreciate your chosen web host. They leave you glad you spent the time doing your homework, testing out their support, features and generally ensuring everything is easy as possible with them. If it isn&#8217;t easy, then your job will be made all that much harder, unnecessarily. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you have small experiences that really make you appreciate your chosen web host. They leave you glad you spent the time doing your homework, testing out their support, features and generally ensuring everything is easy as possible with them. If it isn&#8217;t easy, then your job will be made all that much harder, unnecessarily.</p>
<p>I experienced such a feeling last week with a client who wanted to use their own web hosting. I had updated a small website to include a blog and gallery, both updateable by the client. This wouldn&#8217;t usually be an issue at all if using my own hosting &#8211; simply upload the files, add in my custom htaccess file for some <a href="http://www.web-design-talk.co.uk/116/seo-friendly-urls-with-mod-rewrite/">mod rewriting</a> goodness and away we go.</p>
<p>However, the host in question was <a href="http://www.1and1.co.uk" rel="nofollow external">1and1.co.uk</a>. Now, I&#8217;ve read <a href="http://www.thespanner.co.uk/2007/08/06/1and1-suck/">some</a> <a href="http://tips.webdesign10.com/web-hosting/why-you-should-never-use-1and1-com-hosting">absolute</a> <a href="http://www.simonjones.info/1and1internet/">horror</a> <a href="http://www.chrisbeach.co.uk/view/tech/avoid_oneandone_internet">stories</a> about this company in the past &#8211; all such experiences seem very typical of a very large company, with their support teams based offshore.</p>
<p>So, back onto uploading the updated site in question. I had expressed initial concerns about the clients current 1and1 hosting package, noting that they&#8217;d most likely need to upgrade with 1and1, even though they were on an intermediate hosting package entitled the &#8220;1and1 Standard package&#8221;. I had also personally been forced to use their support about a year ago, which was hard work to say the least. Moving forward, I carried on and uploaded the site to 1and1&#8242;s servers and then visited site. Instant internal server error 500. Straight away I knew this was the hosting as I had previously given the client a link to a staging area on my preferred web host, that worked flawlessly. I&#8217;m aware 1and1 have some restrictive hosting on their basic packages (which seems to be inherant of such a large company, with thousands of customers in my experience), so I immediately headed towards to the .htaccess file (it&#8217;s essentially a variation of the <a href="http://html5boilerplate.com/">HTML5 Bolierplate template</a> with some of my own magic included, nothing out of the ordinary though) and renamed the htaccess file. Whallah &#8211; the site loaded, thus isolating the issue straight away. Great, I can inform 1and1 and find out what htaccess directives are allowed, it <em>should</em> be a run of the mill support request for any support department.</p>
<p><span id="more-410"></span>However, such a request to 1and1&#8242;s support department wasn&#8217;t easy in the least, in fact it was very challenging. After being on hold for roughly 10 minutes I was answered by one of their offshore support staff, who was quite difficult to understand, yet very polite. All I wanted to know was what, if any, features they support on custom htaccess files, on the clients current hosting package. Simple right?</p>
<p>This is the point things got a little messy unfortunately (yes, so early on in the telephone call). After putting me on hold for a further 5 minutes, the lady came back to telephone to tell me to &#8220;check my htaccess file for misconfigurations&#8221;. I  reiterated my previous statement (as there are no errors) and she told me to &#8220;please hold so she could check more things&#8221;, after saying it is easy to leave typos in htaccess access files (I guess that&#8217;s true, but it wasn&#8217;t the case here). After a further 5 minutes was told to go to a PHP script she had uploaded on the site, that displayed the output of a phpinfo call, that I should &#8220;check&#8221;.</p>
<p>Let&#8217;s take a step back here. I have isolated the error down to a server restriction on the 1and1 end. Their response has been to check my perfectly working htaccess file and to look at the output of a phpinfo call. It should be obvious to a person working on a technical support line that if I&#8217;m not getting an internal server error after removing a htaccess file, then the issue lies with the custom  htaccess file &#8211; it&#8217;s error isolation 101, surely? I explained this yet again to the operator who then suggested I &#8220;remove the htaccess file to prevent misconfigurations&#8221;. At this point I was getting a little impatient, decided to make my excuses and end the call &#8211; as we were getting no where. Granted, the lady was very polite on the phone, but my issue was not getting dealt with at all.</p>
<p>So after a 35 minute phone call, I was still left with a site, through no fault of my own, that wasn&#8217;t working. Not good for me, the client or my general sanity. I decided to call again, in order to get this resolved. I sometimes do this in the hope of speaking to a different, more informed member of staff. Sometimes I get lucky, others I don&#8217;t.</p>
<p>The second time I called I believe I spoke to someone a little more experienced, still in an offshore location though. I had to re explain my issue again (there were no recent calls logged, quite annoying &#8230;), I got equally as illogical replies as before. I was told one &#8220;solution&#8221; (said in the loosest sense here) was to go through each line of the htaccess one by one and keep commenting out lines until I tracked down the issue. The file is over 250 lines long &#8211; no thanks! That is not a solution at all in my books. At this point I gave up and decided to report back to client.</p>
<p>What was a little odd related to the emails that got sent the my client, about 20 minutes after my first call &#8211; my client forwarded these onto me. Here is a copy of paste (the gramatical errors are definately not mine!!!) of the email:</p>
<blockquote><p>This is an update regarding your previous call, abou your site &#8220;**********&#8221; that is showing error 500. When there is an error with a .htaccess file, all pages of the website will display a 500 error indefinitely until the .htaccess file is corrected or removed. As little as a simple spelling mistake or syntax error will cause a 500 error. If the .htaccess file has been edited recently, replace the file with a backup. If no backup is available, try to undo the changes to the file if you can remember what has been altered. If those options are not feasible, you can try commenting lines one by one by placing a pound sign(#) at the beginning of the line to comment it out. Then try to access a page of the site. Continue to add the pound sign to more lines until the 500 error stops which should help you pinpoint which line needs to be corrected.</p></blockquote>
<p><em>(email sent 14 October 2011 15:51:36 GMT, from support@1and1.co.uk)</em></p>
<p>I then got the following email from them re the second call:</p>
<blockquote><p>This is an update regarding your call awhile ago, please refer to our FAQ link below for you to check the php settings on the server. You will need to create a phpinfo.php file using notepad and copy the code then paste it in your phpinfo.php file: How can I check the PHP settings on the server? <a href="http://faq.oneandone.co.uk/server/managed/8.html" rel="external, nofollow">http://faq.oneandone.co.uk/server/managed/8.html</a></p></blockquote>
<p><em>(email sent 14 October 2011 16:42:00 GMT, from support@1and1.co.uk)</em></p>
<p>A little later, the following email came through, again a copy and paste:</p>
<blockquote><p>Please upload the phpinfo file for you to get hold of the list of all settings allowed on our servers. With regard to the .htaccess file, sometimes the problem is with the syntax you encoded. In this regard, we highly advise that you make sure you key in the correct directives in order to prevent further issues.</p></blockquote>
<p><em>(email sent 15 October 2011 06:23:00 GMT, from support@1and1.co.uk)</em></p>
<p>Great, yet more generic statements that don&#8217;t help. We have established several times now that the htaccess file was working correctly on the 1and1 hosting, that the issue was due to the 1and1 servers and that all I wanted to know was what, if any, htaccess directives are allowed/disallowed.</p>
<p>These emails are not helpful to anyone and needless to say, I won&#8217;t be chasing 1and1 up any further about this &#8211; it&#8217;s far too time consuming. Instead (and for the sake of my own sanity) I advised my client to transfer her site.</p>
<p>What is most concerning, apart from the fact 1and1 support have drastically failed to understand my rather basic issue, is that the replies are clearly written without appreciation for none technical people &#8211; everyone doesn&#8217;t know (read: probably doesn&#8217;t <em>want</em> to know) about the technical aspects of PHP settings and htaccess files.</p>
<p>I digres, all that is done now and the site has been uploaded to some quality web hosting where I can use a htaccess file. When I compare the poor level of customer service, the poor technical knowledge they demonstrated and the fact that a simple issue went on for much longer than it should have, to my current web host, the difference is night and day. With my preferred host, everything is so easy, if I need support I can get answered within a few minutes maximum.</p>
<p>At times like these and as a web developer, you really appreciate a good web host and things &#8220;just working&#8221;. However, the major difference between webhosts in my opinion, is flexibility and basic reason in my experience. Support teams/staff who take the time to understand your issue and have flexibility in solving your issue are easier to deal with. For instance, on my preferred hosts I was having a small issue with a php hashing framework, casuing my site to not work correctly. All that was required was quick email stating the problem and a response saying that they have added in a few commands to a custom php.ini file &#8211; the issue was essentially turned into a none issue &#8211; all sorted within 10 minutes (even though this issue was potentially more complicated than my little htaccess problem).</p>
<p>No drama, no drawn out telephone conversations to offshore locations &#8211; just my issue being solved within good time (thanks to Darren from tsohost for this by the way!). Another big benefit highlighted here is having knowledgeable people &#8211; when I stated my issue, they clearly know what they are talking about and clearly are not reading from prompt sheets &#8211; this alone, speeds up support requests significantly. I have personally come to the conclusion that the staff I was speaking to were using prompt sheets &#8211; purely due to the level of answer (or lack of answer) I was provided with.</p>
<p>Honestly, before you ever choose a webhost do yourself a huge favour. Do not look for the cheapest price. Do your research and test out your potential host first. Pay particular attention to quality and speed of support you receive. I couldn&#8217;t go through the above every time I needed a basic support question answering.</p>
<p>The above represent&#8217;s my own, personal opinion and is in accordance with my <a href="http://www.web-design-talk.co.uk/disclaimer/" rel="nofollow">blog disclaimer</a>. It does not represent any company I have ever or currently work for.</p>
<p>&nbsp;</p>
<p>LATE NIGHT UPDATE! I was just about to go to bed and the following email came through, very unhelpful (although very polite) &#8211; I&#8217;m not sure why this issue is such a huge deal? How is a server error out of the scope of a technical support department????? Anyway: the email (copy and pasted again):</p>
<blockquote><p>We deeply apologize for this inconvenience. Error 500 is misconfiguration of script in the .htaccess file. Please check it and we are no longer able to extend our help as this is already out of our scope of support. Again, we understand your frustration and we deeply apologize for the inconvenience.</p></blockquote>
<p><em>(email sent 15 October 2011 21:14:00 GMT, from support@1and1.co.uk)</em></p>
<p>If anyone is interested, I can post by email response to the latter email. But as you&#8217;d imagine, I was less than pleased at the exceptionally poor level of service from 1and1 <img src='http://www.web-design-talk.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/410/appreciating-your-web-host/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Enchaning an Invoicing System for Reporting</title>
		<link>http://www.web-design-talk.co.uk/383/enchaning-a-invoicing-system-for-reporting/</link>
		<comments>http://www.web-design-talk.co.uk/383/enchaning-a-invoicing-system-for-reporting/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 19:44:04 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=383</guid>
		<description><![CDATA[At the start of the year I wrote a custom invoicing system for a client, using PHP and Smarty (hope to convert to use Twig at some point). The client has since come back to me to built in extra functionality &#8211; namely a reporting section. I thought I&#8217;d share my solution to the issue [...]]]></description>
			<content:encoded><![CDATA[<p>At the start of the year I wrote a custom invoicing system for a client, using PHP and Smarty (hope to convert to use Twig at some point). The client has since come back to me to built in extra functionality &#8211; namely a reporting section. I thought I&#8217;d share my solution to the issue I was faced with.</p>
<p>The client required some fairly involved reporting facilities, here is a sample of some of the requirements from the client:</p>
<ul>
<li>Aggregated report, split between two dates of our choosing, with totals split by either month, day or week (we want to choose)</li>
<li>A list of invoices for a day of our choosing with aggregated totals of for the day selected</li>
<li>Annual invoicing report &#8211; we want to show a summary of the total for the items sold, the total vat charged and summaries for average invoice values</li>
<li>Invoices totals grouped by customer</li>
</ul>
<p>There were several more, but they were all similar to the above.</p>
<p>Firstly, I&#8217;ll explain the database setup, for the invoicing, of the current system I built. It was basically two tables &#8211; one for the invoivce header and one table for the invoices items &#8211; nothing un typical there at all.</p>
<p><span id="more-383"></span></p>
<p>My first point of call to integrate the reporting was to use what I had already. This proved qwuite complicated as it involved fecthing large sets of data to calculate the totals required by the reports &#8211; this was also pretty slow when running the more intensive reports over a longer date range. It would get even more complicated and database intensive when I wanted totals for the other reports.</p>
<p>After some consideration, my solution to this was simple. I decided to add a few new columns to my invoice header table &#8211; &#8220;invoice_total&#8221;, &#8220;invoice_sub_total&#8221;, &#8220;invoice_vat&#8221; and &#8220;total_invoice_items&#8221;. For the reporting side of things, this made the whole process much easier. For example:</p>
<p>To get an aggreate total figure invoiced between two dates, I required a single sql statement, that required no joins, or loops in PHP:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT SUM(`invoice_total`) As total_invoiced FROM `invoice_header` WHERE (`invoice_issue_date` &gt;= :myDate AND `invoice_issue_date`
</pre>
<p>Equally as simple, to get a monthly total between two dates, grouped by month, the sql statement was just as simple:</p>
<pre class="brush: sql; title: ; notranslate"> SELECT SUM(`invoice_total`) As total_invoiced FROM `invoice_header` WHERE (`invoice_issue_date` &gt;= :myDate AND `invoice_issue_date`
</pre>
<p>Getting average invoice sub total between two dates:</p>
<pre class="brush: sql; title: ; notranslate"> SELECT AVG(`invoice_sub_total`) As average_invoice_subtotal FROM `invoice_header` WHERE (`invoice_issue_date` &gt;= :myDate AND `invoice_issue_date` </pre>
<p>The latter made the actual PHP code required to produce the required reports very straightforward &#8211; before I would have required joins to caluclate the totals and multiple sql queries &#8211; that could have got quite messy. I also gained a few added benefits of storing the totals within my header table:</p>
<ul>
<li>On the print invoice screen, there was need to calculate anything, as I simply read the totals from the datbase</li>
<li>On the invoice listing screens, I could now display an invoice total in a seperate column, as this was again, simply a database value &#8211; before I would have needed to calculate this total via the invoice items table</li>
</ul>
<p>However, this simplicity in one area, came at a cost &#8230; unfortunately. As all report data was now based from totals in the invoice header table, this figure needed to be correct at all times. I needed to amend the add and edit invoice functions. When adding an invoice, I needed another loop to calculate the aggregate totals to insert into the database. When editing the invoice, I needed to recalculate these totals each time the invoice was edited (in case a row was deleted for example). Whilst the latter added a little more work when adding/editing invoices, I feel that this is well worth it due to simplicity when dealing with the reporting side.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/383/enchaning-a-invoicing-system-for-reporting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEO URL Correction</title>
		<link>http://www.web-design-talk.co.uk/306/seo-url-correction/</link>
		<comments>http://www.web-design-talk.co.uk/306/seo-url-correction/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 19:16:34 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=306</guid>
		<description><![CDATA[The use of mod_rewrite to create SEO friendly URLs is common place now. However, if an application is not coded correctly they can have potentially negative effects. Take the fowllowing URL, this is the URL the developer intended &#8211; the news story is fetched from the ID in the querystring: However, if the application is [...]]]></description>
			<content:encoded><![CDATA[<p>The use of mod_rewrite to create <a href="http://www.web-design-talk.co.uk/116/seo-friendly-urls-with-mod-rewrite/">SEO friendly URLs</a> is common place now. However, if an application is not coded correctly they can have potentially negative effects.</p>
<p>Take the fowllowing URL, this is the URL the developer intended &#8211; the news story is fetched from the ID in the querystring:</p>
<pre class="brush: xml; title: ; notranslate">

http://www.site.com/news/23/some-breaking-story.html
</pre>
<p><span id="more-306"></span></p>
<p>However, if the application is coded badly the following URLs may also exist in order to reach the same content:</p>
<pre class="brush: xml; title: ; notranslate">

http://www.site.com/news/23/ANYTEXTHERE-some-breaking-story.html

http://www.site.com/news/23/some-breaking-story.php

http://www.site.com/news/23
</pre>
<p>The latter can have potential issues for your SEO rankings. If search engines pickup on the fact that muliple URLs all goto the same duplicate content then your site send out bad signals to search engines &#8211; this should be avoided. There si recent talk that duplicate content is simply ignored by search engines and now a none issue. However, even ignoring direct penalties imposed on your site, having the same content divided over multiple URLs can reduce your rankings simply by diluting content.</p>
<p>The answer is URL correction and correct use of headers. A single URL for a single page is the goal. This is fairly easy toachieve by following the below methodology in your scripts:</p>
<ul>
<li>Make your mod_rewrite rules specific (E.g. don&#8217;t use lots of ([^/]*) flags as that will match anything!)</li>
<li>Create a standard base URL for the content</li>
<li>When the page loads, check that the base URL (or expected URL) matches the page requested by the visitor</li>
<li>If there is a mismatch, set the correct HTTP headers and redirect to the correct, expected URL</li>
</ul>
<p>Firstly, adjust your rewrite rule to be more specific:</p>
<pre class="brush: xml; title: ; notranslate">
RewriteRule ^news/([0-9]+)/(-a-zA-Z)\.html$ news.php?TITLE=$2&amp;NEWSID=$1 [L]
</pre>
<p>This now looks for the following pattern: a number, letters and then a .html extension.</p>
<p>You can also adject your application logic to add in the following:</p>
<pre class="brush: php; title: ; notranslate">
/* At this point, query your database to retreive information
The variables $title and $id would come from the database */
$actual_url = myClass:getCurrentRequestedURL();
$expected_url = LinkFactory::NewsItem($title, $id);

ob_start();

if ($expected_url != $actual_url) {
ob_clean();
header('HTTP/1.1 31 Moved Permanently'); //Send 301 status code
header('Location: ' . $expected_url); //redirect to expected url
ob_flush();
}
</pre>
<p>Depending on your url rewriting structure, you&#8217;ll notice that WordPress does a very similar thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/306/seo-url-correction/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Store an AJAX Response into a Variable using JQuery</title>
		<link>http://www.web-design-talk.co.uk/303/store-ajax-response-jquery/</link>
		<comments>http://www.web-design-talk.co.uk/303/store-ajax-response-jquery/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 17:42:20 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=303</guid>
		<description><![CDATA[Sometimes, it&#8217;s very useful and a lot cleaner to store the result of an AJAX request into a variable &#8211; that can used in your script. For instance, say you&#8217;re using some sort of calander plugin that takes an array of exluded dates. It is highly likely that these dates will come from an database. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, it&#8217;s very useful and a lot cleaner to store the result of an AJAX request into a variable &#8211; that can used in your script. For instance, say you&#8217;re using some sort of calander plugin that takes an array of exluded dates. It is highly likely that these dates will come from an database. You could echo them out manually by mixing PHP, HTML and JQuery, but this is very messy.</p>
<p>Instead, you could create an AJAX request that queries a database for the dates and stores them in a variable. This is fairly simply when using JQuery:</p>
<p><span id="more-303"></span></p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {

    var myAJAXVariable = (function () {
        var myAjaxValue = null;
        $.ajax({
            'async': false,
            'global': false,
            'url': 'ajax.php',
            beforeSend: function () {
                $('h1').css('background-image', 'url(ajax.gif)');
            },
            success: function (returnedData) {
                $('h1').css('background-image', 'none').html(returnedData);

            }
        });
        return myAjaxValue;
    })();

});
</pre>
<p>The ajax.php file simply returns a list of comma seperated numbers from a loop &#8211; in reality this woulod be actual output from your database. The contents of ajax.php:</p>
<pre class="brush: php; title: ; notranslate">
$values = array();
for ($i = 1; $i&lt;11; $i++) {
    $values[] = rand($i, $i*23);
}
$data = implode(&quot;, &quot;, $values);
sleep(3);
echo $data;
</pre>
<p>There is a delay of 3 seconds to simulate an intensive script &#8211; so the example doesn&#8217;t load instantly. The HTML is very basic, it only requires a single, empty h1 tag (as I&#8217;ll be loading the contents of AJAX result into it).</p>
<p>That&#8217;s it, the final result can be <a rel="nofollow" href="http://www.web-design-talk.co.uk/examples/11/index.php">seen here</a> and you can download the source files from <a rel="nofollow" href="http://www.web-design-talk.co.uk/examples/11/11.rar">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/303/store-ajax-response-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Practices With PEAR Cache Lite</title>
		<link>http://www.web-design-talk.co.uk/286/best-practices-with-pear-cache-lite/</link>
		<comments>http://www.web-design-talk.co.uk/286/best-practices-with-pear-cache-lite/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 20:58:14 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=286</guid>
		<description><![CDATA[Caching a website using PEAR Cache Lite has many benefits &#8211; it will speed up your site and is very simple to implement. However, there are several common pitfalls they could cause potential issues on a website. Basically, you can&#8217;t approach caching from a single angle, as the type of caching used is always project/problem [...]]]></description>
			<content:encoded><![CDATA[<p>Caching a website using <a href="http://www.web-design-talk.co.uk/226/php-caching-pear-cache-lite/">PEAR Cache Lite</a> has many benefits &#8211; it will speed up your site and is very simple to implement. However, there are several common pitfalls they could cause potential issues on a website. Basically, you can&#8217;t approach caching from a single angle, as the type of caching used is always project/problem specific.</p>
<h2>Full File Level Caching</h2>
<p>Full file caching is the simplist method and essentially takes an image of the page at a particular time. This method is very fast to implement but does have it&#8217;s downsides. As you are storing a static file of the page you&#8217;ll instantly notice the following issues (I&#8217;ve included some typical examples you&#8217;ll run into):</p>
<ul>
<li>Any elements of your page that require session data will fail to work (you&#8217;ve essentially cached the session id too!)</li>
<li>If the page needs to be served using a particular header you&#8217;ll be out of luck, as a statiuc file will always be served using a plain text header (E.g. a cached rss feed won&#8217;t validate as the header has changed)</li>
<li>Clearing the cache becomes very clumsey as the whole cache requires cleaning when even a small change is made (E.g. say a new article is added by the admin)</li>
<li>User logins that make use of session data</li>
<li>E-Commerce sites and a shopping basket summary</li>
<li>Search results pages</li>
</ul>
<p>With full file caching dynamic content will always be a issue. However, full file caching CAN help high traffic sites, even when a short cache lifetime is set &#8211; use with caution!<br />
<span id="more-286"></span></p>
<h2>Block Level or Partial File Caching</h2>
<p>Block level caching is likely to be a much longer term caching solution. It is more likely that you&#8217;ll have certain sections of a site that do not require an up to date minute. For example, say we have an ecommerce store with dropdown menu that list our full category structure from a database &#8211; this is likely to be highly database intensive and may use recursion. This output can be cached to a flat file as follows:</p>
<pre class="brush: php; title: ; notranslate">
$options = array(
    'cacheDir' =&gt; '/cached/',
    'lifeTime' =&gt; 1000
);

$cache = new Cache_Lite_Output($options);

if (!$cache-&gt;start('left_category_structure')) {
   $store-&gt;list_full_category_structure();
   $cache-&gt;end();
}
</pre>
<p>This is much better than full file caching for several reasons:</p>
<ul>
<li>The page in question can remain dynamic dynamic elements such as the user&#8217;s login status on another part of the page</li>
<li>If a change is made to the category structure I can delete that particular section of the cache only (the rest of the cache does not require regenerating!)</li>
<li>The cache lifetime can be set on a per block basis &#8211; useful for different types of content</li>
<li>Even if the category structure doesn&#8217;t change often, the block could still be cache forever (set cacheLifeTime to null in the options array) and cleaned when a change is made</li>
</ul>
<h2>Taking Partial Caching Further</h2>
<p>PEAR Cache_LIte is also fairly flexible and you can make it fit your needs. For example, say we wanted to cache 10 random articles on a website &#8211; which consists of a database query that fetches 10 random articles from a database. The idea here is to still cache the content in a block as above. However, for this our system would create a number of cache blocks and then service those cached blocks to the user. The solution is a simple one, building on the example from above:</p>
<pre class="brush: php; title: ; notranslate">
$options = array(
    'cacheDir' =&gt; '/cached/',
    'lifeTime' =&gt; 1000
);

$cache = new Cache_Lite_Output($options);

if (!$cache-&gt;start( 'left_category_structure . rand(1,5))) {
   $store-&gt;list_full_category_structure();
   $cache-&gt;end();
}
</pre>
<p>When the user requests a page, 5 different cache blocks will be checked &#8211; we are essentially creating 5 different versions of the random cached content.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/286/best-practices-with-pear-cache-lite/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Image Uploads &#8211; Better File Type Checking</title>
		<link>http://www.web-design-talk.co.uk/280/php-image-upload-checking/</link>
		<comments>http://www.web-design-talk.co.uk/280/php-image-upload-checking/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 21:13:24 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=280</guid>
		<description><![CDATA[When working on a project I came across a neat snippet of code that will uses PHP&#8217;s image manipulation functions to check the uploaded image type. The majority of the time the filetype is checked using PHP&#8217;s string functions on the file name, as a string E.g. This is fine, but the contents of $myFile [...]]]></description>
			<content:encoded><![CDATA[<p>When working on a project I came across a neat snippet of code that will uses PHP&#8217;s image manipulation functions to check the uploaded image type. The majority of the time the filetype is checked using PHP&#8217;s string functions on the file name, as a string E.g. </p>
<pre class="brush: php; title: ; notranslate">
$myFile = $_FILES['myFile']['name'];
$allowed_filetypes = array('.gif', '.JPEG');
$ext = substr($myFile, strpos($myFile,'.'), strlen($myFile)-1);
</pre>
<p>This is fine, but the contents of $myFile can be faked. A much better check for allowing only image file uploads would be to do the following &#8211; I thought this was quite neat: </p>
<pre class="brush: php; title: ; notranslate">
if (!$img = @imagecreatefromgif($path_to_image)) {
  /* NOT a .GIF image */
}
</pre>
<p><a href="http://php.net/manual/en/function.imagecreatefromgif.php">imagecreatefromgif</a> will return false if the image is not a GIF. A similar thing can be done for checking PNGs (see <a href="http://www.php.net/manual/en/function.imagecreatefrompng.php">imagecreatefrompng</a>) and JPEGs (see <a href="http://www.php.net/manual/en/function.imagecreatefromjpeg.php">imagecreatefromjpeg</a>). </p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/280/php-image-upload-checking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Populate Select Boxes using a Global Associative Array with PHP</title>
		<link>http://www.web-design-talk.co.uk/275/populate-select-boxes-global-array-php/</link>
		<comments>http://www.web-design-talk.co.uk/275/populate-select-boxes-global-array-php/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 19:17:42 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=275</guid>
		<description><![CDATA[The following post is being written because today I&#8217;ve been annoyed, very annoyed. I&#8217;ve been working on updates to a previous developers mini CRM system that I inherited, unfortunately. Basically, the customer wanted to amend the list of options that appear in a HTML select box, on pretty much every page. In this case, 24 [...]]]></description>
			<content:encoded><![CDATA[<p>The following post is being written because today I&#8217;ve been annoyed, very annoyed. I&#8217;ve been working on updates to a previous developers mini CRM system that I inherited, unfortunately. Basically, the customer wanted to amend the list of options that appear in a HTML select box, on pretty much every page. In this case, 24 pages.</p>
<p>Ok, easy job &#8211; or so I thought. If the previous developer hadn&#8217;t been a total mong this simple update would have taken a minute or so &#8211; simply update a common function, database or global array to repopulate the drop down list options. No luck in the least &#8211; the developer had hard coded each drop down into every page, using HTML &#8211; **** great! So I just spent close to 40 minutes wading through include files and HTML to make my changes &#8211; so unecessary.</p>
<p>So, what follows is a very simple method to have a common drop down list that will be included on any page you want, with the data stored in a<strong> global array</strong> (could be a database, but a <a href="http://php.net/manual/en/language.variables.scope.php" target="_blank">global array</a> is quickest:</p>
<p>The include, model or config file &#8211; simple an<strong> associative array </strong>that will be accessible throughout your application (lets call this file includes.php):</p>
<p><span id="more-275"></span></p>
<pre class="brush: php; title: ; notranslate">
global $customer_types;
$customer_types = array(&quot;1&quot;=&gt;&quot;Normal&quot;, &quot;2&quot;=&gt;&quot;Debtor&quot;, &quot;3&quot;=&gt;&quot;Dispute&quot;, &quot;4&quot;=&gt;&quot;Premium&quot;);
</pre>
<p>The page or view &#8211; simply loop through the associative array (as we defined it as a global variable earlier) using the key/value style:</p>
<pre class="brush: php; title: ; notranslate">
include 'includes.php';
echo '&lt;select name=&quot;myTypes&quot;&gt;';

foreach ($customer_types as $key=&gt;$value) {
    echo '&lt;option value=&quot;'.$key.'&quot;&gt;'.$value.'&lt;/option&gt;';
}

echo '&lt;/select&gt;';
</pre>
<p>&#8230; and there you have it, in a couple of lines code you have an select box that can be maintained from a single file and used on as many pages as required.</p>
<p>/slaps previous developer for making me waste 40 minutes unecessarily <img src='http://www.web-design-talk.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/275/populate-select-boxes-global-array-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

