<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>code-diesel</title>
	
	<link>http://www.codediesel.com</link>
	<description>/* PHP &amp; MySQL Journal */</description>
	<lastBuildDate>Thu, 23 May 2013 04:49:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Code-diesel" /><feedburner:info uri="code-diesel" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><feedburner:emailServiceId>Code-diesel</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Tips and Tricks for Improved Drupal Security</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/VQL8g6kV8UY/</link>
		<comments>http://www.codediesel.com/security/tips-and-tricks-for-improved-drupal-security/#comments</comments>
		<pubDate>Wed, 15 May 2013 03:52:49 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[drupal]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3219</guid>
		<description><![CDATA[Drupal is one of the most popular free and open source web application frameworks. Drupal is almost infinitely extensible through not only various theme possibilities but also the vast library of modules or add-ons. However, this great extensibility is also a point of weakness should insecure or vulnerable code be used in either themes or [...]]]></description>
				<content:encoded><![CDATA[<p>Drupal is one of the most popular free and open source web application frameworks. Drupal is almost infinitely extensible through not only various theme possibilities but also the vast library of modules or add-ons. However, this great extensibility is also a point of weakness should insecure or vulnerable code be used in either themes or community contributed modules that can result in compromise. The following guide on best practices for Drupal covers main areas of attention in regards to security for any Drupal web administrator.<br />
<span id="more-3219"></span></p>
<h4>1. Upgrade to Drupal 7</h4>
<p>Even though Drupal 6 is still supported, upgrading to Drupal 7 is recommended for the many security enhancements as well as usability enhancements.</p>
<p>Because of core coding changes in Drupal 7, existing modules have to be re-written to support Drupal 7. This has unfortunately caused a delay in adoption of Drupal 7 as many sites rely on various contributed modules which in some cases have no Drupal 7 counterpart or only experimental versions still testing in Drupal 7.</p>
<p>Drupal 7 finally includes the ability to update modules from the web interface. Drupal 6 security has been perceived as poor in large part because of many sites not updating Drupal core or any associated modules. With Drupal 6, applying updates for general maintenance was somewhat problematic and inconvenient. This is perhaps what led to many sites putting off updates leading to many Drupal installations being compromised. Updating is improved in Drupal 7, and is somewhat similar to the web-based updates that WordPress users have been enjoying.</p>
<p>Other Drupal 7 security benefits include:</p>
<p><strong>Stronger security for stored user passwords</strong><br />
Passwords in Drupal 7 are hashed with phpass, combining multiple rounds and salted hashes. Drupal 6 and prior stored user passwords in MD5 in the database which is now considered weak and easily crackable.</p>
<p><strong>Update notifications</strong><br />
Drupal 7 incorporates automated email notifications of any pending module or core security updates. This is also available in Drupal 6 via a module, but is now built in as functionality in Drupal 7.</p>
<p><strong>Login Rate-Limiting</strong><br />
Drupal 7 now incorporates brute force login protection. Defaults are rate limiting for five failed attempts in a six hour window as well as rate limiting 50 failed attempts from one IP address per hour. This is configurable in modules/user/user.module.</p>
<h4>2. Keep Drupal up-to-date</h4>
<p>Keeping Drupal up-to-date is the fundamentally most important security consideration.<br />
Drupal security consists of three areas to maintain security updates:<br />
-	Drupal Core updates<br />
-	Contributed Module security updates<br />
-	Theme security updates<br />
Drupal Core update announcements are available from <a href="http://drupal.org/security" target="_blank">http://drupal.org/security</a>.<br />
As of Drupal 7, every window in the Administration interface notifies of a pending Drupal Core update.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2013/05/drupal_modules.jpg"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/drupal_modules.jpg" alt="drupal_modules" width="600" height="516" class="aligncenter size-full wp-image-3221" /></a></p>
<p><strong>Modules</strong><br />
Drupal module update announcements are available from <a href="http://drupal.org/security/contrib" target="_blank">http://drupal.org/security/contrib</a>. Drupal 7 has built-in email notification for any outstanding module security updates as well to notify admins of pending updates. Resist the temptation to develop or write custom email forms or other elements for Drupal, but rather look for existing well-established modules that are written to serve various purposes. Existing modules have been tested for the most part in a wide install base and have had more eyeballs on the code to check for security flaws.<br />
Completely remove any disabled modules from the server so as not to have any older vulnerable code live and present in web directories.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2013/05/drupal_updates.jpg"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/drupal_updates.jpg" alt="drupal_updates" width="600" height="516" class="aligncenter size-full wp-image-3222" /></a></p>
<p><strong>Check your sources</strong><br />
In choosing a Drupal theme, consider building upon or using a tested well used theme that has continued updates from the developer. Often users will pick a theme that is ‘pretty’ or meets other cosmetic requirements. However it is critical to inspect if the theme is currently being maintained for security updates. Do not install themes found randomly on the internet; only choose themes from Drupal’s Download &#038; Extend which have been recently maintained. Even then, closely inspect the source to be vetted before launching the code live in a Drupal installation.</p>
<p>Drupal XSS exploits through themes are not uncommon. For example the following theme is susceptible to XSS as one illustration: <a href="http://drupal.org/node/1608780" target="_blank">http://drupal.org/node/1608780</a></p>
<p>If creating a custom theme, thoroughly test the theme in an installation with various web application scanners, either open source or commercial, that test for XSS or SQLi prior to deployment.</p>
<p><strong>Drush</strong><br />
Drush is the ultimate command line utility to manage Drupal. With drush, it is possible to do such tasks as clearing all Drupal caches, upgrade Drupal core and modules, apply database upgrades (similar to running update.php), enable/disable modules, and much more.<br />
If not already using drush, this is a valuable tool to be on top of and easily patch any outstanding Drupal security updates. More information is at the following URL <a href="http://drupal.org/project/drush/" target="_blank">http://drupal.org/project/drush/</a>.</p>
<h4>3. Enable SSH for Update Manager</h4>
<p>The built-in Update Manager for updating through the web interface or installing modules in Drupal 7 has the ability to use SSH to connect to the host. This is of course the preferred way to transfer files instead of FTP. If SSH does not show up as an option in Drupal 7′s Update Manager, install the following PHP library:<br />
Debian / Ubuntu:</p>

<div class="wp_codebox"><table><tr id="p32198"><td class="code" id="p3219code8"><pre class="shell" style="font-family:monospace;">$ sudo apt-get install libssh2-php</pre></td></tr></table></div>

<p>Red Hat / CentOS:<br />
Red Hat and CentOS do not include ssh libraries for PHP. The required package php-pecl-ssh2 can however be installed from the EPEL repository (<a href="http://fedoraproject.org/wiki/EPEL" target="_blank">http://fedoraproject.org/wiki/EPEL</a>).</p>
<h4>4. HTTPS and Drupal</h4>
<p>Drupal by default operates only over HTTP, including sending any login credentials in plain text. One solution is to have the entire site operate over HTTPS. But while perhaps having an entire site over HTTPS is not ideal as of date, steps can be taken to at least have credentials and other form submissions in Drupal to occur over HTTPS.<br />
Drupal 7 by default uses the secure flag for HTTPS cookies to prevent session hijacking. The module Secure Login (<a href="http://drupal.org/project/securelogin" target="_blank">http://drupal.org/project/securelogin</a>) is a required module to help further take advantage of this feature. The Secure Login module allows not only logins but also form submissions in Drupal to occur over HTTPS and have a unique HTTPS session cookie that cannot be hijacked.</p>
<p>Along with the secure cookie flag, the httponly cookie flag can be set in php.ini on the server for another layer of security. In Debian or Ubuntu, edit the following file:</p>

<div class="wp_codebox"><table><tr id="p32199"><td class="code" id="p3219code9"><pre class="text" style="font-family:monospace;">/etc/php5/apache2/php.ini</pre></td></tr></table></div>

<p>Red Hat or CentOS, edit the following file:</p>

<div class="wp_codebox"><table><tr id="p321910"><td class="code" id="p3219code10"><pre class="text" style="font-family:monospace;">/etc/php.ini</pre></td></tr></table></div>

<p>Use the following values to enforce the httponly flag for PHP session cookies:</p>

<div class="wp_codebox"><table><tr id="p321911"><td class="code" id="p3219code11"><pre class="text" style="font-family:monospace;">session.cookie_httponly = 1
session.use_only_cookies = 1</pre></td></tr></table></div>

<p>Without these above changes, one could potentially intercept and steal the authenticated cookie to then gain authenticated access to the Drupal installation.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2013/05/drupal_https.jpg"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/drupal_https.jpg" alt="drupal_https" width="600" height="571" class="aligncenter size-full wp-image-3223" /></a></p>
<h4>5. Web server permissions</h4>
<p>Permissions of the directories and files in Drupal are critical for security. Files or directories should never be 777, nor are 777 permissions required for Drupal to operate. Directories should be 750 or 755 and files should be 644 or 640.</p>
<p>The Drupal directory and files should be owned by a regular user, and the group of the apache user. This can cause problems for automated updates. Temporarily changing permissions to have the apache user own the Drupal directory so to install updates may be required. Once updates are complete, change the Drupal directory back to be owned by a regular user.</p>
<p>This example command changes the owner to jsmith (example username) and group of the Apache user on Debian and Ubuntu for all files in the Drupal installation:</p>

<div class="wp_codebox"><table><tr id="p321912"><td class="code" id="p3219code12"><pre class="shell" style="font-family:monospace;">$ sudochown -R jsmith:www-data /var/www/drupal</pre></td></tr></table></div>

<p>To temporarily switch permissions to allow updates, change the owner to the apache user:</p>

<div class="wp_codebox"><table><tr id="p321913"><td class="code" id="p3219code13"><pre class="shell" style="font-family:monospace;">$ sudochown -R www-data:www-data /var/www/drupal</pre></td></tr></table></div>

<p>Next perform updates, then set permissions back:</p>

<div class="wp_codebox"><table><tr id="p321914"><td class="code" id="p3219code14"><pre class="shell" style="font-family:monospace;">$ sudochown -R jsmith:www-data /var/www/drupal</pre></td></tr></table></div>

<h4>6. Recommended Modules</h4>
<p>In the security area, two recommended modules should be part of a Drupal installation.</p>
<p>The Security Review module (<a href="http://drupal.org/project/security_review" target="_blank">http://drupal.org/project/security_review</a>) inspects various aspects of a Drupal installation including file system permissions, user auditing, database and other errors, as well as things such as input formats allowed. This module is also useful in that the interactive results detail how to fix or remedy various issues that apply to the Drupal installation.</p>
<p>Secure Login (<a href="http://drupal.org/project/securelogin" target="_blank">http://drupal.org/project/securelogin</a>) as mentioned above is a critical plugin to keep the security of authenticated sessions and form submissions free from session hijacking.</p>
<p>If still on Drupal 6, making use of a phpass module addon (<a href="http://drupal.org/project/phpass" target="_blank">http://drupal.org/project/phpass</a>) will strengthen password hashes for users that are stored in the database.</p>
<h4>7. Backups</h4>
<p>Regular backups are a part of any system administration and that includes running and administering a Drupal web application. Two backups are required for Drupal: regular full database dumps and also regular snapshot backups of the entire Drupal directory. Should compromise occur, having the ability to roll back to a previous snapshot or compare files to a previous snapshot is invaluable. Creating either automated cron jobs to make backups or using a module such as Backup and Migrate (<a href="http://drupal.org/project/backup_migrate" target="_blank">http://drupal.org/project/backup_migrate</a>) is critical and should be part of the security administration for a Drupal installation.</p>
<h4>8. Scanning and Auditing</h4>
<p>Regular scanning of the Drupal site with web application scanners or vulnerability scanners is required today to be on top of security. At least monthly scanning at a minimum is a good interval if not more frequently. Many open source as well as commercial web application scanners are able to test sites for XSS and SQL injection which is very relevant to web applications such as Drupal.</p>
<h4>9. Operating System Updates and Logs</h4>
<p>Drupal security extends to operating system security, which is the host running the web server Apache as well as PHP. If Drupal is installed in a self-managed VPS or other similar installation, staying on top of OS security updates and patches are critical to ensure that the entire host is secure and free from compromise. Subscribe to various Linux distribution security update mailing lists or Twitter feeds to keep on top of any pending updates or security issues for the operating system that is hosting the Drupal installation.</p>
<p>Reviewing Apache or other operating system server logs daily is part of general security no matter what application or software is in use. Make use of logwatch or other automated log alert software to be on top of any trending patterns in logs from would-be attackers.</p>
<h4>Conclusions</h4>
<p>Drupal security is achievable by keeping on top of security updates for Drupal core and contributed modules as well as taking advantage of SSH and HTTPS options that are available. Most default Drupal installs provided by scripts in hosting companies do not have many of the above mentioned security notes installed or available, which leaves most Drupal users unknowingly connecting and managing their site via insecure protocols. Upgrading to Drupal 7 as soon as possible is strongly encouraged by this author for the many security benefits outlined. The problematic maintenance and upgrading of Drupal 6 is much improved in Drupal 7 which will help users to keep sites and code more up-to-date against today’s seemingly growing threat of attack against web applications. For a deeper look into Drupal and other web application security, check out the web application penetration testing course offered by the InfoSec Institute. </p>
<blockquote><p>
This guest post is written by Scott Miller, a security researcher for the <a href="http://resources.infosecinstitute.com/" title="infosecinstitute" target="_blank">InfoSec Institute</a> with experience in web application hacking, Linux security, and also network security.
</p></blockquote>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=VQL8g6kV8UY:QzjSmE4GDcg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=VQL8g6kV8UY:QzjSmE4GDcg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=VQL8g6kV8UY:QzjSmE4GDcg:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/VQL8g6kV8UY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/tips-and-tricks-for-improved-drupal-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/security/tips-and-tricks-for-improved-drupal-security/</feedburner:origLink></item>
		<item>
		<title>10 Tools for Designing Responsive websites</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/1y8H_NxK5ds/</link>
		<comments>http://www.codediesel.com/design/10-tools-for-designing-responsive-websites/#comments</comments>
		<pubDate>Sun, 12 May 2013 04:52:21 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[responsive]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3194</guid>
		<description><![CDATA[With a wide variety of devices available for viewing web content, responsive design has become a necessity rather than a feature of a website. Below are some frameworks and tools that will help you in designing advanced responsive websites for any viewing device. ZURB Foundation Definitely one of my favorite responsive frameworks. Now in version [...]]]></description>
				<content:encoded><![CDATA[<p>With a wide variety of devices available for viewing web content, responsive design has become a necessity rather than a feature of a website. Below are some frameworks and tools that will help you in designing advanced responsive websites for any viewing device.<br />
<span id="more-3194"></span></p>
<h4>ZURB Foundation</h4>
<p><a href="http://foundation.zurb.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/foundation-zurb-responsive-web-design.png" alt="foundation-zurb-responsive-web-design" width="300" height="53" class="aligncenter size-full wp-image-3206" /></a></p>
<p>Definitely one of my favorite responsive frameworks. Now in version 4, Foundation has now adopted a mobile first strategy. This means that now you can build for small devices first, and then as devices get larger and larger, layer in more complexity. The framework included predefined UI elements and over a dozen single page templates to kick-start your responsive design.</p>
<h4>Twitter Bootstrap</h4>
<p><a href="http://twitter.github.io/bootstrap/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/twitter-bootstrap.png" alt="twitter-bootstrap" width="300" height="53" class="aligncenter size-full wp-image-3208" /></a></p>
<p>Another widely used frontend framework for creating websites and web applications. Contains HTML and CSS-based design templates for typography, forms, buttons, charts, navigation and other interface components, as well as optional JavaScript extensions. Since version 2.0 it also supports responsive design. Both Foundation and Bootstrap allow you to customize the framework download depending on the components you require.</p>
<h4>GroundworkCSS</h4>
<p><a href="http://groundwork.sidereel.com/home.html"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/groundwork-css.png" alt="groundwork-css" width="300" height="53" class="aligncenter size-full wp-image-3213" /></a></p>
<p>Built from the ground up with the incredibly powerful CSS preprocessor Sass, GroundworkCSS offers some advanced responsive layout techniques. The framework features an incredibly flexible, nestable, fluid grid system and supports any columns in any fractional amount from halves to twelfths. The result is a framework that works for virtually any imaginable modern layout. GroundworkCSS comes with a large number of UI elements which makes the creation of web pages a breeze.</p>
<h4>xyCSS</h4>
<p><a href="http://xycss.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/xycss.png" alt="xycss" width="300" height="53" class="aligncenter size-full wp-image-3214" /></a></p>
<p>xy.css is a lightweight CSS template for creating semantic HTML5 designs on a responsive liquid matrix. At its heart, xy.css neutralizes rogue browser styles, combines horizontal and vertical grids, and provides a flexible template for responsive design. xy.css brings together the best CSS techniques from around the Web and integrates them into a single, powerful stylesheet template. The site itself ( xyCSS.com ) is built with WordPress, HTML5, CSS3 and of course xy.css. To help visualize the responsive, grid-based design, the site includes numerous on-page browser hints: current browser width, buttons for showing/hiding the grid, current @media rules.</p>
<h4>Centurion</h4>
<p><a href="http://jhough10.github.io/Centurion/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/centurion.png" alt="centurion" width="300" height="53" class="aligncenter size-full wp-image-3216" /></a></p>
<p>Built using SASS and CSS3 media queries, Centurion is a responsive web framework that scales with your device. No longer do you need to worry about the screen size of an iPhone or an Android tablet since Centurion does the work for you. The framework comes integrated with several JavaScript libraries, such as, jQuery, Coffeescript, Craydent and more. It includes a 960px grid (that scales down to 320px), can handle image scaling and has a navigation with desktop and mobile versions. There are also styles for CSS-only buttons and tables. The framework is easy to learn and customizable (thanks to SASS).</p>
<h4>Jetstrap for Bootstrap</h4>
<p><a href="https://www.jetstrap.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/jetstrap.png" alt="jetstrap" width="300" height="53" class="aligncenter size-full wp-image-3209" /></a></p>
<p>A web-based interface building tool for Twitter Bootstrap. Built for developers and designers, Jetstrap helps you get awesome websites up and running fast, with less work and digging through docs. Features a drag-and-drop GUI tools and components to create your responsive Bootstrap design. This is a subscription based service with a free account available if you need to try out the features before you buy.</p>
<h4>Layoutit</h4>
<p><a href="http://www.layoutit.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/layoutit.png" alt="layoutit" width="300" height="53" class="aligncenter size-full wp-image-3217" /></a></p>
<p>Like Jetstrap Layoutit helps you create your frontend code quickly with Bootstrap using a Drag &#038; Drop Web Interface Builder. It takes every element and component of Bootstrap to make your frontend coding easier without you needing to be an expert in javascript, html5 or css3. All the designs are Responsive and Fluid. Note that Layoutit is not a site-builder but a kind of a scaffolding to kick-start your front-end design.</p>
<h4>Pears</h4>
<p><a href="http://http://pea.rs/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/responsive-design-pears.png" alt="responsive-design-pears" width="300" height="53" class="aligncenter size-full wp-image-3210" /></a></p>
<p>Not directly related to responsive design, Pear enables you to collect, test, and experiment with interface pattern pairings of CSS &#038; HTML. Pears is an open source WordPress theme, enabling people like you to get your own pattern library up and running quickly. The WordPress theme allows you as a team to share common HTML/CSS design patterns.</p>
<h4>enquire.js</h4>
<p><a href="http://wicky.nillia.ms/enquire.js/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/enquire_js.png" alt="enquire_js" width="300" height="53" class="aligncenter size-full wp-image-3211" /></a></p>
<p>A lightweight, pure JavaScript library for responding to CSS media queries. In responsive design, CSS media queries can only take you so far. enquire.js allows you to harness media queries in JavaScript, giving you the tools to create more advanced responsive sites. More important, it does not have any dependencies, not even jQuery.</p>
<h4>Reverie</h4>
<p><a href="http://themefortress.com/reverie/"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/reverie.png" alt="reverie" width="300" height="53" class="aligncenter size-full wp-image-3212" /></a></p>
<p>A extremely versatile HTML5 WordPress framework based on ZURB&#8217;s Foundation. Reverie Framework inherits all the cool features from Foundation, and packs with several other interesting features to optimize the experience for WordPress and HTML5. Including customized output for WordPress menus and caption. Reverie utilizes Foundation&#8217;s grid to implement layouts. With the power of Foundation, Reverie uses media query to adjust for all kinds of devices, including phones, tablets and computers. Reverie is also optimized for iPhone and iPad</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=1y8H_NxK5ds:v6UUtdCVgbg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=1y8H_NxK5ds:v6UUtdCVgbg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=1y8H_NxK5ds:v6UUtdCVgbg:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/1y8H_NxK5ds" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/design/10-tools-for-designing-responsive-websites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/design/10-tools-for-designing-responsive-websites/</feedburner:origLink></item>
		<item>
		<title>Intercepting mouse events on an iPad</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/mc3APuTdM3Y/</link>
		<comments>http://www.codediesel.com/javascript/intercepting-mouse-events-on-an-ipad/#comments</comments>
		<pubDate>Fri, 10 May 2013 10:26:05 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ipad]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3200</guid>
		<description><![CDATA[In the last post we saw how we could easily work with mouse events on an iPad. Touchscreen devices like the iPad do not have a cursor, so the user cannot exactly move the mouse over an HTML element triggering a &#8216;mouseover&#8217; event. One of the readers requested on how we could use a different [...]]]></description>
				<content:encoded><![CDATA[<p>In the last post we saw how we could easily work with mouse events on an iPad. Touchscreen devices like the iPad do not have a cursor, so the user cannot exactly move the mouse over an HTML element triggering a &#8216;mouseover&#8217; event. One of the readers requested on how we could use a different interaction pattern on an iPad for a &#8216;mouseover&#8217; event than on a desktop browser. For example in the following web page code the <code>image-container</code> class is attached to images div which displays a preview link overlay on <code>mouseover</code>.<br />
<span id="more-3200"></span></p>

<div class="wp_codebox"><table><tr id="p320018"><td class="code" id="p3200code18"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.image-container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseover'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'image-info-active'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a href="http://www.codediesel.com/wp-content/uploads/2013/05/ipad-mouseover.png"><img src="http://www.codediesel.com/wp-content/uploads/2013/05/ipad-mouseover.png" alt="ipad-mouseover" width="431" height="180" class="aligncenter size-full wp-image-3202" /></a></p>
<p>Obviously this will not work exactly on an iPad like it would on a desktop browser. The overlay will be displayed on a single tap, but will not disappear till we tap another clickable element. One different interaction pattern for the above example is to trigger the overlay on a <code>touchstart</code> event and remove the overlay after some delay. The first step however is to detect if the site is being viewed on an iPad using the browser user-agent string.</p>

<div class="wp_codebox"><table><tr id="p320019"><td class="code" id="p3200code19"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> isiPad <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">userAgent</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/iPad/i</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Later we can run the appropriate code depending the viewing device.</p>

<div class="wp_codebox"><table><tr id="p320020"><td class="code" id="p3200code20"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isiPad<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.image-container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'touchstart'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'image-info-active'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2000</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.image-container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseover'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'image-info-active'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now on an iPad the above code will &#8216;fadeIn&#8217; the preview overlay once the image is touched and then &#8216;fadeOut&#8217; after a delay. Of course you could try some different interaction pattern to make better use of the touch capabilities of a tablet.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=mc3APuTdM3Y:YmVv6q3-loc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=mc3APuTdM3Y:YmVv6q3-loc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=mc3APuTdM3Y:YmVv6q3-loc:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/mc3APuTdM3Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/intercepting-mouse-events-on-an-ipad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/javascript/intercepting-mouse-events-on-an-ipad/</feedburner:origLink></item>
		<item>
		<title>Making ‘mouseover’ event work on an iPad</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/lAyjz-xxFVY/</link>
		<comments>http://www.codediesel.com/javascript/making-mouseover-event-work-on-an-ipad/#comments</comments>
		<pubDate>Tue, 07 May 2013 12:06:01 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ipad]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3203</guid>
		<description><![CDATA[Because of the way Safari on iOS creates events to emulate a mouse, some of your web page elements may not behave as expected on iOS. In particular, some elements that only use mouseover handlers need to be changed because iOS doesn’t recognize them as clickable elements, such as the div below. As the image-container [...]]]></description>
				<content:encoded><![CDATA[<p>Because of the way Safari on iOS creates events to emulate a mouse, some of your web page elements may not behave as expected on iOS. In particular, some elements that only use <code>mouseover</code> handlers need to be changed because iOS doesn’t recognize them as clickable elements, such as the div below. As the <code>image-container</code> div is not clickable in iOS, the corresponding <code>mouseover</code> event is not fired.<br />
<span id="more-3203"></span></p>

<div class="wp_codebox"><table><tr id="p320324"><td class="code" id="p3203code24"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image-container&quot;</span>&gt;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p320325"><td class="code" id="p3203code25"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.image-container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseover'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #006600; font-style: italic;">//...</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>On an iPad mouse events are delivered in the same order you&#8217;d expect in other web browsers. As illustrated below, if the user taps a nonclickable element, no events are generated. If the user taps a clickable element, events arrive in the following order: mouseover, mousemove, mousedown, mouseup, and click. The mouseout event occurs only if the user taps on another clickable item. </p>
<p><img src="http://www.codediesel.com/wp-content/uploads/2013/05/iossingletap.jpg" alt="iossingletap" width="365" height="375" class="aligncenter size-full wp-image-3205" style="border: none;" /></p>
<p>To make the div clickable one just needs to add a dummy <code>onclick</code> handler, so that Safari on iOS recognizes the div element as a clickable element. Now the <code>mouseover</code> event is fired on an iPad whenever the user taps the <code>image-container</code> div.</p>

<div class="wp_codebox"><table><tr id="p320326"><td class="code" id="p3203code26"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image-container&quot;</span> <span style="color: #000066;">onclick</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;void(0)&quot;</span>&gt;</span></pre></td></tr></table></div>

<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=lAyjz-xxFVY:n-ghCa0OrWY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=lAyjz-xxFVY:n-ghCa0OrWY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=lAyjz-xxFVY:n-ghCa0OrWY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/lAyjz-xxFVY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/making-mouseover-event-work-on-an-ipad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/javascript/making-mouseover-event-work-on-an-ipad/</feedburner:origLink></item>
		<item>
		<title>Efficiently Replicating RETS data to MySQL</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/BA486NQgXoI/</link>
		<comments>http://www.codediesel.com/data/efficiently-replicating-rets-data-to-mysql/#comments</comments>
		<pubDate>Thu, 02 May 2013 04:45:07 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[rets]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3196</guid>
		<description><![CDATA[A recent project of mine entailed replicating a RETS database on a local MySQL database server. The client had a new real-estate mobile search app in development and wanted to have a local copy of the RETS database for search queries instead of a remote RETS server. This approach has several advantages: Response times for [...]]]></description>
				<content:encoded><![CDATA[<p>A recent project of mine entailed replicating a <a href="http://www.reso.org/rets" title="RETS" target="_blank">RETS</a> database on a local MySQL database server. The client had a new real-estate mobile search app in development and wanted to have a local copy of the RETS database for search queries instead of a remote RETS server. This approach has several advantages:</p>
<ul>
<li>
Response times for accessing your local database are significantly faster than connecting to a remote RETS server for each request.
</li>
<li>
RETS servers requires that you query using certain combination of fields and also limits the number of fields you can search on. Using a local database would allow you to search on any field with any combination.
</li>
<li>
RETS servers also limit the time of day you’re allowed to access the RETS server and also restricts how much queries you can run per hour. You may also be limited to the number of records you can retrieve per query from a RETS server while a local database wouldn’t have that limit.
</li>
</ul>
<p><span id="more-3196"></span><br />
Replicating RETS data rather than using the live version is slightly complex, however. In order to replicate the RETS data into your own local database, a series of processes are needed in order to make sure the data you have is both updated and in sync with the server. Those processes typically include the following two major steps: Grabbing the entire database once, and running incremental updates to find changes or new records.</p>
<p>For this project I used the excellent <a href="https://github.com/troydavisson/PHRETS/wiki" title="PHRETS PHP RETS library" target="_blank">PHRETS</a> PHP library. PHRETS is a versatile library and allows you to communicate with a RETS server in an easy manner.</p>
<h4>Grabbing the complete database once.</h4>
<p>To kick start the replication we need to get the complete initial database from the RETS server. Once of the important field we will require is the <code>LastModifiedDateTime</code> field. This field instructs the RETS server to only return records that have been modified since the given time. For our purpose here this will require that we pass a very old <code>LastModifiedDateTime</code> for each query. The following for example is a query to get all the records for the city of &#8216;Anaheim&#8217; since 1 January 1980. Note the &#8216;LastModifiedDateTime&#8217; value.</p>

<div class="wp_codebox"><table><tr id="p319631"><td class="code" id="p3196code31"><pre class="text" style="font-family:monospace;">(City=|Anaheim), (Status=|A,C,E,H,I,O,P,S,W,X),
(LastModifiedDateTime=1980-01-01T00:00:00+)&quot;;</pre></td></tr></table></div>

<p>RETS database contains a set of six major metadata tables which we need to replicate on our server: History, Agent, Association, Office, Open House, and Property. Many of these also have corresponding images to go with. Downloading these images requires a separate query and can return multiple images for any single resource.</p>
<p>Your local database schema should always have an index on some main field, for example on &#8216;ListingRid&#8217; in case of &#8216;Property&#8217; table. This will ensure that no duplicate records are entered in our database.</p>
<h4>Keeping the data in sync</h4>
<p>Once we are through downloading the initial database, the next task is to run a regular update to keep the RETS server data in sync with our local server. For this a CRON job that runs on the hour is usually a standard option. The <code>LastModifiedDateTime</code> is again helpful here. Now we can run the same above query but with a &#8216;LastModifiedDateTime&#8217; that is adjusted with our CRON job. So if you run a CRON job every hour to query the RETS server, we can set the &#8216;LastModifiedDateTime&#8217; to a value that increments every hour. So for example the following will only fetch the records that have been modified since 3/5/2013 09:00:00am GMT.</p>

<div class="wp_codebox"><table><tr id="p319632"><td class="code" id="p3196code32"><pre class="text" style="font-family:monospace;">(City=|Anaheim), (Status=|A,C,E,H,I,O,P,S,W,X),
(LastModifiedDateTime=2013-03-05T09:00:00+)&quot;;</pre></td></tr></table></div>

<p>The next query that will run with the next CRON execution will be the following.</p>

<div class="wp_codebox"><table><tr id="p319633"><td class="code" id="p3196code33"><pre class="text" style="font-family:monospace;">(City=|Anaheim), (Status=|A,C,E,H,I,O,P,S,W,X),
(LastModifiedDateTime=2013-03-05T10:00:00+)&quot;;</pre></td></tr></table></div>

<p>It may happen that a duplicate record is found for some reason, most probably due to incorrect &#8216;LastModifiedDateTime&#8217; value. We need to take that into account while inserting records into our database as a duplicate record will through an error. I usually check to see if MySQL has encountered a &#8217;1062&#8242; error (Duplicate entry) and then update or skip that particular record, depending on the context.</p>

<div class="wp_codebox"><table><tr id="p319634"><td class="code" id="p3196code34"><pre class="mysql" style="font-family:monospace;"><span style="color: #009900;">if</span><span style="color: #FF00FF;">&#40;</span>mysql_errno<span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">==</span> <span style="color: #008080;">1062</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#123;</span>
   <span style="color: #808000; font-style: italic;">/* If duplicate record was found */</span>
   $sql <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;UPDATE property<span style="color: #008080; font-weight: bold;">_</span>table &quot;</span> . $subquery . <span style="color: #008000;">&quot; <span style="color: #004000; font-weight: bold;">\ </span>
   WHERE ListingRid = '{$record['ListingRid']}'&quot;</span><span style="color: #000033;">;</span>
<span style="color: #FF00FF;">&#125;</span></pre></td></tr></table></div>

<h4>Ensuring CRON job is executed on regular intervals</h4>
<p>Your RETS data will quickly be out of sync if your CRON script fails to run on a regular basis. One of the ways to avoid that is to create a new table in our local database that will have a update timestamp field; let us call it &#8216;lastupdate&#8217;. So every time a CRON script is run on the hour it will add a timestamp to the &#8216;lastupdate&#8217; field. So now all we have to do to make sure that the CRON script is executed on time is to check for the &#8216;lastupdate&#8217; field and ensure that the timestamp stored is no more than an hour old.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=BA486NQgXoI:pyXFpRmVKtA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=BA486NQgXoI:pyXFpRmVKtA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=BA486NQgXoI:pyXFpRmVKtA:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/BA486NQgXoI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/efficiently-replicating-rets-data-to-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/data/efficiently-replicating-rets-data-to-mysql/</feedburner:origLink></item>
		<item>
		<title>6 Essential JavaScript frameworks for building web apps</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/GZMZz0CDyGU/</link>
		<comments>http://www.codediesel.com/javascript/6-essential-javascript-frameworks-for-building-web-apps/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 07:37:13 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3184</guid>
		<description><![CDATA[Single Page Applications (SPA) are on the rise and with it various JavaScript frameworks. A decade back the notion of developing whole web applications in javascript would have sounded ludicrous. But now things are different. We now have many complex frameworks that enable you to easily develop web applications using nothing but JavaScript, even on [...]]]></description>
				<content:encoded><![CDATA[<p>Single Page Applications (SPA) are on the rise and with it various JavaScript frameworks. A decade back the notion of developing whole web applications in javascript would have sounded ludicrous. But now things are different. We now have many complex frameworks that enable you to easily develop web applications using nothing but JavaScript, even on the server side. Below are a few frameworks listed that have been loved by developers and some new ones that show real promise.<br />
<span id="more-3184"></span></p>
<h4>Backbone.js</h4>
<p><a href="http://backbonejs.org/"><img src="http://www.codediesel.com/wp-content/uploads/2013/04/backbone-300x53.png" alt="backbone" width="300" height="53" class="aligncenter size-medium wp-image-3185" /></a></p>
<p>Currently the numero uno JavaScript MVC framework. Designed for developing single-page web applications, and is based on the model–view–presenter (MVP) application design paradigm. Backbone was created by Jeremy Ashkenas, who is also known for CoffeeScript. One of the main feature of Backbone that sets it apart from other similar frameworks is its lightweight nature. Backbone.js enforces that all communication to the server should be done entirely through a RESTful API. The frameworks only hard dependency is underscore.js, a library of useful javascript utilities and functions.</p>
<h4>Ember.js</h4>
<p><a href="http://emberjs.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/04/ember.png" alt="ember" width="300" height="53" class="aligncenter size-full wp-image-3187" /></a></p>
<p>Ember.js is an application framework for building sophisticated browser applications. Ember.js (formerly Amber.js SproutCore 2.0) is one of the newest contenders. It is an attempt to extricate the core features from SproutCore 2.0 into a more compact modular framework suited for the web. If you want to build something that tries to tackle desktop-level application development for the web then EmberJS is for you.</p>
<p>The framework supports persistence, computed properties and has auto-updating (live) templates. It also should supports state management rather than the manual routing solution many other frameworks advocate. It also comes with extensive documentation ,templating and has scaffolding tools.</p>
<h4>Knockout js</h4>
<p><a href="http://knockoutjs.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/04/knockout.png" alt="knockout" width="300" height="53" class="aligncenter size-full wp-image-3189" /></a></p>
<p>Knockout is a standalone JavaScript implementation of the Model-View-View Model (MVVM) pattern with templates. Knockout includes the following features:</p>
<p>- Declarative bindings<br />
- Automatic UI refresh (when the data model&#8217;s state changes, the UI updates automatically)<br />
- Dependency tracking<br />
- Templating (using a native template engine)</p>
<h4>AngularJs</h4>
<p><a href="http://angularjs.org/"><img src="http://www.codediesel.com/wp-content/uploads/2013/04/angularjs.png" alt="angularjs" width="300" height="53" class="aligncenter size-full wp-image-3190" /></a></p>
<p>AngularJS is built around the belief that declarative programming (HTML) should be used for building UIs and wiring software components, while imperative programming (JavaScript, PHP etc.) is excellent for expressing business logic.  AngularJS lets you extend HTML vocabulary for your application to better serve dynamic content through two-way data-binding that allows for the automatic synchronization of models and views. As a result, AngularJS deemphasizes DOM manipulation. It is easy to build complex dynamic UIs with a clean underlying data model and declarative bindings using AngulsrJS</p>
<h4>Meteor</h4>
<p><a href="http://meteor.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/04/meteorjs.png" alt="meteorjs" width="300" height="53" class="aligncenter size-full wp-image-3188" /></a></p>
<p>Meteor is a new full-stack JavaScript framework, powered by Node.js. Meteor allows you to write your entire application in nothing but JavaScript; not just the client-side, but the server persistence layer as well, with every single API offered in one language. While the framework is yet to reach version 1.0, as long as development remains active you should absolutely investigate this new approach to writing applications.</p>
<h4>Express</h4>
<p><a href="http://expressjs.com/"><img src="http://www.codediesel.com/wp-content/uploads/2013/04/expressjs.png" alt="expressjs" width="300" height="53" class="aligncenter size-full wp-image-3191" /></a></p>
<p>Express is a light-weight web application framework for node.js to help create a MVC web app architecture on the server side. You can then use a database like mongodb with mongoose (for modeling) to provide a backend for your node.js app. Express basically helps you manage everything, from routes, to handling requests and views. Express was specifically inspired by sinatra</p>
<p>Out of the box, Express provides features such as routing, templating/view rendering , dynamic CSS support, middleware (via Connect), session management, logging, application settings, and a command line interface.</p>
<h4>Selecting the appropriate framework</h4>
<p>As with every other thing in life that offers multiple choices, selecting a good framework for your next project is not an easy thing. It depends on your particular web app requirement and the features the framework provides. Also, some frameworks require a steep learning curve and you would have to invest a sizable amount of your time. I would suggest you take a cursory look through the documentation of all the above frameworks to see which one suits your need. Also take a look at this article &#8211; <a href="http://coding.smashingmagazine.com/2012/07/27/journey-through-the-javascript-mvc-jungle/" title="http://coding.smashingmagazine.com/2012/07/27/journey-through-the-javascript-mvc-jungle/" target="_blank">Journey Through The JavaScript MVC Jungle</a> by Addy Osmani.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=GZMZz0CDyGU:3Epo917Li_E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=GZMZz0CDyGU:3Epo917Li_E:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=GZMZz0CDyGU:3Epo917Li_E:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/GZMZz0CDyGU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/6-essential-javascript-frameworks-for-building-web-apps/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/javascript/6-essential-javascript-frameworks-for-building-web-apps/</feedburner:origLink></item>
		<item>
		<title>Getting SEO page ranks for different providers</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/NgoLK7odwC8/</link>
		<comments>http://www.codediesel.com/php/getting-seo-page-ranks-for-different-providers/#comments</comments>
		<pubDate>Mon, 08 Apr 2013 13:54:52 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3180</guid>
		<description><![CDATA[Piwik is a Open source web analytics application that has a huge number of valuable functions related to SEO and other analytics stuff built-in. One such module is RankChecker. This module provides page rank information for Google, Dmoz and Alexa. With some modification to the original RankChecker.php we can use it in our own application [...]]]></description>
				<content:encoded><![CDATA[<p>Piwik is a Open source web analytics application that has a huge number of valuable functions related to SEO and other analytics stuff built-in. One such module is RankChecker. This module provides page rank information for Google, Dmoz and Alexa. With some modification to the original RankChecker.php we can use it in our own application (with appropriate license). The following is a example code for the same using RankChecker.<br />
<span id="more-3180"></span></p>

<div class="wp_codebox"><table><tr id="p318037"><td class="code" id="p3180code37"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RankChecker.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$rank</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SEO_RankChecker<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'www.wired.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Google PageRank : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$rank</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPageRank</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Alexa PageRank : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$rank</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAlexaRank</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Dmoz Entries: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$rank</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDmoz</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Google Indexed Pages : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$rank</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIndexedPagesGoogle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Bing Indexed Pages : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$rank</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIndexedPagesBing</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This will return the following.</p>

<div class="wp_codebox"><table><tr id="p318038"><td class="code" id="p3180code38"><pre class="text" style="font-family:monospace;">Google PageRank : 8
Alexa PageRank : 806
Dmoz Entries: 480
Google Indexed Pages : 367000
Bing Indexed Pages : 427000</pre></td></tr></table></div>

<p>The code files can be downloaded from below.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/check-rank">Download Code files</a><br />
<span>Downloads : 108  / File size : 2.9 kB</span>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=NgoLK7odwC8:NP364PplImo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=NgoLK7odwC8:NP364PplImo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=NgoLK7odwC8:NP364PplImo:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/NgoLK7odwC8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/getting-seo-page-ranks-for-different-providers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/php/getting-seo-page-ranks-for-different-providers/</feedburner:origLink></item>
		<item>
		<title>Splitting images to prevent image copying from web sites</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/vrmPNaQYpFI/</link>
		<comments>http://www.codediesel.com/php/splitting-images-to-prevent-image-copying-from-web-sites/#comments</comments>
		<pubDate>Sat, 06 Apr 2013 15:37:48 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[interface]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3176</guid>
		<description><![CDATA[Image plagiarism is one of the common issues faced by websites, specially by designers and photographers. Besides the technique of attaching a copyright text or a hidden watermark, the other most common method of preventing casual copying of images from websites is by disabling right-click using JavaScript. Another scheme I recently found uses a method [...]]]></description>
				<content:encoded><![CDATA[<p>Image plagiarism is one of the common issues faced by websites, specially by designers and photographers. Besides the technique of attaching a copyright text or a hidden watermark, the other most common method of preventing casual copying of images from websites is by disabling right-click using JavaScript. Another scheme I recently found uses a method wherein the image is split into three parts and then displayed on the page. So whenever the user tries to save the image he gets three different parts of the image rather than a single image. This prevents casual copying of images from web pages. Of course, this is not a fool-proof method, and with some workaround one is able to create the original image but with some extra effort. This method can also be useful to prevent automated bots from easily downloading your images.<br />
<span id="more-3176"></span><br />
I&#8217;ve attached a small code that will split an image into 3 equal parts which can then be added to the webpage. The following is an example code that relies on the &#8216;class.imagesplitter.php&#8217; class to accomplish the task. Split images will be appended with the part number at the end.</p>
<pre>
sample-image-0.jpg
sample-image-1.jpg
sample-image-2.jpg
</pre>

<div class="wp_codebox"><table><tr id="p317642"><td class="code" id="p3176code42"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./class.imagesplitter.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$splitter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ImageSplitter<span style="color: #339933;">;</span>
<span style="color: #DD1144; font-style: normal;">/* IMAGETYPE_GIF for gif images
   IMAGETYPE_JPEG for jpg images
 */</span>
<span style="color: #000088;">$splitter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">outputType</span> <span style="color: #339933;">=</span> IMAGETYPE_JPEG<span style="color: #339933;">;</span>
<span style="color: #000088;">$splitter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sample-image.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$splitter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Split</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><a href="http://www.codediesel.com/wp-content/uploads/2013/04/image-splitter.png"><img src="http://www.codediesel.com/wp-content/uploads/2013/04/image-splitter.png" alt="image-splitter" width="488" height="231" class="aligncenter size-full wp-image-3179" /></a></p>
<p>The code supports 3 image types &#8211; gif, jpg and png. Use <code>IMAGETYPE_JPEG</code> for jpg images, <code>IMAGETYPE_GIF</code> for gif images. The default format is png when no &#8216;outputType&#8217; is set. To combine the images to display as a single image on a page you will need something like the following.</p>

<div class="wp_codebox"><table><tr id="p317643"><td class="code" id="p3176code43"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;iparts&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sample-image-0.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sample-image-1.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sample-image-2.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>The CSS for the above is given below. This is to ensure that no visible gap is displayed between the different image parts and is shown as a single whole.</p>

<div class="wp_codebox"><table><tr id="p317644"><td class="code" id="p3176code44"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.iparts</span> img <span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> 
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h4>Cons of the above method</h4>
<p>The obvious drawback is that it takes some extra effort. The other is that for each image split there are two additional resource requests by the browser. So if you have 3 images on your webpage using this method, the browser will have to make a total of 9 requests to the server instead of the original 3. In view of the above points, the method should only be considered if you are seriously interested in protecting your image assets. You could for example only use it while displaying larger versions of your images and not for smaller previews.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/image-splitter">Download Code files</a><br />
<span>Downloads : 73  / File size : 32.2 kB</span>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=vrmPNaQYpFI:9ZgfF4_PwIw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=vrmPNaQYpFI:9ZgfF4_PwIw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=vrmPNaQYpFI:9ZgfF4_PwIw:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/vrmPNaQYpFI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/splitting-images-to-prevent-image-copying-from-web-sites/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/php/splitting-images-to-prevent-image-copying-from-web-sites/</feedburner:origLink></item>
		<item>
		<title>WordPress, “You do not have sufficient permissions to access this page”</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/VSnERCt2fGc/</link>
		<comments>http://www.codediesel.com/wordpress/wordpress-you-do-not-have-sufficient-permissions-to-access-this-page/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 11:01:26 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3168</guid>
		<description><![CDATA[WordPress upgrades is a task most users do on a frequent basis,and most of the time it works flawlessly. But once in a while something goes wrong and WordPress doesn&#8217;t behave the way we expect. The most common complaint I see is the following error being thrown during wp-admin login after a WordPress database upgrade. [...]]]></description>
				<content:encoded><![CDATA[<p>WordPress upgrades is a task most users do on a frequent basis,and most of the time it works flawlessly. But once in a while something goes wrong and WordPress doesn&#8217;t behave the way we expect. The most common complaint I see is the following error being thrown during wp-admin login after a WordPress database upgrade.</p>
<blockquote><p>&#8220;You do not have sufficient permissions to access this page&#8221;</p></blockquote>
<p>This innocuous message however is the source of many a wasted hours. Although there could be many reasons for the above message, the one I most often see cited is the inconsistency between WordPress prefix  for the following values:<br />
<span id="more-3168"></span><br />
<strong>Table &#8211; Column &#8211; Value</strong><br />
wp_options &#8211; option_name &#8211; wp_user_roles<br />
wp_usermeta &#8211; meta_key &#8211; wp_capabilities<br />
wp_usermeta &#8211; meta_key &#8211; wp_user_level</p>
<p>So if you have a value like &#8216;wpress_capabilities&#8217; and the other &#8216;wp_user_roles&#8217; (notice the different prefixes), the error is thrown. In many cases the value itself is missing from the table after a database upgrade. In a recent case, after a WordPress database upgrade the <code>wp_user_roles</code> option name was missing from the &#8216;wp_options&#8217; table, which disallowed admin login and displayed the above message. The solution was to add the option name manually to the table with the option value taken from a old database backup. If you do not have a database backup (God forbid) you can use the value from a fresh WordPress installation.</p>
<p>To quickly check if all the above values exist with also the same prefix, you can use the following simple query.</p>

<div class="wp_codebox"><table><tr id="p316847"><td class="code" id="p3168code47"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> option_name <span style="color: #993333; font-weight: bold;">AS</span> A <span style="color: #993333; font-weight: bold;">FROM</span> wp_options <span style="color: #993333; font-weight: bold;">WHERE</span> option_name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%_user_roles'</span>
<span style="color: #993333; font-weight: bold;">UNION</span> 
<span style="color: #993333; font-weight: bold;">SELECT</span> meta_key <span style="color: #993333; font-weight: bold;">AS</span> A <span style="color: #993333; font-weight: bold;">FROM</span> wp_usermeta <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%_capabilities'</span>
<span style="color: #993333; font-weight: bold;">UNION</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> meta_key <span style="color: #993333; font-weight: bold;">AS</span> A <span style="color: #993333; font-weight: bold;">FROM</span> wp_usermeta <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%_user_level'</span></pre></td></tr></table></div>

<p>Which will return:</p>

<div class="wp_codebox"><table><tr id="p316848"><td class="code" id="p3168code48"><pre class="text" style="font-family:monospace;">A
wp_user_roles
wp_capabilities
wp_user_level</pre></td></tr></table></div>

<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=VSnERCt2fGc:DkajN8ij0Wg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=VSnERCt2fGc:DkajN8ij0Wg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=VSnERCt2fGc:DkajN8ij0Wg:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/VSnERCt2fGc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/wordpress/wordpress-you-do-not-have-sufficient-permissions-to-access-this-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/wordpress/wordpress-you-do-not-have-sufficient-permissions-to-access-this-page/</feedburner:origLink></item>
		<item>
		<title>Storing images into a database – resolving a contentious matter</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/aibSeBwNDFU/</link>
		<comments>http://www.codediesel.com/mysql/storing-images-into-a-database/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 09:19:52 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=3166</guid>
		<description><![CDATA[As with many other databases, MySQL provide a BLOB type that allows you to store binary data &#8211; images, wav files, videos etc. A frequent question developers have is regarding to storing images in the database. There is much discussion and argument with no final say on the issue. In one of my recent project [...]]]></description>
				<content:encoded><![CDATA[<p>As with many other databases, MySQL provide a BLOB type that allows you to store binary data &#8211; images, wav files, videos etc. A frequent question developers have is regarding to storing images in the database. There is much discussion and argument with no final say on the issue. In one of my recent project the same issue was raised; the client and myself discussing the benefits and drawback of storing the images into a database. The project needed storing around 50,000 images, so it was important to get the question resolved satisfactorily.</p>
<p>After much deliberation we settled on using the file system. The major factor in the decision was that we needed the database and images decoupled as we would be having multiple databases using the same set of images. Also in the future it was possible that we would require some processing done on the images (cropping, resizing), which would be tedious and taxing if the images where stored in the database. So in light of these factors we found using a filesystem a suitable solution.<br />
<span id="more-3166"></span></p>
<h4>So should you store images in to a database?</h4>
<p>That will depend on the actual purpose of the application, so the question is purely subjective and will have different answers depending on the situation. </p>
<p>Deciding where to store images is a matter of trade-offs. There are advantages and disadvantages regardless of whether you store images in the database or in the filesystem. The ever-so-useful <a href="http://www.amazon.com/MySQL-Cookbook-Paul-DuBois/dp/059652708X/" title="MySQL Cookbook" target="_blank">MySQL Cookbook</a> has the following to say on the topic.</p>
<p><strong>1. </strong>Storing images in a database table bloats the table. With a lot of images, you&#8217;re more likely to approach any limits your operating system places on table size. On the other hand, if you store images in the filesystem, directory lookups may become slow. To avoid this, you may be able to implement some kind of hierarchical storage or use a filesystem that has good lookup performance for large directories (such as the Reiser filesystem that is available on Linux).</p>
<p><strong>2. </strong>Using a database centralizes storage for images that are used across multiple web servers on different hosts. Images stored in the filesystem must be stored locally on the web server host. In a multiple-host situation, that means you must replicate the set of images to the filesystem of each host. If you store the images in MySQL, only one copy of the images is required because each web server can get the images from the same database server.</p>
<p><strong>3. </strong>When images are stored in the filesystem, they constitute in essence a foreign key. Image manipulation requires two operations: one in the database and one in the filesystem. This in turn means that if you require transactional behavior, it&#8217;s more difficult to implementnot only do you have two operations, but they take place in different domains. Storing images in the database is simpler because adding, updating, or removing an image requires only a single row operation. It becomes unnecessary to make sure the image table and the filesystem remain in synchrony.</p>
<p><strong>4. </strong>It can be faster to serve images over the Web from the filesystem than from the database, because the web server itself opens the file, reads it, and writes it to the client. Images stored in the database must be read and written twice. First, the MySQL server reads the image from the database and writes it to your web script. Then the script reads the image and writes it to the client.</p>
<p><strong>5. </strong>Images stored in the filesystem can be referred to directly in web pages by means of <img> tag links that point to the image files. Images stored in MySQL must be served by a script that retrieves an image and sends it to the client. However, even if images are stored in the filesystem and accessible to the web server, you might still want to serve them through a script. This would be appropriate if you need to account for the number of times you serve each image (such as for banner ad displays where you charge customers by the number of ad impressions) or if you want to select an image at request time (such as when you pick an ad at random).</p>
<p><strong>6. </strong>If you store images in the database, you need to use a data type such as a BLOB. This is a variable length type, so the table itself will have variable-length rows. For the MyISAM storage engine, operations on fixed-length rows are often quicker, so you may gain some table lookup speed by storing images in the filesystem and using fixed-length types for the columns in the image table.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Code-diesel?a=aibSeBwNDFU:dwVIDLn29mY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Code-diesel?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Code-diesel?a=aibSeBwNDFU:dwVIDLn29mY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Code-diesel?i=aibSeBwNDFU:dwVIDLn29mY:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Code-diesel/~4/aibSeBwNDFU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/mysql/storing-images-into-a-database/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.codediesel.com/mysql/storing-images-into-a-database/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 1.456 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-24 15:03:59 -->
