<?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>Luutaa Technologies</title>
	<atom:link href="http://blog.luutaa.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.luutaa.com</link>
	<description>Where Design Meets Code</description>
	<lastBuildDate>Sun, 13 Nov 2011 06:44:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Prevent user from deleting categories in wordpress</title>
		<link>http://blog.luutaa.com/wordpress/prevent-user-from-deleting-categories-in-wordpress/</link>
		<comments>http://blog.luutaa.com/wordpress/prevent-user-from-deleting-categories-in-wordpress/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 12:04:09 +0000</pubDate>
		<dc:creator>murtaza</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.luutaa.com/?p=118</guid>
		<description><![CDATA[WordPress is like a heaven for the programmer and for designer both. With the introduction of wordpress, blogging moves to next level . All of us know that wordpress is highly customizable and in any manner but there are several things which becomes pain for the beginner developer or wordpress programmer. One of the reason for the pain is, &#8220;Categories&#8221;. Categories helps us in grouping the posts so it is easy for manage and beneficial [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is like a heaven for the programmer and for designer both. With the introduction of wordpress, blogging moves to next level . All of us know that wordpress is highly customizable and in any manner but there are several things which becomes pain for the beginner developer or wordpress programmer.</p>
<p>One of the reason for the pain is, &#8220;Categories&#8221;. Categories helps us in grouping the posts so it is easy for manage and beneficial for reader and for programmer also. But sometimes it happens that programmer creates a category which is treated as top level category , which we dont want to delete anyhow , so as to maintain the smooth functionality of our blog / site,  as we can  create custom files for categories on the basis of category slug / ID and so on.</p>
<p>So overcome the fear of category deletion , we can write some piece of code in our theme&#8217;s <em>functions.php</em> file , which will helps us to overcome the fear of category deletion .</p>
<p>The piece of code for preventing the category deletion is provided below :</p>
<pre class="brush:php">&lt;?php
// pass IDs of categories to block as arra</pre>
<pre class="brush:php">$cat_array = array(4, 3, 5); // pass the id's of category which you want to prevent from deletion
return blockCategoriesDeletionPlugin::bootstrap( $cat_array ); 

class blockCategoriesDeletionPlugin {
	/**
	* @var blockCategoriesDeletionPlugin
	*/
	static $instance;
	private $categoryIDs = array();
	public static function bootstrap(array $categoryIDs) {
		if (null===self::$instance) {
			self::$instance = new self($categoryIDs);
		} else {
			throw new BadFunctionCallException(sprintf('Plugin %s already instantiated', __CLASS__));
		}
		return self::$instance;
	}

	private function isCategoryDeleteRequest() {
		$notAnCategoryDeleteRequest =
		empty($_REQUEST['taxonomy'])
		|| empty($_REQUEST['action'])
		|| $_REQUEST['taxonomy'] !== 'category'
		|| !( $_REQUEST['action'] === 'delete' || $_REQUEST['action'] === 'delete-tag');

		$isCategoryDeleteRequest = !$notAnCategoryDeleteRequest;

		return $isCategoryDeleteRequest;
	}

	public function __construct(array $categoryIDs) {
		$this-&gt;categoryIDs = $categoryIDs;
		if ($this-&gt;isCategoryDeleteRequest()) {
			add_filter('check_admin_referer', array($this, 'check_referrer'), 10, 2);
			add_filter('check_ajax_referer', array($this, 'check_referrer'), 10, 2);
		}
	}

	private function blockCategoryID($categoryID) {
		return in_array($categoryID, $this-&gt;categoryIDs);
	}

	/**
	* @-wp-hook check_admin_referer
	* @-wp-hook check_ajax_referer
	*/

	public function check_referrer($action, $result) {

		if (!$this-&gt;isCategoryDeleteRequest()) {
			return;
		}

		$prefix = 'delete-tag_';
		if (strpos($action, $prefix) !== 0)
			return;

		$actionID = substr($action, strlen($prefix));
		$categoryID = max(0, (int) $actionID);

		if ($this-&gt;blockCategoryID($categoryID)) {
			wp_die(__('This category is blocked for deletion.'));
		}
	}
}
?&gt;</pre>
<p>As you can see , you just have to pass the array of category id&#8217;s in the first line and then no one is able to delete the defined category from wp-admin .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.luutaa.com/wordpress/prevent-user-from-deleting-categories-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get thumbnail image src attribute in wordpress</title>
		<link>http://blog.luutaa.com/wordpress/how-to-get-thumbnail-image-src-attribute-in-wordpress/</link>
		<comments>http://blog.luutaa.com/wordpress/how-to-get-thumbnail-image-src-attribute-in-wordpress/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 06:20:30 +0000</pubDate>
		<dc:creator>murtaza</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.luutaa.com/?p=113</guid>
		<description><![CDATA[Wordpress introduced Post Thumbnail feature in Version 2.9.  Thumbnail is an image that is chosen as the representative image for Posts, Pages or Custom Post Types.  This is especially useful for "magazine-style" themes where each post has an image according to wordpress .]]></description>
			<content:encoded><![CDATA[<p><strong>WordPress </strong> introduced <a title="Post Thumbnail" href="http://codex.wordpress.org/Post_Thumbnails" target="_blank">Post Thumbnail</a> feature in Version 2.9.  Thumbnail is an image that is chosen as the representative image for  Posts, Pages or Custom Post Types.  This is especially useful for &#8220;magazine-style&#8221; themes where  each post has an image according to wordpress .</p>
<p>To enable post thumbnail write this code in your theme functions.php file</p>
<pre class="brush:php">if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 150, 150, true ); //default Post Thumbnail dimensions (cropped)

    // additional image sizes
    // delete the next line if you do not need additional image sizes
    add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
}</pre>
<p>More detailed information can be found at <strong>WordPress</strong> codex for <a title="Post Thumbnail" href="http://codex.wordpress.org/Post_Thumbnails" target="_blank">Post Thumbnail</a>.</p>
<p>Next, important thing is how to use post thumbnail in wordpress loop ? It is not a complex thing . We have to just check whether post thumbnail for current post exists or not, and if it exists display it .</p>
<p>Code for post thumbnail display :</p>
<pre class="brush:php">&lt;?php 

$default_attr = array(
		'src'	=&gt; $src,
		'class'	=&gt; "attachment-$size",
		'alt'	=&gt; trim(strip_tags( wp_postmeta-&gt;_wp_attachment_image_alt )),
		'title'	=&gt; trim(strip_tags( $attachment-&gt;post_title )),
		);

if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    the_post_thumbnail($image_size , $default_attr);
} 

?&gt;</pre>
<p>As you can see first we checked whether the post thumbnail exists or not with</p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; white-space: pre;">&lt;?php</span></p>
<pre class="brush:php">if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
   // write code for display here
}</pre>
<pre class="brush:php">?&gt;</pre>
<p>then, to display the post thumbnail we have to write</p>
<pre class="brush:applescript">&lt;?php
the_post_thumbnail($image_size , $default_attr);
?&gt;</pre>
<p>In the above code first attribute is image size which we can set in our functions.php.</p>
<p>Another attribute is the array of attributes like image class, alt tag,  title tag and src.</p>
<p>The only problem with this function is that it echo&#8217;s the whole html code for post thumbnail wrapped in &lt;img /&gt; .</p>
<p>So it is very difficult to get only the src of the post thumbnail. But as usual there is a way to get only the src of thumbnail image.</p>
<p>just write a line of code and you will get in return the array containing three values</p>
<ul>
<li>thumbnail src</li>
<li>thumbnail width</li>
<li>thumbnail height</li>
</ul>
<p>so just write</p>
<pre class="brush:php">&lt;?php
$thumbnail = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post-&gt;ID ), $image_size);
?&gt;</pre>
<p>this single line of code gives you the array in return if post thumbnail is available.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>I hope this article gave you some insight into how to use get the post thumbnail src in wordpress. If you have any questions, feel free to ask them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.luutaa.com/wordpress/how-to-get-thumbnail-image-src-attribute-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to protect your bandwidth by htaccess</title>
		<link>http://blog.luutaa.com/uncategorized/how-to-protect-your-bandwidth-by-htaccess/</link>
		<comments>http://blog.luutaa.com/uncategorized/how-to-protect-your-bandwidth-by-htaccess/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 15:54:55 +0000</pubDate>
		<dc:creator>achint</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://blog.luutaa.com/?p=106</guid>
		<description><![CDATA[Many bloggers, webmasters copy paste the resource URLs linking directly to non-html objects not on one own&#8217;s server, such as images, .js files etc. The victim&#8217;s server in this case is robbed of bandwidth (and in turn money) as the violator enjoys showing content without having to pay for its deliverance. The most common practice of hot linking pertains to another site&#8217;s images. The best way to stop hot linking is to have your images [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Many bloggers, webmasters copy paste the resource URLs linking directly to non-html  objects not on one own&#8217;s server, such as images, .js files etc. The  victim&#8217;s server in this case is robbed of bandwidth (and in turn money)  as the violator enjoys showing content without having to pay for its  deliverance. The most common practice of hot linking pertains to another  site&#8217;s images.</strong></p>
<p>The best way to stop hot linking is to have your images be placed in a  seperate folder (not the same folder as html files) and put a .htaccess  file in it.</p>
<p>Copy this text below, make the changes to show your domain info, and  paste it into notepad. Name this file .htaccess and place in in all your  images folders. Be sure to upload in ASCII mode or the .htaccess file  will not work.</p>
<blockquote>
<pre>
<pre>RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]</pre>
</pre>
</blockquote>
<p>Be sure to replace &#8220;mydomain.com&#8221; with your own. The above code causes a  broken image to be displayed when its hot linked. You can have an image  display for those who try to hot link. You can have an image of your  choice be displayed for those attempting to steal bandwidth. The code  for this is:</p>
<blockquote>
<pre>
<pre>RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/notallowed.gif [R,L]</pre>
</pre>
</blockquote>
<p>The first line tells Apache to turn on the MOD Rewite.<br />
The next two lines you change to your address (either with, and without the www. as well as your IP).<br />
The last line is where you would like the link from the site trying to  download from their pages to be redirected. This way if some one links  directly to your &#8220;coolpicture.jpg&#8221; from their website, instead of seeing  your cool picture the user will see a picture that you decide to show.  Make the picture be something the user will not want to see and get the  message across that he is a bandwidth stealer. After the user sees that  the &#8220;hot linking&#8221; isn&#8217;t working, the user will change his links.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.luutaa.com/uncategorized/how-to-protect-your-bandwidth-by-htaccess/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Ruby on Rails 3 on Windows</title>
		<link>http://blog.luutaa.com/ruby-on-rails/installing-ruby-on-rails-3-on-windows/</link>
		<comments>http://blog.luutaa.com/ruby-on-rails/installing-ruby-on-rails-3-on-windows/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 03:42:53 +0000</pubDate>
		<dc:creator>achint</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.luutaa.com/?p=97</guid>
		<description><![CDATA[This post helps you Installing ruby on rails 3, on windows platform. So without wasting your time, here we go. Download the latest stable release of ruby. ( In our case we are taking Ruby 1.9.3 &#38; Rails 3 ) Install it like any other program you do. Open command prompt &#38; navigate to ruby &#62; in directory &#38; run following command to check version &#62; ruby &#8211;version it should output something like this ruby [...]]]></description>
			<content:encoded><![CDATA[<p>This post helps you Installing ruby on rails 3, on windows platform. So without wasting your time, here we go.</p>
<ol>
<li><a title="Download Ruby" href="http://rubyonrails.org/download" target="_blank">Download </a>the latest stable release of ruby. ( In our case we are taking Ruby 1.9.3 &amp; Rails 3 )</li>
<li>Install it like any other program you do.</li>
<li>Open command prompt &amp; navigate to ruby &gt; in directory &amp; run following command to check version<br />
<strong>&gt; ruby &#8211;version</strong><br />
it should output something like this<br />
<span style="color: #808080">ruby 1.9.2p290 (2011-07-09) [i386-mingw32]</span>Now run following to update ruby &amp; then installing gemcutter<br />
&gt; <strong>gem update &#8211;system<br />
&gt; gem sources -a http://gemcutter.org</strong></p>
<p><strong> </strong><strong> </strong>Now time to install Rails. Run following command.<br />
&gt; <strong>gem install rails</strong><br />
<span style="color: #808080">after installation, it will show a message &#8216;Successfully installed rails-3.0 &#8216;</span></p>
<p>you can check the rails version by following command<br />
&gt; <strong>rails &#8211;v</strong></p>
<p><strong> </strong>Now, lets create your first application after that we can test it in browser. To create a new application run this command.<br />
&gt; <strong>rails new <span style="color: #339966">yourappname</span></strong><br />
<span style="color: #808080">this will create all directories needed by your application &amp; will setup all configuration files as well. Under bin directory (where you are right now), you can see a new folder with <strong>yourappname</strong></span></p>
<p>Now, navigate to that app folder just created and run following command.<br />
&gt; <strong>bundle install</strong></p>
<p>Now the final step. Starting the rails server<br />
&gt; <strong>rails server</strong><br />
when you run this command. It will show some output like this.<br />
=&gt; Booting WEBrick<br />
=&gt; Rails 3.0.10 application starting in development on <a title="Check if Rails Server Running Now" href="http://localhost:3000/" target="_blank">http://0.0.0.0:3000</a><br />
=&gt; Call with -d to detach<br />
=&gt; Ctrl-C to shutdown server<br />
[2011-08-29 08:56:17] INFO  WEBrick 1.3.1<br />
[2011-08-29 08:56:17] INFO  ruby 1.9.2 (2011-07-09) [i386-mingw32]<br />
[2011-08-29 08:56:17] INFO  WEBrick::HTTPServer#start: pid=4000 port=3000</p>
<p>Now to test your server running, open this in your browser.<br />
<strong>http://localhost:3000/</strong></li>
</ol>
<p><strong><a href="http://blog.luutaa.com/wp-content/uploads/rails-running.jpg"><img class="aligncenter size-full wp-image-100" src="http://blog.luutaa.com/wp-content/uploads/rails-running.jpg" alt="" width="600" height="336" /></a><a href="http://blog.luutaa.com/wp-content/uploads/200x200.png"><br />
</a><br />
</strong></p>
<ol></ol>
<div style="width: 1px;height: 1px;overflow: hidden">DS.&#8217;home&#8217;.DS.&#8217;<strong>mycake</strong>&#8216;</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.luutaa.com/ruby-on-rails/installing-ruby-on-rails-3-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your Website Facebook Ready</title>
		<link>http://blog.luutaa.com/facebook-development/make-your-website-facebook-ready/</link>
		<comments>http://blog.luutaa.com/facebook-development/make-your-website-facebook-ready/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 17:38:40 +0000</pubDate>
		<dc:creator>achint</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Web Marketing]]></category>

		<guid isPermaLink="false">http://blog.luutaa.com/?p=79</guid>
		<description><![CDATA[We see the popular facebook like button on most of the websites. We know when someone clicks on like button, it instantly gets posted on user&#8217;s wall with a backlink and some other information. Have you ever seen closely how facebook link sharing script extracts information about your website to show on website? Lets investigate this minute, but important fact which can make a lot difference in what gets posted on facebook when someone clicks [...]]]></description>
			<content:encoded><![CDATA[<p>We see the popular facebook like button on most of the websites. We know when someone clicks on like button, it instantly gets posted on user&#8217;s wall with a backlink and some other information.</p>
<p>Have you ever seen closely how facebook link sharing script extracts information about your website to show on website? Lets investigate this minute, but important fact which can make a lot difference in what gets posted on facebook when someone clicks &#8216;like&#8217; button.</p>
<div id="attachment_88" class="wp-caption aligncenter" style="width: 597px"><a href="http://blog.luutaa.com/wp-content/uploads/open-graph.png"><img class="size-full wp-image-88" title="open-graph" src="http://blog.luutaa.com/wp-content/uploads/open-graph.png" alt="How Facebook Like Button Works" width="587" height="157" /></a><p class="wp-caption-text">How Facebook Like Button Works</p></div>
<p>By default, facebook extracts &#8216;Title Tag&#8217;, Meta Tags Especially, &#8216;description&#8217; tag for Title &amp; Description. For image, it searched for images on website &amp; picks one with default (no choice like we see while sharing link on wall).</p>
<p>We can actually control what information is shared on Facebook. Isn&#8217;t that great? With the Help of Facebook OG (Open Graph) Tags in Header of Page, we can predetermine the format.</p>
<p>Here are simple Steps for the same.</p>
<ol>
<li>Make Changes in HTML Tag as mentioned here. <a href="http://developers.facebook.com/docs/opengraph/" target="_blank">Facebook Open Graph </a></li>
<li>Create the OG Meta Tags as Mentioned Below</li>
</ol>
<p>The Open Graph protocol defines four required properties:</p>
<ul>
<li><code>og:title</code> &#8211; The title of your object as it should appear within the graph, e.g., &#8220;The Rock&#8221;.</li>
<li><code>og:type</code> &#8211; The type of your object, e.g., &#8220;movie&#8221;. See the <a href="http://developers.facebook.com/docs/opengraph/#types">complete list of supported types</a>.</li>
<li><code>og:image</code> &#8211; An image URL which should represent your object within the graph. The image must be at least 50px by 50px and have a maximum aspect ratio of 3:1. We support PNG, JPEG and GIF formats. You may include multiple <code>og:image</code> tags to associate multiple images with your page.</li>
<li><code>og:url</code> &#8211; The canonical URL of your object that will be used as its permanent ID in the graph, e.g., <code>http://www.yoursite.com/</code>.</li>
</ul>
<p>In addition, we&#8217;ve extended the basic meta data to add two required fields to connect your webpage with Facebook:</p>
<ul>
<li><code>og:site_name</code> &#8211; A human-readable name for your site, e.g., &#8220;Luutaa Technologies&#8221;.</li>
<li><code>fb:admins</code> or <code>fb:app_id</code> &#8211; A comma-separated list of either Facebook user IDs or a Facebook Platform application ID that administers this page. It is valid to include both <code>fb:admins</code> and <code>fb:app_id</code> on your page.</li>
</ul>
<p>At Last You can Check if OG Tags are working properly using this <a title="Facebook URL Checker" href="http://developers.facebook.com/tools/lint" target="_blank">Facebook URL Lint</a></p>
<p><strong>This small trick is very helpful in makes your site look good while its shared on Facebook</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.luutaa.com/facebook-development/make-your-website-facebook-ready/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mod URL Rewrite</title>
		<link>http://blog.luutaa.com/php/57/</link>
		<comments>http://blog.luutaa.com/php/57/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 07:47:50 +0000</pubDate>
		<dc:creator>murtaza</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.luutaa.com/?p=57</guid>
		<description><![CDATA[What is Mod URL Rewrite&#8230; A basic understanding? Mod URL Rewrite mean to a.) A fancy URL. b.) A URL that is Search Engine Friendly. C.) A URL that is user friendly too. So, Mod URL Rewrite means to create a fancy web URL that is User and&#160;Search Engine Friendly too. Example: Original URL www.yourwebsite.com/home.php Fancy URL www.yourwebsite.com/myhome Another Example: Original URL www.yourwebsite.com/post.php?year=2011&#38;month=3 Fancy URL www.yourwebsite.com/post/2011/3 Modification from original URL to a Fancy URL is [...]]]></description>
			<content:encoded><![CDATA[<p><b>What is Mod URL Rewrite&#8230; A basic understanding?</b></p>
<p>Mod URL Rewrite mean to</p>
<p>a.) A fancy URL.</p>
<p>b.) A URL that is Search Engine Friendly.</p>
<p>C.) A URL that is user friendly too.</p>
<p>So, Mod URL Rewrite means to create a fancy web URL that is User and&nbsp;Search Engine Friendly too.</p>
<p><b>Example:</b></p>
<p>Original URL</p>
<pre>www.yourwebsite.com/home.php</pre>
<p>Fancy URL</p>
<pre>www.yourwebsite.com/myhome</pre>
<p><b>Another Example:</b></p>
<p>Original URL</p>
<pre>www.yourwebsite.com/post.php?year=2011&amp;month=3</pre>
<p>Fancy URL</p>
<pre>www.yourwebsite.com/post/2011/3</pre>
<p>Modification from original URL to a Fancy URL is done by <b>Rewrite Engine</b>.</p>
<p>Pros and Cons of Using Mod URL Rewrite:</p>
<p><b>Pros:</b></p>
<p>1.) A clean and fancy url gives transparency to human readable.</p>
<p>2.) Clean and fancy urls are easily indexes by Search Engines.</p>
<p>3.)&nbsp; Simple and elegant way to achieve Search Engine Optimization.</p>
<p>4.)&nbsp; Hides our page extension and directory structure.</p>
<p>5.)&nbsp; Safety from Hotlinks, which consumes our band width.</p>
<p><b>Cons:</b></p>
<p>1.) Emphasis on Server Load.(read further to know more)</p>
<p>2.) If a user wants to modify a URL to retrieve new data, the <b>rewrite engine</b> may stuck to the construction of custom URL due to the lack of named variables.</p>
<p>For example, it&#8217;s difficult to identify the date from the following URL:</p>
<pre>http://www.yourdomain.com/post/12/10/2006/</pre>
<p>In this case, the original URL was more useful,</p>
<p>Since the query string denotes month and day:</p>
<pre>http://www. yourdomain.com/post.php/ year=2006&amp;month=12&amp;day=10</pre>
<p><b>What is Rewrite Engine?</b></p>
<p>Rewrite Engine is software that modifies the URL appearance, this modification is&nbsp;called as URL Rewriting.</p>
<p><b>How Rewrite Engine Works?</b></p>
<p>Before moving towards the URL Rewriting module.</p>
<p>You  must ensure that your server is able to handle URL Rewrite request. By  default an apache installation comes with Rewrite Module installed on  it, but it is disabled by default.</p>
<p>So to enable this you have to contact to your hosting provider.</p>
<p><b>What the hosting provider will do?</b></p>
<p>They will open the apache server configuration file httpd .conf</p>
<p>And remove # (comment) from the following line:</p>
<pre>
<pre># LoadModule rewrite_module modules/mod_rewrite.so

Save the httpd .conf file and restart the apache server.Congrats! Now you are able to use Mod URL Rewrite Engine.</pre>
<p></pre>
<p><b>Let&#8217;s Start rewriting :</b></p>
<p><b> </b>URL writing can be achieved by two popular ways.</p>
<p>1.)&nbsp; Using . htaccess file, it is not more than a simple text file but having a very strong utility in itself. You must be familiar with this file because this allows you to set all kinds of server options. A simple example (a custom 404 Not Found Page)</p>
<p>Moreover, this file is interpreted each time by apache server when you made any request.</p>
<p>1.)&nbsp; Using httpd .conf file, this file resides almost all type of server configurations. You can write your mod rewrite rule inside this file.</p>
<p>But you can do so when you have root access.</p>
<p><b>Which method is to choose???</b></p>
<p>Depending upon the following factor let we identify which method is best for you…</p>
<p>a.)&nbsp; <b>Load Issue:</b> A critical question comes in the mind when using new things.</p>
<p>Consider a scenario, you have a very huge site like ebay and you want to use mod URL Rewrite in this.</p>
<p>Obliviously, use of . htaccess file for this purpose emphasis directly on Server Load, because as we know . htaccess file interprets every time by apache server for its each request.</p>
<p>Hence, you should use httpd .conf file for this purpose. As it compile once.</p>
<p><b>b.) </b><b>Performance: </b>Performance of a webpage or web portal is another big issue.</p>
<p><b> </b></p>
<p>Consider another scenario,</p>
<p>You have 1000 of visitors a day, again . htaccess file may reduce the performance of your webportal.</p>
<p>Hence, you should use httpd .conf file for this also.</p>
<p><b>C.)&nbsp;&nbsp;&nbsp; Easyness: </b>Most of the time we have small and medium level WebPages that has moderate amount of visitors. And Want to promote your website on Search Engine Indexing as well.</p>
<p>The easiest way to do this is using . htaccess file, because this file is in our control. So we can edit it any time.</p>
<p>Thus, as per your requirement you can choose any of above method.</p>
<p>For the sake of all the users we will use . htaccess file in this tutorial.</p>
<p><b>Follow the steps:</b></p>
<p>1.) Connect to server via FTP and download the . htaccess file to you local machine from document root i.e. from public_html folder.</p>
<p><b>Important:</b> Keep the orginal . htaccess file on some safe place, in case if we did anything wrong it may cause to our site down, so immediately we can replace this by old one.</p>
<p>2.) The best practice to start with Mod URL Rewrite is to download the whole site on our local machine’s WAMP/LAMP server. And edit . htaccess file.</p>
<p>3.) Now Open . htaccess file in your favorite text editor.</p>
<p>It may be possible this file contents some text or content nothing.</p>
<p>4.) Now you have to add following commands in your . htaccess:</p>
<p>a.) +FollowSymLinks is one of security feature of rewrite engine. You can’t use the rewrite module without this line</p>
<pre>         Options +FollowSymLinks</pre>
<p>b.) Finally most important requirement is to turn the rewrite engine on.</p>
<pre>         RewriteEngine On</pre>
<p>I strongly suggest you to begin you rewriting code with following two commands:</p>
<pre>          Options +FollowSymLinks

          RewriteEngine On</pre>
<p>c.) Following command explicitly set the Base URL for our rewrites.</p>
<pre>          RewriteBase /</pre>
<p><b>Now Write Rewrite Rule:</b></p>
<p>Each Rewrite Rule is executed by &nbsp;a command RewriteRule</p>
<p>Syntax to write a rule is:</p>
<p><b>RewriteRule FANCY_NAME ORIGINAL_NAME</b></p>
<p>For Example:</p>
<p>The existing url is :</p>
<pre>www.yourdomain.com/xyz.php</pre>
<p>And I want this&nbsp; :</p>
<pre>www.yourdomain.com/extras</pre>
<p>More redable.</p>
<p>Hence, Rewrite Rule for this would be:</p>
<pre>RewriteRule     ^extras$      xyz.php</pre>
<p>Where ^ indicates that a pattern must start with extras and $ indicates that a patter must ends with extras. See this is based on Regular expressions. For better understanding of this you must read the Regular Expression basic tutorial.</p>
<p>Now what this Rewrite Rule will do.</p>
<p>When we hit the URL <a href="http://www.yourdomain.com/extras">www.yourdomain.com/extras</a> on our web browser. The . htaccess file matches the patter extras and execute its RewriteRule Command to call the contents of xyz.php.</p>
<p>It looks like, <a href="http://www.yourdomain.com/extras">www.yourdomain.com/extras</a> is working independently but actually it is fetching the content of xyz.php using the Rewrite Rule pattern matching.</p>
<p>Hence the actual URL is modified but it contents remain the same.</p>
<p><b>Thus, the final . htaccess file will look like:</b></p>
<pre>Options +FollowSymLinks

RewriteEngine On

RewriteBase /

RewriteRule     ^extras$      xyz.php

RewriteRule     ^about-us$     about.php

RewriteRule     ^home$     index.php</pre>
<p>Again fancy URLs are :</p>
<pre>http://www.yourdomain.com/homehttp://www.yourdomain.com/extrashttp://www.yourdomain.com/about-us</pre>
<p>Last but not the least; Since this is the basic tutorial for Mod URL Rewrite, so we have to stop here.</p>
<p>And, the advance tutorial with some advance examples on Regular Expression and Link factory will arrive soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.luutaa.com/php/57/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Resize in PHP</title>
		<link>http://blog.luutaa.com/php/image-resize-in-php/</link>
		<comments>http://blog.luutaa.com/php/image-resize-in-php/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 07:11:31 +0000</pubDate>
		<dc:creator>murtaza</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.luutaa.com/?p=20</guid>
		<description><![CDATA[Today i am working on a PHP project and i needed a PHP function which dynamically resize uploaded image. I searched in Google and other PHP forum for 2 &#8211; 3 hours but didn&#8217;t find any perfect solution for my need , some of the functions can resize only jpeg images while some of the functions may resize png and gif images also but the output result is jpeg. So i decided to wrote a [...]]]></description>
			<content:encoded><![CDATA[<p>Today i am working on a PHP project and i needed a PHP function which dynamically resize uploaded image. I searched in Google and other PHP forum for 2 &#8211; 3 hours but didn&#8217;t find any perfect solution for my need , some of the functions can resize only jpeg images while some of the functions may resize png and gif images also but the output result is jpeg. So i decided to wrote a class for image resize .</p>
<p>This class is very easy to use and interesting thing about this class is it can resize all of the popular formats such as JPEG|JPG|PNG|GIF.</p>
<p>Some of the benefits of this class is described below :</p>
<ul>
<li>The format of the output image is same as of the format of the input image .</li>
<li>This class will output transparent compressed png image with the possible quality for web and same for gif format .</li>
<li>Another great feature of this class is that, if we cannot pass new width and new height for resize it will automatically calculate it.</li>
<li>Name of the output image is in the format of current timestamp + new width + new height + extension, so that the name of the image is always unique.</li>
</ul>
<p>So , here is the PHP class which do all of the above functionality</p>
<pre class="brush:php">&lt;?php
class resizeImage{

	function do_resize($w,$h,$filename=array(),$savepath)
	{

		//get the filename of the image
		$name = $filename['name'];

		//get the extension of the image

		$extension = strtolower(end(explode(".",$name)));

		// check wether supported files were uploaded or not
		if (($extension != "jpg") &amp;&amp; ($extension != "jpeg") &amp;&amp; ($extension != "png") &amp;&amp; ($extension != "gif"))
		{
			echo ' Unsupported File';
		}
		else
		{
			// get the temporary filename of the image
			$tmpname=$filename['tmp_name'];

			// set the name of the resized image which is "[current timestamp][-][defined width][defined height][extension]"
			$newf=time()."-".$w.$h.".".$extension;

			// check the format and apply php function
			if($extension=="jpg" || $extension=="jpeg" )
			{
				$im = imagecreatefromjpeg($tmpname);
			}
			else if($extension=="png")
			{
				$im = imagecreatefrompng($tmpname);
			}
			else if($extension=="gif")
			{
				$im = imagecreatefromgif($tmpname);
			}

			// $W is original width of the image
			// $H is original height of the image
			// $w is given width of the image
			// $h is given height of the image

			$W=imagesx($im);
			$H=imagesy($im); 

			if($w==0)
			{
				$w = ($W/$H) *$h;
			}
			else if($h==0)
			{
				$h = ($H/$W) * $w;
			} 

			// variable declared for calculation of width and height of the image
			$newH=0;
			$newW=0;

			if($W&gt;$w)
			{
				if($H&gt;$h)
				{
					if(($H/$h)&gt;($W/$w))
					{
						$newH=$h;
						$newW=$h*($W/$H);
					}
					else
					{
						$newW=$w;
						$newH=$w*($H/$W);
					}
				}
				else
				{
					$newW=$w;
					$newH=$w*($H/$W);
				}
			}
			else
			{
				if($H&gt;$h)
				{
					$newH=$h;
					$newW=$h*($W/$H);
				}
				else
				{
					 $newH=$H;
					 $newW=$W;
				}
			}

			// new temporary file is generated width new width and new height
			$new_temp_image  = imagecreatetruecolor($newW, $newH);

			imagecopyresampled($new_temp_image, $im, 0, 0, 0, 0, $newW, $newH, $W, $H);

			if($extension=="jpg" || $extension=="jpeg" )
			{
				// imageinterlace is used for generating progressive image
				imageinterlace($new_temp_image, true);

				// finally create a new resized image
				imagejpeg($new_temp_image,$savepath.$newf,65);

			}
			else if($extension=="png")
			{
				// Turn off transparency blending
				imagealphablending($new_temp_image, false);

				// create a new transparent color for png image
				$color = imagecolorallocatealpha($new_temp_image, 0, 0, 0, 127);

				// completely fill the background of the new image with allocated color from above step.
				imagefill($new_temp_image, 0, 0, $color);

				// again restore transparency blending
				imagesavealpha($new_temp_image, true);

				// finally create a new resized image
				imagepng($new_temp_image,$savepath.$newf,9);

			}
			else if($extension == "gif" )
			{

				// set the transpatent color in the given image
				$tranparent = imagecolortransparent($im);

				  // check if we have a specific transparent color
				  if ($tranparent &gt;= 0) {

						// get the original rgb value
						$transparent_color    = imagecolorsforindex($im, $tranparent);

						// Allocate the same color in the new image resource
						$tranparent    = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);

						// fill the background of the new image with allocated color.
						imagefill($new_temp_image, 0, 0, $tranparent);

						// Set the background color for new image to transparent
						imagecolortransparent($new_temp_image, $tranparent);
				   }

				imagegif($new_temp_image,$savepath.$newf);
			}

			imagedestroy($new_temp_image);

			// after success this class returns the name of the new file
			return $newf;
		}
	}
}
?&gt;</pre>
<p>I know some of you are bit confused by this class, so let me explain step by step.First we declared a class named resizeImage and in this class we create our function named do_resize().</p>
<p>As you can we are passing four parameters in this function :</p>
<p>- width of the new image</p>
<p>- height of the new image</p>
<p>- array of the $_FILES['input_name']</p>
<p>- savepath (where you want to save the resized image)</p>
<pre class="brush:php">&lt;?php

class resizeImage{

	function do_resize($w,$h,$filename=array(),$savepath)
	{
        }
}
?&gt;</pre>
<p>Next, we are defining some variables such as :</p>
<p>- original name of the image</p>
<p>- temporary name of the image</p>
<p>- format of the image</p>
<p>then we wrote a code block which checks the format of the code and if supported format not found we echoed &#8220;Unsupported File Format&#8221;</p>
<pre class="brush:php">//get the filename of the image

$name = $filename['name'];

// get the temporary filename of the image
$tmpname=$filename['tmp_name'];

//get the extension of the image
$extension = strtolower(end(explode(".",$name)));

// check wether supported files were uploaded or not
if (($extension != "jpg") &amp;&amp; ($extension != "jpeg") &amp;&amp; ($extension != "png") &amp;&amp; ($extension != "gif"))
{
	echo ' Unsupported File Format';
}
</pre>
<p>After checking the format of the code we move a step ahead,</p>
<p>if the given format is correct we create new name for our final output image</p>
<p>in a way, that it should always be unique, so we do this in this way :</p>
<p>current timestamp + new width + new height + format of the original image.</p>
<p>After that we put PHP if else and applied proper image create funtion for correct format</p>
<pre class="brush:php">// set the name of the resized image which is "[current timestamp][-][defined width][defined height][extension]"
$newf=time()."-".$w.$h.".".$extension;

// check the format and apply php function
if($extension=="jpg" || $extension=="jpeg" )
{
	$im = imagecreatefromjpeg($tmpname);
}
else if($extension=="png")
{
	$im = imagecreatefrompng($tmpname);
}
else if($extension=="gif")
{
	$im = imagecreatefromgif($tmpname);
}</pre>
<p>Next, we are going to calculate the width and height for the new image<br />
before i can explain further please look at the variable declaration :<br />
$W &#8211; indicates original width of the image<br />
$H &#8211; indicates original height of the image<br />
$w &#8211; indicates width which we pass it to our function<br />
$h &#8211; indicates height which we pass it to our function<br />
$newW &#8211; indicates width which we are going to calculate<br />
$newH &#8211; indicates height which we are going to calculate<br />
first we check wether new width of new height is given or not,<br />
if not we can calculate it too.</p>
<pre class="brush:php">$W=imagesx($im);
$H=imagesy($im); 

if($w==0)
{
	$w = ($W/$H) *$h;
}
else if($h==0)
{
	$h = ($H/$W) * $w;
} 

// variable declared for calculation of width and height of the image
$newH=0;
$newW=0;
</pre>
<p>Next, we are going to calculate the new height and new width of the image</p>
<pre class="brush:php">if($W&gt;$w)
{
	if($H&gt;$h)
	{
		if(($H/$h)&gt;($W/$w))
		{
			$newH=$h;
			$newW=$h*($W/$H);
		}
		else
		{
			$newW=$w;
			$newH=$w*($H/$W);
		}
	}
	else
	{
		$newW=$w;
		$newH=$w*($H/$W);
	}
}
else
{
	if($H&gt;$h)
	{
		$newH=$h;
		$newW=$h*($W/$H);
	}
	else
	{
		 $newH=$H;
		 $newW=$W;
	}
}
</pre>
<p>first we check whether original image is greater than the given image, if it<br />
is greater than given image, we further check whether original height is greater<br />
than given height, if it is greater than given image, than we check if height is greater<br />
than width than new height will be given height in the function and new width will be given<br />
height * (original width/ original height) and if height is not greater than width, than new<br />
width will be the given width and new height will be given width * (original height / original<br />
width), else original height is not greater than given height, new width will be given width and<br />
new height will be given width * (original height / original width), if outermost if condition<br />
failed than we will process in else condition, in this else block we will check if original height<br />
is greater than given height or not, if TRUE, than new height will be given height and new width<br />
will be given height * ( original width / original height), if FALSE, new height will be original<br />
height and new width will be original width<br />
After calculating new width and new height for the image, we will collect an<br />
image resource identifier with the help of PHP function imagecreatetruecolor<br />
with the help of which we would proceed further and resize our image with the help<br />
of another function imagecopyresampled</p>
<pre class="brush:php">// new temporary file is generated width new width and new height
$new_temp_image  = imagecreatetruecolor($newW, $newH);

imagecopyresampled($new_temp_image, $im, 0, 0, 0, 0, $newW, $newH, $W, $H);
</pre>
<p>Next, we are going to produced our final image and we will do that with the</p>
<p>help of image resource identifier returned by the above function by checking the</p>
<p>format of the image</p>
<pre class="brush:php">if($extension=="jpg" || $extension=="jpeg" )
{
	// imageinterlace is used for generating progressive image
	imageinterlace($new_temp_image, true);

	// finally create a new resized image
	imagejpeg($new_temp_image,$savepath.$newf,65);

}
else if($extension=="png")
{
	// Turn off transparency blending
	imagealphablending($new_temp_image, false);

	// create a new transparent color for png image
	$color = imagecolorallocatealpha($new_temp_image, 0, 0, 0, 127);

	// completely fill the background of the new image with allocated color from above step.
	imagefill($new_temp_image, 0, 0, $color);

	// again restore transparency blending
	imagesavealpha($new_temp_image, true);

	// finally create a new resized image
	imagepng($new_temp_image,$savepath.$newf,9);

}
else if($extension == "gif" )
{

	// set the transpatent color in the given image
	$tranparent = imagecolortransparent($im);

	// check if we have a specific transparent color
        if ($tranparent &gt;= 0) {

	       // get the original rgb value
	       $transparent_color    = imagecolorsforindex($im, $tranparent);

        	// Allocate the same color in the new image resource
        	$tranparent    = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);

        	// fill the background of the new image with allocated color.
        	imagefill($new_temp_image, 0, 0, $tranparent);

        	// Set the background color for new image to transparent
        	imagecolortransparent($new_temp_image, $tranparent);
        }

	imagegif($new_temp_image,$savepath.$newf);
}
</pre>
<p>Next, we are going to destroy our temporary image resource identifier because we didn&#8217;t</p>
<p>need it any more .<br />
Finally, our function will return the name of the uploaded image</p>
<pre class="brush:php">imagedestroy($new_temp_image);

// after success this class returns the name of the new file
return $newf;
</pre>
<p>That&#8217;s all. Hope you enjoyed this tutorial and may this class will help you in your own project.<br />
Any feedback and suggestion are welcome from you. We would like to hear from you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.luutaa.com/php/image-resize-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

