<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5762064040393208356</id><updated>2024-09-10T07:57:44.744-07:00</updated><title type='text'>How To Heaven</title><subtitle type='html'>find best linux tutorial , centos tutorial , set up and configuring  linux , apache and php webserver</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>54</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-8762578444066016663</id><published>2012-08-21T04:26:00.002-07:00</published><updated>2012-08-21T04:26:41.211-07:00</updated><title type='text'>How to fix vsftpd error “500 OOPS: cannot change directory:/some/directory”</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: &#39;Lucida Grande&#39;, Verdana, Arial, sans-serif; font-size: 11px; line-height: 1.5em; margin-bottom: 10px; margin-right: 5px; margin-top: 10px; text-align: justify;&quot;&gt;
that error is generate for Selinux plz do the following actions:&lt;/div&gt;
&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: &#39;Lucida Grande&#39;, Verdana, Arial, sans-serif; font-size: 11px; line-height: 1.5em; margin-bottom: 10px; margin-right: 5px; margin-top: 10px; text-align: justify;&quot;&gt;
[root@sun02 vsftpd]# getenforce&lt;br /&gt;Enforcing&lt;br /&gt;[root@sun02 vsftpd]# getsebool -a | grep ftp&lt;br /&gt;allow_ftpd_anon_write –&amp;gt; off&lt;br /&gt;allow_ftpd_full_access –&amp;gt; off&lt;br /&gt;allow_ftpd_use_cifs –&amp;gt; off&lt;br /&gt;allow_ftpd_use_nfs –&amp;gt; off&lt;br /&gt;allow_tftp_anon_write –&amp;gt; off&lt;br /&gt;ftp_home_dir –&amp;gt; on (change that to on in ur case this option is off)&lt;br /&gt;ftpd_disable_trans –&amp;gt; off&lt;br /&gt;ftpd_is_daemon –&amp;gt; on&lt;br /&gt;httpd_enable_ftp_server –&amp;gt; off&lt;br /&gt;tftpd_disable_trans –&amp;gt; off&lt;br /&gt;[root@sun02 vsftpd]# setsebool -P ftp_home_dir on&lt;/div&gt;
&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: &#39;Lucida Grande&#39;, Verdana, Arial, sans-serif; font-size: 11px; line-height: 1.5em; margin-bottom: 10px; margin-right: 5px; margin-top: 10px; text-align: justify;&quot;&gt;
This is all that u want to need.&lt;/div&gt;
&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: &#39;Lucida Grande&#39;, Verdana, Arial, sans-serif; font-size: 11px; line-height: 1.5em; margin-bottom: 10px; margin-right: 5px; margin-top: 10px; text-align: justify;&quot;&gt;
Good Luck!&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/8762578444066016663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/08/how-to-fix-vsftpd-error-500-oops-cannot.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/8762578444066016663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/8762578444066016663'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/08/how-to-fix-vsftpd-error-500-oops-cannot.html' title='How to fix vsftpd error “500 OOPS: cannot change directory:/some/directory”'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-7271244398505126189</id><published>2012-07-14T13:48:00.001-07:00</published><updated>2012-07-14T13:48:36.928-07:00</updated><title type='text'>how to create a custom Pinterest “Pin It” button for your website</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is the Javascript code I use to create a Pin It button for a web page using a custom graphic:&lt;br /&gt;

&lt;br /&gt;

&lt;pre&gt;&amp;lt;div&amp;gt;
&amp;lt;a href=&quot;javascript:void((&lt;wbr&gt;&lt;/wbr&gt;function(){var%20e=document.&lt;wbr&gt;&lt;/wbr&gt;createElement(&#39;script&#39;); e.&lt;wbr&gt;&lt;/wbr&gt;setAttribute(&#39;type&#39;,&#39;text/&lt;wbr&gt;&lt;/wbr&gt;javascript&#39;); e.setAttribute(&#39;&lt;wbr&gt;&lt;/wbr&gt;charset&#39;,&#39;UTF-8&#39;); e.&lt;wbr&gt;&lt;/wbr&gt;setAttribute(&#39;src&#39;,&#39;&lt;a href=&quot;http://assets.pinterest.com/js/pinmarklet.js?r=%27+Math.random%28%29*99999999%29;document.body.appendChild%28e%29%7D%29%28%29%29&quot; target=&quot;_blank&quot;&gt;http://&lt;wbr&gt;&lt;/wbr&gt;assets.pinterest.com/js/&lt;wbr&gt;&lt;/wbr&gt;pinmarklet.js?r=&#39;+Math.random(&lt;wbr&gt;&lt;/wbr&gt;)*99999999);document.body.&lt;wbr&gt;&lt;/wbr&gt;appendChild(e)})())&lt;/a&gt;;&quot;&amp;gt; &amp;lt;img src=&quot;images&lt;a href=&quot;http://www.clickinmoms.com/cmprodaily/wp-content/uploads/2011/09/pinit.jpg&quot; target=&quot;_blank&quot;&gt;/pinit.jpg&lt;/a&gt;&quot; alt=&quot;Pin It&quot; /&amp;gt;&amp;lt;/a&amp;gt; &amp;lt;/div&amp;gt; &amp;nbsp;&lt;/pre&gt;
You will want to change the path to the image in the code above so 
that it points to the graphic that you want to use for the Pin It 
button. You could also substitute text for the graphic if you prefer.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/7271244398505126189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/how-to-create-custom-pinterest-pin-it.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/7271244398505126189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/7271244398505126189'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/how-to-create-custom-pinterest-pin-it.html' title='how to create a custom Pinterest “Pin It” button for your website'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-4230495280992768355</id><published>2012-07-08T07:26:00.000-07:00</published><updated>2012-07-08T07:26:04.661-07:00</updated><title type='text'>ho to Set static front page and blog page programmatically in WordPress</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
You want to make sure the About and Blog pages exist, so create them before if necessary, see &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/wp_insert_post&quot;&gt;wp_insert_post()&lt;/a&gt;&lt;br /&gt;

    
   
   &lt;div class=&quot;content&quot;&gt;

    &lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Use a static front page&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$about&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_page_by_title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;About&#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;update_option&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;page_on_front&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$about&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ID&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;update_option&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;show_on_front&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;page&#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Set the blog page&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$blog&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_page_by_title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;Blog&#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;update_option&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;page_for_posts&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$blog&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ID&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Switch to our theme&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//switch_theme( &#39;Template&#39;, &#39;stylesheet&#39; );&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/4230495280992768355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/ho-to-set-static-front-page-and-blog.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4230495280992768355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4230495280992768355'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/ho-to-set-static-front-page-and-blog.html' title='ho to Set static front page and blog page programmatically in WordPress'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-2221884334332754703</id><published>2012-07-06T07:17:00.003-07:00</published><updated>2012-07-06T07:17:40.575-07:00</updated><title type='text'>How to Force a WordPress plugin to be loaded before all other plugins</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
When you activate a plugin via the WordPress admin panel it calls the action hook “&lt;em&gt;activated_plugin&lt;/em&gt;“, which updates the “&lt;em&gt;active_plugins&lt;/em&gt;” site option stored in the database to determine which plugins your site should load.&lt;br /&gt;

The option value is a serialized array of the active plugins saved in
 alphabetical order according to the plugin directory and file name, for
 example:&lt;br /&gt;

&lt;span id=&quot;more-829&quot;&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre&gt;Array
(
 [0] =&amp;gt; akismet/akismet.php
 [1] =&amp;gt; example-plugin/index.php
)&lt;/pre&gt;
You can however alter the order of the plugins in the array, which 
will in turn set the order in which the plugins are loaded by WordPress.&lt;br /&gt;

The first step towards adjusting the order is to add the following action to your plugin file, which is most likely to be &lt;em&gt;/my-plugin/index.php&lt;/em&gt; or &lt;em&gt;/my-plugin/my-plugin.php&lt;/em&gt;.&lt;br /&gt;

&lt;pre&gt;add_action( &#39;activated_plugin&#39;, &#39;my_plugin_load_first&#39; );&lt;/pre&gt;
Next you need to include the functionality to perform the actual 
re-ordering. The following function will fetch the existing list, check 
that your plugin is in the array and if so remove then append it to the 
beginning, before finally saving the altered list to the database.&lt;br /&gt;

&lt;pre&gt;function my_plugin_load_first()
{
 $path = str_replace( WP_PLUGIN_DIR . &#39;/&#39;, &#39;&#39;, __FILE__ );
 if ( $plugins = get_option( &#39;active_plugins&#39; ) ) {
  if ( $key = array_search( $path, $plugins ) ) {
   array_splice( $plugins, $key, 1 );
   array_unshift( $plugins, $path );
   update_option( &#39;active_plugins&#39;, $plugins );
  }
 }
}&lt;/pre&gt;
It should not be necessary for you to adjust anything specified here 
other than modifying the name of the function used to suit the namespace
 used by your plugin.&lt;br /&gt;

One final thing to consider is only adding this action when the 
dashboard or administration panels are being displayed, by making use of
 the &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/is_admin&quot; target=&quot;_blank&quot;&gt;is_admin()&lt;/a&gt; conditional tag.&lt;br /&gt;

&lt;strong&gt;Please note that modifying this option is not something I 
recommend people do unless absolutely necessary, and it my situation it 
proved to be very useful.&lt;/strong&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/2221884334332754703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/how-to-force-wordpress-plugin-to-be.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/2221884334332754703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/2221884334332754703'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/how-to-force-wordpress-plugin-to-be.html' title='How to Force a WordPress plugin to be loaded before all other plugins'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-3257902414148474634</id><published>2012-07-04T12:11:00.000-07:00</published><updated>2012-07-04T12:11:27.653-07:00</updated><title type='text'>How to load the template you want with template_redirect - Wordpress</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
				
		&lt;br /&gt;
&lt;div class=&quot;postcontent&quot;&gt;
 
        					If you’re a web developer and you are using&amp;nbsp;WordPress&amp;nbsp;to
 create a website rather than a blog, I’m&amp;nbsp;pretty sure you would try to 
achieve some of the following:&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;use a different layout for a certain category (and maybe all it’s subcategories)&lt;/li&gt;
&lt;li&gt;use a different layout for a certain post&lt;/li&gt;
&lt;li&gt;use a different layout for a certain post inside a certain category&lt;/li&gt;
&lt;li&gt;load a different page&amp;nbsp;for a certain non-WordPress-URL&lt;/li&gt;
&lt;/ul&gt;
If I guessed, then this tutorial is for you.&lt;br /&gt;

&lt;h2&gt;
template_redirect – where all begins&lt;/h2&gt;
The drawing bellow illustrates how &lt;em&gt;template_redirect &lt;/em&gt;works. Basically, you use it to&amp;nbsp;intervene&amp;nbsp;&lt;strong&gt;&lt;em&gt;just before&lt;/em&gt;&lt;/strong&gt; WordPress decides which template to use, and then override it with what you want.&lt;br /&gt;

&lt;a href=&quot;http://www.mihaivalentin.com/wp-content/uploads/2010/12/template_redirect_request.gif&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;alignnone size-full wp-image-363&quot; height=&quot;254&quot; src=&quot;http://www.mihaivalentin.com/wp-content/uploads/2010/12/template_redirect_request.gif&quot; title=&quot;template_redirect_request&quot; width=&quot;544&quot; /&gt;&lt;/a&gt;&lt;br /&gt;

The simplest way to show how&amp;nbsp;&lt;em&gt;template_redirect &lt;/em&gt;works would 
be to tell WordPress that, no matter which page is requested, just 
display “Testing template_redirect” on a blank page.&lt;br /&gt;

The code is below. I recommend you put it in &lt;strong&gt;functions.php&lt;/strong&gt; file of your theme:&lt;br /&gt;

&lt;div&gt;
&lt;div class=&quot;syntaxhighlighter  php&quot; id=&quot;highlighter_309742&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
6&lt;/div&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;code class=&quot;php keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;my_template() {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;echo&lt;/code&gt; &lt;code class=&quot;php string&quot;&gt;&quot;Testing template_redirect&quot;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;exit&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;template_redirect&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;my_template&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;em&gt;add_action &lt;/em&gt;is a function that allows you to hook to certain moments in the WordPress loading process and provide custom functionality. &lt;em&gt;template_redirect &lt;/em&gt;is one of the many functionalities you can alter.&lt;br /&gt;

As a result of the &lt;em&gt;add_action &lt;/em&gt;call, WordPress will execute &lt;em&gt;my_template &lt;/em&gt;function&amp;nbsp;every time&amp;nbsp;a page is requested in order to find out which template should it load.&lt;br /&gt;

As I said above, this example just prints that text and does nothing afterward (because of the &lt;em&gt;exit &lt;/em&gt;keyword).
 If exit would not be present, the text would have been printed, and 
WordPress would have continued with it’s default logic.&lt;br /&gt;

&lt;h2&gt;
So, what can we really do inside template_redirect?&lt;/h2&gt;
Because I don’t like theory either, I will begin with some simples examples and explanations.&lt;br /&gt;

&lt;h3&gt;
Use a different template for a certain category (example “fun”)&lt;/h3&gt;
&lt;div&gt;
&lt;div class=&quot;syntaxhighlighter  php&quot; id=&quot;highlighter_693200&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
8&lt;/div&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;code class=&quot;php keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;my_template() {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(is_category() &amp;amp;&amp;amp; get_query_var(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;cat&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;) == get_cat_id(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;fun&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;)) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;include&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(TEMPLATEPATH . &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;/category-fun.php&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;exit&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;template_redirect&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;my_template&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The first thing we check is whether we find ourselves in a category. 
is_category() tells me if I am currently trying to access a category 
page. This first condition is useful, because we&amp;nbsp;wouldn’t&amp;nbsp;want to apply 
this rule to a post, to a page or the front page.&lt;br /&gt;

The next condition (&lt;em&gt;get_query_var(‘cat’) == get_cat_id(‘fun’)&lt;/em&gt;) checks whether we are trying to access the “fun” category of our blog. &lt;em&gt;get_query_var&lt;/em&gt; gets the numeric id of the category we are currently accessing. &amp;nbsp;&lt;em&gt;get_cat_id&lt;/em&gt; gets the id for the given category name. We could also do &lt;em&gt;get_query_var(‘cat’) == 7&lt;/em&gt; &lt;span style=&quot;color: #999999;&quot;&gt;(assuming
 that “fun” has the id 7, but it is not recommended to leave numbers in 
your code, as later you won’t have any idea what “7″ represents)&lt;/span&gt;&lt;br /&gt;

If both conditions are true, that means we are accessing the “fun” 
category and we load a different template for it. In this case, we 
include the file “category-fun.php” and then exit. As I said above, we 
exit because we loaded the template and we have to tell&amp;nbsp;WordPress&amp;nbsp;to 
stop executing the default logic.&lt;br /&gt;

If one or both conditions are false, then nothing happens, and 
WordPress continues to process it’s default logic, thus loading the 
default category page.&lt;br /&gt;

&lt;h3&gt;
Use a different template for a certain category and all it’s subcategories (example “fun”)&lt;/h3&gt;
Suppose now that our “fun” category has more subcategories, such as 
“jokes”, “cats”, “epic fails”, “shows”. If you want all these categories
 (including their parent – fun) to have the same template, there are two
 options:&lt;br /&gt;

- either you add more conditions to the function in the previous 
example (which is really not a good idea, as for any new subcategories 
you would also have to add new conditions)&lt;br /&gt;

- either you use the code below that&amp;nbsp;explicitly&amp;nbsp;states that both fun 
and it’s subcategories (that may change in time) will be loaded using 
the given template (this is the good solution)&lt;br /&gt;

&lt;div&gt;
&lt;div class=&quot;syntaxhighlighter  php&quot; id=&quot;highlighter_481216&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
10&lt;/div&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;code class=&quot;php keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;my_template() {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(is_category() &amp;amp;&amp;amp;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;(get_query_var(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;cat&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;) == get_cat_id(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;fun&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;) ||&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;cat_is_ancestor_of(get_cat_id(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;fun&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;), get_query_var(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;cat&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;)))) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;include&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(TEMPLATEPATH . &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;/category-fun.php&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;exit&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;template_redirect&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;my_template&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
This example adds a new condition&amp;nbsp;referring to the category ancestor. So basically now, all it does is check:&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;whether it is the “fun” category itself &lt;strong&gt;OR&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;whether it is a category that is a children of “fun”&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
Use a different layout for a certain post&lt;/h3&gt;
&lt;div&gt;
&lt;div class=&quot;syntaxhighlighter  php&quot; id=&quot;highlighter_45420&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;line number11 index10 alt2&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;line number12 index11 alt1&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;line number13 index12 alt2&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;line number14 index13 alt1&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;line number15 index14 alt2&quot;&gt;
15&lt;/div&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;code class=&quot;php keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;my_template() {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(is_single()) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;global&lt;/code&gt; &lt;code class=&quot;php variable&quot;&gt;$post&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$post&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;-&amp;gt;ID == 10) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;include&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(TEMPLATEPATH . &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;/post-with-id-10.php&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;exit&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$post&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;-&amp;gt;post_name == &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;hello-world&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;include&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(TEMPLATEPATH . &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;/post-with-permalink-hello-world.php&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;exit&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number11 index10 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number12 index11 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number13 index12 alt2&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number14 index13 alt1&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line number15 index14 alt2&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;template_redirect&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;my_template&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The example below shows that you can check for any property of the 
post in order to take a decision about which template to load.&lt;br /&gt;

is_single() returns true if a single post is being accessed.&lt;br /&gt;

&lt;h3&gt;
Use a different layout for a certain post inside a certain category&lt;/h3&gt;
&lt;div&gt;
&lt;div class=&quot;syntaxhighlighter  php&quot; id=&quot;highlighter_864828&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;line number11 index10 alt2&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;line number12 index11 alt1&quot;&gt;
12&lt;/div&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;code class=&quot;php keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;my_template() {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(is_single()) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;global&lt;/code&gt; &lt;code class=&quot;php variable&quot;&gt;$post&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$current_post_categories&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;= wp_get_post_categories(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$post&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;-&amp;gt;ID);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(in_array(get_cat_id(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;fun&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;),&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$current_post_categories&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;)) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;include&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(TEMPLATEPATH . &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;/post-in-fun.php&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;exit&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number10 index9 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number11 index10 alt2&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line number12 index11 alt1&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;template_redirect&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;my_template&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The first thing we do is to get the list of categories in which the 
current post belongs and then see if “fun” is one of them. If yes, that 
means the post is in the “fun” category and we load it’s template.&lt;br /&gt;

&lt;h3&gt;
Load a different page for a certain non-WordPress-URL&lt;/h3&gt;
This is a bit tricky, because if you want to have a custom link 
structure for some sections of your website, if they do not look like 
what WordPress knows, it will throw you a nice 404 not found response 
and will mess up both your SEO and your page (on some browsers like 
Internet Explorer, if it receives a 404, it displays their default 404 
page). That’s why first we have define a function like this:&lt;br /&gt;

&lt;div&gt;
&lt;div class=&quot;syntaxhighlighter  php&quot; id=&quot;highlighter_110374&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
9&lt;/div&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;code class=&quot;php keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;include_wordpress_template(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$t&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;global&lt;/code&gt; &lt;code class=&quot;php variable&quot;&gt;$wp_query&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$wp_query&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;-&amp;gt;is_404) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$wp_query&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;-&amp;gt;is_404 = false;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$wp_query&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;-&amp;gt;is_archive = true;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;header(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&quot;HTTP/1.1 200 OK&quot;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number8 index7 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;include&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$t&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number9 index8 alt2&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
What this function does is it removes the 404 flag for WordPress, it 
sends the 200 OK header and then includes the requested template&lt;br /&gt;

&lt;div&gt;
&lt;div class=&quot;syntaxhighlighter  php&quot; id=&quot;highlighter_108349&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
7&lt;/div&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot;&gt;
&lt;code class=&quot;php keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;my_template() {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$_SERVER&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;[&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;REQUEST_URI&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;] == &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;/high-scores&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;) {&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;include_wordpress_template(TEMPLATEPATH . &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;/high-scores.php&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot;&gt;
&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number6 index5 alt1&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line number7 index6 alt2&quot;&gt;
&lt;code class=&quot;php plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;template_redirect&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;php string&quot;&gt;&#39;my_template&#39;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
What this function does is that if someone enters on /high-scores, it
 justs loads a certain template, without letting wordpress deciding 
whether it is a post or a page. It is extremly useful for embedding 
extra-functionality based on a custom link structure. It’s like building
 a whole new attached to the structure of&amp;nbsp;WordPress, but without needing
 to map it to the&amp;nbsp;WordPress&amp;nbsp;default entities such as “posts”, “pages”, 
“categories”, “tags”, etc.&lt;br /&gt;

&lt;h2&gt;
Where to go from here&lt;/h2&gt;
This tutorial presented you some basic examples of how you can load 
custom templates depending on some given conditions. As you can see, the
 possiblities are limitless and this is where you must begin to make a 
simple WordPress blog become a complex website.&lt;br /&gt;

I recommend reading the WordPress Codex to find out what other cool functions you can use.&lt;br /&gt;

Some quick links for that are: &lt;a href=&quot;http://codex.wordpress.org/Conditional_Tags&quot; target=&quot;_blank&quot;&gt;Conditional Tags&lt;/a&gt;, &lt;a href=&quot;http://codex.wordpress.org/Function_Reference/query_posts&quot; target=&quot;_blank&quot;&gt;Query posts&lt;/a&gt;, &lt;a href=&quot;http://codex.wordpress.org/Function_Reference&quot; target=&quot;_blank&quot;&gt;Function reference&lt;/a&gt;&lt;br /&gt;

		
			&lt;/div&gt;
&lt;div id=&quot;comment-wrap&quot;&gt;



	&lt;h3 id=&quot;comments&quot;&gt;
&lt;br /&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/3257902414148474634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/how-to-load-template-you-want-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/3257902414148474634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/3257902414148474634'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/07/how-to-load-template-you-want-with.html' title='How to load the template you want with template_redirect - Wordpress'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-704544863792764016</id><published>2012-06-27T13:18:00.001-07:00</published><updated>2012-06-27T13:18:21.365-07:00</updated><title type='text'>How to add jQuery Thickbox on Ajax Generated Pages</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
The jQuery thickbox plugin is fantastic. All you have to do is 
include the js file, and give the elements that require a jQuery 
thickbox, a class of thickbox. Like below;&lt;br /&gt;

&lt;span id=&quot;more-12&quot;&gt;&lt;/span&gt;&lt;br /&gt;

&lt;code class=&quot;codeIndent&quot;&gt;&amp;lt;a class=&quot;thickbox&quot; href=&quot;thickboxexample.php?height=600&amp;amp;width=600&quot;&amp;gt;jQuery Thickbox Example&amp;lt;/a&amp;gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;

The thickbox plugin then automically!! attaches its events to those 
elements. For ease of use this is great, but it has its limitations, 
because the events are attached on page load.&lt;br /&gt;

&lt;strong&gt;What happens when you want to attach a thickbox to an element that is generated via an ajax call? &lt;/strong&gt;&lt;br /&gt;

Well you’re gonna kick yourself! You simply need to re-call the the 
thickbox initialise function within your ajax call, just like the 
example below:&lt;br /&gt;

&lt;pre class=&quot;codeIndent&quot;&gt;$.ajax({
    type:       &quot;GET&quot;,
    url:        &quot;/ajax-content.php&quot;,
    cache:      false,
    data:       &quot;f=foo&amp;amp;b=bar&quot;,
    loading:    $(&#39;.loading&#39;).html(&quot;&quot;),
    success:    function(html) {
                    $(&quot;#ajaxContent&quot;).html(html);
                    //re-attach thickbox
                    tb_init(&#39;a.thickbox, area.thickbox, input.thickbox&#39;);
                }
});&lt;/pre&gt;
I am assuming that you already know how to make an ajax call using 
jQuery, so I won’t explain the above code, except for the fact that a 
call is made to &lt;code&gt;tb_init()&lt;/code&gt; after the ajax response. This is the thickbox initialise function which attaches its events to your selected elements.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/704544863792764016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/06/how-to-add-jquery-thickbox-on-ajax.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/704544863792764016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/704544863792764016'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/06/how-to-add-jquery-thickbox-on-ajax.html' title='How to add jQuery Thickbox on Ajax Generated Pages'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-4912569787617155161</id><published>2012-06-20T08:12:00.001-07:00</published><updated>2012-06-20T08:12:27.084-07:00</updated><title type='text'>How To Use PHP to Force a File Download</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
PHP allows you to change the HTTP headers of files that you&#39;re writing, 
so that you can force a file to be downloaded that normally the browser 
would load in the same window. This is perfect for files like PDFs, 
document files, images, and video that you want your customers to 
download rather than read online.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Here&#39;s How:&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Upload the file you want to make available for download to your Web server. For example, &lt;blockquote class=&quot;yes&quot;&gt;
huge_document.pdf&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Edit a new PHP file - I recommend naming it the same name as your downloaded file, only with the extension .php. For example: &lt;blockquote class=&quot;yes&quot;&gt;
huge_document.php&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Open the PHP block: &lt;blockquote class=&quot;yes&quot;&gt;
&amp;lt;?php&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;On the next line, set the HTTP header: &lt;blockquote class=&quot;yes&quot;&gt;
header(&#39;Content-disposition: attachment; filename=huge_document.pdf&#39;);&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Then set the MIME-type of the file: &lt;blockquote class=&quot;yes&quot;&gt;
header(&#39;Content-type: application/pdf&#39;);&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Point to the file you want to download: &lt;blockquote class=&quot;yes&quot;&gt;
readfile(&#39;huge_document.pdf&#39;);&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Then close the PHP block and save the file: &lt;blockquote class=&quot;yes&quot;&gt;
?&amp;gt;[/blockquote&amp;gt;&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Your PHP file should look like this:&lt;blockquote class=&quot;yes&quot;&gt;

&amp;lt;?php&lt;br /&gt;
header(&#39;Content-disposition: attachment; filename=huge_document.pdf&#39;);&lt;br /&gt;
header(&#39;Content-type: application/pdf&#39;);&lt;br /&gt;
readfile(&#39;huge_document.pdf&#39;);&lt;br /&gt;
?&amp;gt;
    &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;Link to your PHP file as a download link. For example: &lt;blockquote class=&quot;yes&quot;&gt;
&amp;lt;a href=&quot;huge_document.php&quot;&amp;gt;Download my huge document (PDF)&amp;lt;/a&amp;gt;&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;There should be &lt;b&gt;no spaces or carriage returns&lt;/b&gt; anywhere in the file. Blank lines will cause PHP to default to text/html and your file won&#39;t download.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
What You Need&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The file to be downloaded&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;http://webdesign.about.com/od/multimedia/l/bl_mime_types_by_file_ext.htm&quot;&gt;MIME type&lt;/a&gt; of the file&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/4912569787617155161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/06/how-to-use-php-to-force-file-download.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4912569787617155161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4912569787617155161'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/06/how-to-use-php-to-force-file-download.html' title='How To Use PHP to Force a File Download'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-4235544990375454355</id><published>2012-06-20T04:01:00.000-07:00</published><updated>2012-06-20T04:01:11.339-07:00</updated><title type='text'>How to send email from the Linux command line</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
The Linux command line can be very powerful once you know how to use 
it. You can parse data, monitor processes, and do a lot of other useful 
and cool things using it. There often comes a need to generate a report 
and mail it out. It could be as simple a requirement as a notification 
that the day’s backup went through fine, or did not. I’ll help you get 
started with sending mails from the Linux command line and in shell 
scripts. We will also cover sending attachments from the command line. 
We will begin with the “mail” command. &lt;span id=&quot;more-1763&quot;&gt;&lt;/span&gt;&lt;br /&gt;

&lt;h3&gt;
MAIL&lt;/h3&gt;
First run a quick test to make sure the “sendmail” application is 
installed and working correctly. Execute the following command, 
replacing “you@youremailid.com” with your e-mail address.&lt;br /&gt;

 # &lt;strong&gt;mail -s “Hello world” you@youremailid.com&lt;/strong&gt;&lt;br /&gt;

Hit the return key and you will come to a new line. Enter the text 
“This is a test from my server”. Follow up the text by hitting the 
return key again. Then hit the key combination of &lt;strong&gt;Control+D&lt;/strong&gt; to continue. The command prompt will ask you if you want to mark a copy of the mail to any other address, hit &lt;strong&gt;Control+D&lt;/strong&gt; again. Check your mailbox. This command will send out a mail to the email id mentioned with the subject, “Hello world”.&lt;br /&gt;

To add content to the body of the mail while running the command you 
can use the following options. If you want to add text on your own:&lt;br /&gt;

 # &lt;strong&gt;echo “This will go into the body of the mail.” | mail -s “Hello world” you@youremailid.com&lt;/strong&gt;&lt;br /&gt;

And if you want mail to read the content from a file:&lt;br /&gt;

 # &lt;strong&gt;mail -s “Hello world” you@youremailid.com &amp;lt; /home/calvin/application.log&lt;/strong&gt;&lt;br /&gt;

Some other useful options in the mail command are:&lt;br /&gt;

 &lt;strong&gt;-s subject&lt;/strong&gt; (The subject of the mail)&lt;br /&gt;
 &lt;strong&gt;-c email-address&lt;/strong&gt; (Mark a copy to this “email-address”, or CC)&lt;br /&gt;
 &lt;strong&gt;-b email-address&lt;/strong&gt; (Mark a blind carbon copy to this “email-address”, or BCC)&lt;br /&gt;

Here’s how you might use these options:&lt;br /&gt;

 # &lt;strong&gt;echo “Welcome to the world of Calvin n Hobbes” | mail -s “Hello world” calvin@cnh.com -c hobbes@cnh.com -b susie.derkins@cnh.com&lt;/strong&gt;&lt;br /&gt;

&lt;h3&gt;
MUTT&lt;/h3&gt;
One of major drawbacks of using the mail command is that it does not 
support the sending of attachments. mutt, on the other hand, does 
support it. I’ve found this feature particularly useful for scripts that
 generate non-textual reports or backups which are relatively small in 
size which I’d like to backup elsewhere. Of course, mutt allows you to 
do a lot more than just send attachments. It is a much more complete 
command line  mail client than the “mail” command. Right now we’ll just 
explore the basic stuff we might need often. Here’s how you would attach
 a file to a mail:&lt;br /&gt;

 # &lt;strong&gt;echo “Sending an attachment.” | mutt -a backup.zip -s “attachment” calvin@cnh.com&lt;/strong&gt;&lt;br /&gt;

This command will send a mail to calvin@cnh.com with the subject (-s)
 “attachment”, the body text “Sending an attachment.”, containing the 
attachment (-a) backup.zip. Like with the mail command you can use the 
“-c” option to mark a copy to another mail id.&lt;br /&gt;

&lt;h3&gt;
SENDING MAIL FROM A SHELL SCRIPT&lt;/h3&gt;
Now, with the basics covered you can send mails from your shell 
scripts. Here’s a simple shell script that gives you a reading of the 
usage of space on your partitions and mails the data to you.&lt;br /&gt;

&lt;blockquote&gt;
#!/bin/bash&lt;br /&gt;
 df -h | mail -s “disk space report” calvin@cnh.com&lt;/blockquote&gt;
Save these lines in a file on your Linux server and run it. You 
should receive a mail containing the results of the command. If, 
however, you need to send more data than just this you will need to 
write the data to a text file and enter it into the mail body while 
composing the mail. Here’s and example of a shell script that gets the 
disk usage as well as the memory usage, writes the data into a temporary
 file, and then enters it all into the body of the mail being sent out:&lt;br /&gt;

&lt;blockquote&gt;
#!/bin/bash&lt;br /&gt;
 df -h &amp;gt; /tmp/mail_report.log&lt;br /&gt;
 free -m &amp;gt;&amp;gt; /tmp/mail_report.log&lt;br /&gt;
 mail -s “disk and RAM report” calvin@cnh.com &amp;lt; /tmp/mail_report.log&lt;/blockquote&gt;
Now here’s a more complicated problem. You have to take a backup of a
 few files and mail then out. First the directory to be mailed out is 
archived. Then it is sent as an email attachment using mutt. Here’s a 
script to do just that:&lt;br /&gt;

&lt;blockquote&gt;
#!/bin/bash&lt;br /&gt;
 tar -zcf /tmp/backup.tar.gz  /home/calvin/files&lt;br /&gt;
 echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” calvin@cnh.com&lt;/blockquote&gt;
The echo at the start of the last line adds a blank into the body of the mail being set out.&lt;br /&gt;

This should get you started with sending mails form the Linux command
 line and from shell scripts. Read up the “man page” for both mail and 
mutt for more options.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/4235544990375454355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/06/how-to-send-email-from-linux-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4235544990375454355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4235544990375454355'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/06/how-to-send-email-from-linux-command.html' title='How to send email from the Linux command line'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-6823220473161779083</id><published>2012-05-17T06:06:00.002-07:00</published><updated>2012-05-17T06:06:27.835-07:00</updated><title type='text'>how to fix Yum thread.error: can’t start new thread</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
 
     If you get this error &lt;b&gt;(thread.error: can’t start new thread)&lt;/b&gt;
 when you are trying to update your CentOS (I got this error when I 
tried to install PHP), you have a two step solution to overcome this 
issue. This is not very common issue, and its about the memory resource 
problem with the VPS which is caused by Yum’s fastestmirror plugin. Here
 is the solution;&lt;br /&gt;

&lt;ol&gt;
&lt;li&gt;Stop the mysql server.&lt;/li&gt;
&lt;li&gt;Start Yum again after disabling Yum’s fastestmirror plugin like the code below;&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;yum --disableplugin=fastestmirror update&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;
You should now update your CentOS.&lt;br /&gt;

                    &lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/6823220473161779083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-fix-yum-threaderror-cant-start.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/6823220473161779083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/6823220473161779083'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-fix-yum-threaderror-cant-start.html' title='how to fix Yum thread.error: can’t start new thread'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-2318660217222067551</id><published>2012-05-10T14:36:00.001-07:00</published><updated>2012-05-10T14:36:50.509-07:00</updated><title type='text'>How to Install Apache 2.4.2 from Source on CentOS 6.2 with SSL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;Make sure you have gcc and openssl-devel installed.&lt;br /&gt;

&lt;pre&gt;# yum install gcc
# yum install openssl-devel&lt;/pre&gt;
You also need “Apache Portable Runtime Library” APR to install Apache from source.&lt;br /&gt;

You’ll already have “apr” and “apr-util” package installed. Install the apr-devel and apr-util-devel packages.&lt;br /&gt;

&lt;pre&gt;# yum install apr-devel
# yum install apr-util-devel&lt;/pre&gt;
Note: In our case (because of the version compatibility issues), 
we’ll be downloading these and installing it manually later. But, let us
 go with the flow for now and see what happens when you try to do it 
this way.&lt;br /&gt;

&lt;h3&gt;
Download Apache&lt;/h3&gt;
Download Apache from &lt;a href=&quot;http://httpd.apache.org/&quot;&gt;httpd.apache.org&lt;/a&gt;. The current stable release is 2.4.2.&lt;br /&gt;

Once you get the direct URL to download the latest stable version of 
Apache, use wget as shown below to download it directly to you server.&lt;br /&gt;

&lt;pre&gt;cd /usr/src
wget http://mirror.nyi.net/apache//httpd/httpd-2.4.2.tar.gz
tar xvfz httpd-2.4.2.tar.gz&lt;/pre&gt;
&lt;h3&gt;
Install Apache with SSL/TLS&lt;/h3&gt;
View all available Apache installation and configuration options as shown below.&lt;br /&gt;

&lt;pre&gt;cd httpd-2.4.2
./configure --help&lt;/pre&gt;
To install an Apache module, you would typically say 
–enable-{module-name}. For example, to install SSL with Apache, it is 
–enable-ssl. To install ldap module, it is –enable-ldap.&lt;br /&gt;

To uninstall any default module that comes with Apache, you would 
typically say –disable-{module-name}. For example, to disable basic 
authentication in Apache, it is –disable-auth-basic&lt;br /&gt;

In this example, we will install Apache with all default modules, 
with addition of –enable-ssl (to install mod_ssl for SSL support), and 
–enable-so, which helps to load modules in Apache during run-time via 
the Dynamic Shared Object (DSO) mechanism, rather than requiring a 
recompilation.&lt;br /&gt;

&lt;pre&gt;./configure --enable-ssl --enable-so
make
make install&lt;/pre&gt;
Note: By default the above installs Apache under /usr/local/apache2. 
If you like to change this location, use –prefix option in the 
./configure.&lt;br /&gt;

&lt;h3&gt;
Fixing APR Utility Error Messages&lt;/h3&gt;
You might’ve not faced this problem while &lt;a href=&quot;http://www.thegeekstuff.com/2008/07/install-apache-2-from-source-on-linux/&quot;&gt;installing older version of Apache&lt;/a&gt; as we discussed a while back.&lt;br /&gt;

When you execute the “make”, you might get “&lt;strong&gt;rotatelogs.c:(.text+0x5ed): undefined reference to `apr_file_link’&lt;/strong&gt;” error message if you are doing this on CentOS 6.2 as shown below.&lt;br /&gt;

&lt;pre&gt;# make
rotatelogs.c:298: warning: implicit declaration of function âapr_file_linkâ
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -std=gnu99 -pthread
-o rotatelogs  rotatelogs.lo /usr/lib64/libaprutil-1.la -ldb-4.7 -lexpat -ldb-4.7 /usr/lib64/libapr-1.la -lpthread
rotatelogs.o: In function `post_rotate&#39;:
rotatelogs.c:(.text+0x5ed): undefined reference to `apr_file_link&#39;
collect2: ld returned 1 exit status
make[2]: *** [rotatelogs] Error 1
make[2]: Leaving directory `/usr/src/httpd-2.4.2/support&#39;
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/src/httpd-2.4.2/support&#39;
make: *** [all-recursive] Error 1&lt;/pre&gt;
This is because on CentOS 6, the latest APR version available through yum installation is 1.3.9 as shown below.&lt;br /&gt;

&lt;pre&gt;# rpm -qa apr*
apr-1.3.9-3.el6_1.2.x86_64
apr-util-1.3.9-3.el6_0.1.x86_64&lt;/pre&gt;
However, Apache 2.4.2 needs the latest version of APR (which is currently 1.4.6).&lt;br /&gt;

So, go to &lt;a href=&quot;http://apr.apache.org/download.cgi&quot;&gt;APR download page&lt;/a&gt; and download both apr and apr-util.&lt;br /&gt;

&lt;pre&gt;cd /usr/src
wget http://mirror.atlanticmetro.net/apache//apr/apr-1.4.6.tar.gz
wget http://mirror.atlanticmetro.net/apache//apr/apr-util-1.4.1.tar.gz
tar xvfz apr-1.4.6.tar.gz
tar xvfz apr-util-1.4.1.tar.gz&lt;/pre&gt;
Now, you should place this new version of apr and apr-util 
directories (without the version name in the directory) under “srclib” 
directory located under the httpd-2.4.2 directory that was created when 
you uncompressed the downloaded apache software.&lt;br /&gt;

In my example, I downloaded the httpd-2.4.2.tar.gz and uncompressed 
it under /usr/src. So, I need to place the latest apr and apr-util under
 this directory.&lt;br /&gt;

&lt;pre&gt;mv apr-1.4.6 /usr/src/httpd-2.4.2/srclib/apr
mv apr-util-1.4.1 /usr/src/httpd-2.4.2/srclib/apr-util&lt;/pre&gt;
After this is done, we need to configure and make it again. If you 
execute the ./configure –help, you’ll see the following options that are
 related to APR&lt;br /&gt;

&lt;pre&gt;# cd /usr/src/httpd-2.4.2
# ./configure --help
  --with-included-apr     Use bundled copies of APR/APR-Util
  --with-apr=PATH         prefix for installed APR or the full path to apr-config
  --with-apr-util=PATH    prefix for installed APU or the full path to apu-config&lt;/pre&gt;
If you decide to install the apr-1.4.6 and apr-util-1.4.1 on your 
system, you need to use “–with-apr” and “–with-apr-util” and provide the
 path where you installed these utility.&lt;br /&gt;

In this example, we didn’t do that. i.e We didn’t install the apr and
 apr-util that we downloaded. Instead we placed them under the 
httpd-2.4.2/srclib/apr-util. So, we should use “–with-included-apr” in 
the ./configure which will use these apr and apr-util only for the 
apache compilation and installation.&lt;br /&gt;

So, let us re-do the ./configure (using –with-included-apr), make and make install as shown below.&lt;br /&gt;

&lt;pre&gt;./configure --enable-ssl --enable-so --with-included-apr
make
make install&lt;/pre&gt;
Now, make will not give “rotatelogs.c:(.text+0x5ed): undefined reference to `apr_file_link” error message anymore.&lt;br /&gt;

&lt;h3&gt;
Enable SSL in httpd.conf&lt;/h3&gt;
Apache configuration file httpd.conf is located under /usr/local/apache2/conf.&lt;br /&gt;

Uncomment the httpd-ssl.conf Include line and the LoadModule ssl_module line in the /usr/local/apache2/conf/httpd.conf file.&lt;br /&gt;

&lt;pre&gt;# vi /usr/local/apache2/conf/httpd.conf
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf&lt;/pre&gt;
View the httpd-ssl.conf to review all the default SSL configurations.
 For most cases, you don’t need to modify anything in this file.&lt;br /&gt;

&lt;pre&gt;# vi /usr/local/apache2/conf/extra/httpd-ssl.conf&lt;/pre&gt;
The SSL certificate and key are required before we start the Apache. 
The server.crt and server.key file mentioned in the httpd-ssl.conf needs
 to be created before we move forward.&lt;br /&gt;

&lt;pre&gt;# cd /usr/local/apache2/conf/extra
# egrep &#39;server.crt|server.key&#39; httpd-ssl.conf
SSLCertificateFile &quot;/usr/local/apache2/conf/server.crt&quot;
SSLCertificateKeyFile &quot;/usr/local/apache2/conf/server.key&quot;&lt;/pre&gt;
&lt;h3&gt;
Create server.crt and server.key file&lt;/h3&gt;
First, Generate the server.key using openssl.&lt;br /&gt;

&lt;pre&gt;# cd /usr/src
# openssl genrsa -des3 -out server.key 1024&lt;/pre&gt;
The above command will ask for the password. Make sure to remember 
this password. You need this while starting your Apache later.&lt;br /&gt;

Next, generate a certificate request file (server.csr) using the above server.key file.&lt;br /&gt;

&lt;pre&gt;# openssl req -new -key server.key -out server.csr&lt;/pre&gt;
Finally, generate a self signed ssl certificate (server.crt) using the above server.key and server.csr file.&lt;br /&gt;

&lt;pre&gt;# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt&lt;/pre&gt;
After you’ve done with the above steps, you’ll see the following three files under /usr/src&lt;br /&gt;

&lt;pre&gt;# ls server*
server.crt  server.csr  server.key&lt;/pre&gt;
Copy the server.key and server.crt file to appropriate Apache configuration directory location.&lt;br /&gt;

&lt;pre&gt;cp server.key /usr/local/apache2/conf/
cp server.crt /usr/local/apache2/conf/&lt;/pre&gt;
&lt;h3&gt;
Start the Apache&lt;/h3&gt;
If you are getting the below error message, make sure to uncomment the line shown below in httpd.conf&lt;br /&gt;

&lt;pre&gt;# /usr/local/apache2/bin/apachectl start
AH00526: Syntax error on line 51 of /usr/local/apache2/conf/extra/httpd-ssl.conf:
Invalid command &#39;SSLCipherSuite&#39;, perhaps misspelled or defined by a module not included in the server configuration

# vi /usr/local/apache2/conf/httpd.conf
LoadModule ssl_module modules/mod_ssl.so&lt;/pre&gt;
If you are getting the below error message, make sure to uncomment the line shown below in httpd.conf&lt;br /&gt;

&lt;pre&gt;# /usr/local/apache2/bin/apachectl start
AH00526: Syntax error on line 76 of /usr/local/apache2/conf/extra/httpd-ssl.conf:
SSLSessionCache: &#39;shmcb&#39; session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).

# vi /usr/local/apache2/conf/httpd.conf
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so&lt;/pre&gt;
Finally, this will prompt you to enter the password for your private key before starting up the apache.&lt;br /&gt;

&lt;pre&gt;# /usr/local/apache2/bin/apachectl start
Apache/2.4.2 mod_ssl (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.

Server www.example.com:443 (RSA)
Enter pass phrase:

OK: Pass Phrase Dialog successful.&lt;/pre&gt;
Verify that the Apache httpd process is running in the background&lt;br /&gt;

&lt;pre&gt;# ps -ef | grep http
root   29529     1  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 29530 29529  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 29531 29529  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 29532 29529  0 13:08 ?     00:00:00 /usr/local/apache2/bin/httpd -k start
root   29616 18260  0 13:09 pts/0 00:00:00 grep http&lt;/pre&gt;
To stop the apache use apachectl stop.&lt;br /&gt;

&lt;pre&gt;# /usr/local/apache2/bin/apachectl stop&lt;/pre&gt;
Use httpd -l to view all the modules that are compiled inside the Apache httpd daemon.&lt;br /&gt;

&lt;pre&gt;# /usr/local/apache2/bin/httpd -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c
  event.c&lt;/pre&gt;
By default Apache SSL runs on 443 port. Open a web browser and verify
 that you can access your Apache using https://{your-ip-address}&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/2318660217222067551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-install-apache-242-from-source.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/2318660217222067551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/2318660217222067551'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-install-apache-242-from-source.html' title='How to Install Apache 2.4.2 from Source on CentOS 6.2 with SSL'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-1797812141305128212</id><published>2012-05-10T14:33:00.001-07:00</published><updated>2012-05-10T14:33:45.435-07:00</updated><title type='text'>How Traceroute Works</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
There are scenarios in which one would like to know the route which a
 connection follows. By route here we mean the IP addresses of all the 
forwarding entities (like routers in between).&lt;br /&gt;

Although there is no guarantee that the route will remain same for 
all the packets of a connection but usually it is same. This route 
related information can be very handy while debugging network related 
issues.&lt;br /&gt;
&lt;span id=&quot;more-10404&quot;&gt;&lt;/span&gt;&lt;br /&gt;
traceroute utility prints out complete route to a particular 
destination. In this article we will discuss how traceroute works and 
will see some practical examples.&lt;br /&gt;

&lt;h3&gt;
How Traceroute Works?&lt;/h3&gt;
Before beginning with examples, lets understand the concept on which traceroute works.&lt;br /&gt;

Traceroute utility uses the TTL field in the IP header to achieve its
 operation. For users who are new to TTL field, this field describes how
 much hops a particular packet will take while traveling on network.&lt;br /&gt;

So, this effectively outlines the lifetime of the packet on network. 
This field is usually set to 32 or 64. Each time the packet is held on 
an intermediate router, it decreases the TTL value by 1. When a router 
finds the TTL value of 1 in a received packet then that packet is not 
forwarded but instead discarded.&lt;br /&gt;

After discarding the packet, router sends an ICMP error message of 
“Time exceeded” back to the source from where packet generated. The ICMP
 packet that is sent back contains the IP address of the router.&lt;br /&gt;

So now it can be easily understood that traceroute operates by 
sending packets with TTL value starting from 1 and then incrementing by 
one each time. Each time a router receives the packet, it checks the TTL
 field, if TTL field is 1 then it discards the packet and sends the ICMP
 error packet containing its IP address and this is what traceroute 
requires. So traceroute incrementally fetches the IP of all the routers&amp;nbsp;
 between the source and the destination.&lt;br /&gt;

You should also understand the &lt;a href=&quot;http://www.thegeekstuff.com/2012/03/ip-protocol-header/&quot;&gt;IP header fields&lt;/a&gt; that we discussed a while back.&lt;br /&gt;

&lt;h3&gt;
Traceroute Examples&lt;/h3&gt;
&lt;h3&gt;
1. How to run traceroute?&lt;/h3&gt;
&lt;pre&gt;$ traceroute &amp;lt;server-name&amp;gt;&lt;/pre&gt;
The server-name above is the destination name or IP address.&amp;nbsp; For 
example, traceroute is used to find the network path from my machine to 
google.com :&lt;br /&gt;

&lt;pre&gt;$ traceroute google.com
traceroute to google.com (74.125.236.132), 30 hops max, 60 byte packets
1&amp;nbsp; 220.224.141.129 (220.224.141.129)&amp;nbsp; 89.174 ms&amp;nbsp; 89.094 ms&amp;nbsp; 89.054 ms
2&amp;nbsp; 115.255.239.65 (115.255.239.65)&amp;nbsp; 109.037 ms&amp;nbsp; 108.994 ms&amp;nbsp; 108.963 ms
3&amp;nbsp; 124.124.251.245 (124.124.251.245)&amp;nbsp; 108.937 ms&amp;nbsp; 121.322 ms&amp;nbsp; 121.300 ms
4&amp;nbsp; * 115.255.239.45 (115.255.239.45)&amp;nbsp; 113.754 ms&amp;nbsp; 113.692 ms
5&amp;nbsp; 72.14.212.118 (72.14.212.118)&amp;nbsp; 123.585 ms&amp;nbsp; 123.558 ms&amp;nbsp; 123.527 ms
6&amp;nbsp; 72.14.232.202 (72.14.232.202)&amp;nbsp; 123.499 ms&amp;nbsp; 123.475 ms&amp;nbsp; 143.523 ms
7&amp;nbsp; 216.239.48.179 (216.239.48.179)&amp;nbsp; 143.503 ms&amp;nbsp; 95.106 ms&amp;nbsp; 95.026 ms
8&amp;nbsp; bom03s02-in-f4.1e100.net (74.125.236.132)&amp;nbsp; 94.980 ms&amp;nbsp; 104.989 ms&amp;nbsp; 104.954 ms&lt;/pre&gt;
Each lines gives the details of interaction with each router 
encountered. So we see that traceroute not only gives the IP addresses 
of the intermediate routers but also three round trip times for that 
particular router as for each router the traceroute commands fires three
 packets.&lt;br /&gt;

&lt;h4&gt;
The ‘*’ field in output&lt;/h4&gt;
There are times when one could encounter an ‘*’ in the output rather 
than a value. This depicts that the required field could not be fetched.
 The reason can be anything from reverse DNS lookup failure to packets 
not hitting the target router to packets getting lost on their way back.
 So we see that the reason could be many but for all these type of cases
 the traceroute utility provides an * in the output.&lt;br /&gt;

&lt;h3&gt;
2. Disable IP address and host name mapping&lt;/h3&gt;
Traceroute provides and option through which the mapping of IP 
addresses with host name (that traceroute tries) is disabled. The option
 for doing this is ‘-n’ . Following example illustrates it :&lt;br /&gt;

&lt;pre&gt;$ traceroute google.com -n
traceroute to google.com (173.194.36.7), 30 hops max, 60 byte packets
1&amp;nbsp; 220.224.141.129&amp;nbsp; 109.352 ms&amp;nbsp; 109.280 ms&amp;nbsp; 109.248 ms
2&amp;nbsp; 115.255.239.65&amp;nbsp; 131.633 ms&amp;nbsp; 131.598 ms&amp;nbsp; 131.573 ms
3&amp;nbsp; 124.124.251.245&amp;nbsp; 131.554 ms&amp;nbsp; 131.529 ms&amp;nbsp; 131.502 ms
4&amp;nbsp; 115.255.239.45&amp;nbsp; 131.478 ms&amp;nbsp; 131.464 ms&amp;nbsp; 199.741 ms
5&amp;nbsp; 72.14.212.118&amp;nbsp; 199.674 ms&amp;nbsp; 199.637 ms&amp;nbsp; 199.603 ms
6&amp;nbsp; 209.85.241.52&amp;nbsp; 199.578 ms&amp;nbsp; 199.549 ms&amp;nbsp; 209.838 ms
7&amp;nbsp; 209.85.241.187&amp;nbsp; 199.488 ms&amp;nbsp; 177.264 ms&amp;nbsp; 177.196 ms
8&amp;nbsp; 173.194.36.7&amp;nbsp; 177.159 ms&amp;nbsp; 187.463 ms&amp;nbsp; 187.434 ms&lt;/pre&gt;
So we see that no host name is displayed in the output.&lt;br /&gt;

&lt;h3&gt;
3. Configure Response Wait Time&lt;/h3&gt;
The time for which traceroute utility waits after issuing a probe can
 also be configured. This can be done through ‘-w’ option that it 
provides. The -w option expects a value which the utility will take as 
the response time to wait for. In this example, the wait time is 0.1 
seconds and the traceroute utility was unable to wait for any response 
and it printed all the *’s.&lt;br /&gt;

&lt;pre&gt;$ traceroute google.com -w 0.1
traceroute to google.com (74.125.236.101), 30 hops max, 60 byte packets
1&amp;nbsp; * * *
2&amp;nbsp; * * *
3&amp;nbsp; * * *
..
26&amp;nbsp; * * *
27&amp;nbsp; * * *
28&amp;nbsp; * * *
29&amp;nbsp; * * *
30&amp;nbsp; * * *&lt;/pre&gt;
So we see that traceroute tried 30 attempts (the max hop attempts) 
and then gave up as no ICMP packet was received in 0.1 seconds.&lt;br /&gt;

&lt;h3&gt;
4. Configure Number of Queries per Hop&lt;/h3&gt;
As already explained earlier, the traceroute utility sends 3 packets 
per hop to provide 3 round trip times. This default value of 3 is 
configurable using the option ‘-q’. This option expects an integer which
 it sets as new value of number of probes per hop.&lt;br /&gt;

&lt;pre&gt;$ traceroute google.com -q 5
traceroute to google.com (173.194.36.46), 30 hops max, 60 byte packets
1&amp;nbsp; 220.224.141.129 (220.224.141.129)&amp;nbsp; 91.579 ms&amp;nbsp; 91.497 ms&amp;nbsp; 91.458 ms&amp;nbsp; 91.422 ms&amp;nbsp; 91.385 ms
2&amp;nbsp; 115.255.239.65 (115.255.239.65)&amp;nbsp; 91.356 ms&amp;nbsp; 91.325 ms&amp;nbsp; 98.868 ms&amp;nbsp; 98.848 ms&amp;nbsp; 98.829 ms
3&amp;nbsp; 124.124.251.245 (124.124.251.245)&amp;nbsp; 94.581 ms&amp;nbsp; 107.083 ms&amp;nbsp; 107.044 ms&amp;nbsp; 107.017 ms&amp;nbsp; 106.981 ms
4&amp;nbsp; 115.255.239.45 (115.255.239.45)&amp;nbsp; 106.948 ms&amp;nbsp; 106.918 ms&amp;nbsp; 144.432 ms&amp;nbsp; 144.412 ms&amp;nbsp; 144.392 ms
5&amp;nbsp; 72.14.212.118 (72.14.212.118)&amp;nbsp; 115.565 ms&amp;nbsp; 115.485 ms&amp;nbsp; 115.446 ms&amp;nbsp; 115.408 ms&amp;nbsp; 115.381 ms
6&amp;nbsp; 72.14.232.202 (72.14.232.202)&amp;nbsp; 115.351 ms&amp;nbsp; 87.232 ms&amp;nbsp; 117.157 ms&amp;nbsp; 117.123 ms&amp;nbsp; 117.049 ms
7&amp;nbsp; 209.85.241.189 (209.85.241.189)&amp;nbsp; 126.998 ms&amp;nbsp; 126.973 ms&amp;nbsp; 126.950 ms&amp;nbsp; 126.929 ms&amp;nbsp; 126.912 ms
8&amp;nbsp; bom04s02-in-f14.1e100.net (173.194.36.46)&amp;nbsp; 126.889 ms&amp;nbsp; 95.526 ms&amp;nbsp; 95.450 ms&amp;nbsp; 95.418 ms&amp;nbsp; 105.392 ms&lt;/pre&gt;
So we see that after configuring the number of probes to 5, the output started showing five round trip times per hop.&lt;br /&gt;

&lt;h3&gt;
5. Configure the TTL value to start with&lt;/h3&gt;
Traceroute utility is flexible enough to accept the TTL value that 
the user wants to start the utility with. By default its value is 1 
which means it starts off with the first router in the path but using 
the ‘-f’ option (which expects the new value of TTL) a new value of the 
TTL field can be set. For example, I tried a normal traceroute operation
 and then tried a traceroute with a different TTL value.&lt;br /&gt;

&lt;pre&gt;$ traceroute google.com
traceroute to google.com (74.125.236.132), 30 hops max, 60 byte packets
1&amp;nbsp; 220.224.141.129 (220.224.141.129)&amp;nbsp; 89.181 ms&amp;nbsp; 101.540 ms&amp;nbsp; 101.503 ms
2&amp;nbsp; 115.255.239.65 (115.255.239.65)&amp;nbsp; 101.468 ms&amp;nbsp; 101.431 ms&amp;nbsp; 101.324 ms
3&amp;nbsp; 124.124.251.245 (124.124.251.245)&amp;nbsp; 121.373 ms&amp;nbsp; 121.350 ms&amp;nbsp; 158.694 ms
4&amp;nbsp; 115.255.239.45 (115.255.239.45)&amp;nbsp; 101.223 ms&amp;nbsp; 141.135 ms&amp;nbsp; 123.932 ms
5&amp;nbsp; 72.14.212.118 (72.14.212.118)&amp;nbsp; 123.867 ms&amp;nbsp; 123.832 ms&amp;nbsp; 123.802 ms
6&amp;nbsp; 72.14.232.202 (72.14.232.202)&amp;nbsp; 123.773 ms&amp;nbsp; 123.742 ms&amp;nbsp; 587.812 ms
7&amp;nbsp; 216.239.48.179 (216.239.48.179)&amp;nbsp; 587.723 ms&amp;nbsp; 587.681 ms&amp;nbsp; 587.642 ms
8&amp;nbsp; bom03s02-in-f4.1e100.net (74.125.236.132)&amp;nbsp; 577.548 ms&amp;nbsp; 577.524 ms&amp;nbsp; 587.512 ms

$ traceroute google.com -f 8
traceroute to google.com (74.125.236.129), 30 hops max, 60 byte packets
8&amp;nbsp; bom03s02-in-f1.1e100.net (74.125.236.129)&amp;nbsp; 96.961 ms&amp;nbsp; 96.886 ms&amp;nbsp; 96.849 ms&lt;/pre&gt;
So we see that after using the -f option with value 8, only the last (8th) line from the previous output was shown.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/1797812141305128212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-traceroute-works.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1797812141305128212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1797812141305128212'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-traceroute-works.html' title='How Traceroute Works'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-4863109952178226363</id><published>2012-05-03T05:25:00.003-07:00</published><updated>2012-05-03T05:25:47.014-07:00</updated><title type='text'>How to add cakePHP auto-complete to netbeans</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
NetBeans is a very powerful development environment for many 
languages including PHP. With the release of its latest version, 
NetBeans announced full support for &lt;a href=&quot;http://www.symfony-project.org/&quot; target=&quot;_blank&quot; title=&quot;Symfony PHP framework official site&quot;&gt;symfony PHP framework&lt;/a&gt;.&amp;nbsp;NetBeans
 can also support many other PHP frameworks and libraries although it is
 not officially supported by NetBeans. This support needs some effort to
 enable some tools specially auto-complete, or intellisense, which saves
 a lot of time for developers.&lt;br /&gt;

We will start to make NetBeans support CakePHP. Firstly we need to create a cake project using cake command line tools.&lt;span id=&quot;more-84&quot;&gt;&lt;/span&gt;&lt;br /&gt;

&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_694935&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;1&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;functions&quot;&gt;cd&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;DOCUMENT_ROOT&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;2&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;cake bake PROJECT_NAME&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Then we need to create a NetBeans project using the create files. 
Click file &amp;gt; New Project, then choose New Project. From the window 
choose PHP from categories and from projects choose PHP Application with
 Existing Sources. Click Next then choose the project path. and click 
finish.&lt;br /&gt;

&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_87&quot; style=&quot;width: 457px;&quot;&gt;
&lt;a href=&quot;http://www.tiplite.com/wp-content/uploads/2010/02/netbeans_new_project.jpg&quot;&gt;&lt;img alt=&quot;NetBeans new project dialog&quot; class=&quot;size-full wp-image-87 &quot; height=&quot;321&quot; src=&quot;http://www.tiplite.com/wp-content/uploads/2010/02/netbeans_new_project.jpg&quot; title=&quot;NetBeans New Project Dialog&quot; width=&quot;447&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;wp-caption-text&quot;&gt;
NetBeans New Project Dialog&lt;/div&gt;
&lt;/div&gt;
After the project is created select the project in the Projects pane 
and right click Include Path. Click add folder and choose cake library 
path and add it. NetBeans will scan and add the library to its internal 
library.&lt;br /&gt;

&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_88&quot; style=&quot;width: 417px;&quot;&gt;
&lt;a href=&quot;http://www.tiplite.com/wp-content/uploads/2010/02/netbeans_php_include_path.jpg&quot;&gt;&lt;img alt=&quot;NetBeans PHP include path dialog&quot; class=&quot;size-full wp-image-88 &quot; height=&quot;276&quot; src=&quot;http://www.tiplite.com/wp-content/uploads/2010/02/netbeans_php_include_path.jpg&quot; title=&quot;netbeans_php_include_path&quot; width=&quot;407&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;wp-caption-text&quot;&gt;
NetBeans PHP include path dialog&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 20px auto; text-align: center;&quot;&gt;
&lt;br /&gt;
&lt;ins style=&quot;border: none; display: inline-table; height: 60px; margin: 0; padding: 0; position: relative; visibility: visible; width: 468px;&quot;&gt;&lt;ins id=&quot;aswift_0_anchor&quot; style=&quot;border: none; display: block; height: 60px; margin: 0; padding: 0; position: relative; visibility: visible; width: 468px;&quot;&gt;&lt;/ins&gt;&lt;/ins&gt;
&lt;/div&gt;
Now you will have auto-complete working in your controllers, models, 
controllers, behaviors and helpers files. This will happen because 
NetBeans is smart enough to know that your inheriting AppController, 
AppModel,...etc which in turn inherits Controller and Model classes 
which is found in CakePHP library directory which NetBeans just scanned.
 But till now we don&#39;t have support for models and components included 
magically by CakePHP in controllers and models. To make NetBeans 
identifies those variables we will use PHPDoc trick. In your model or 
controller add a variable with the same name of your model or any other 
model you want, but make sure it is loaded as this will not include your
 model.&lt;br /&gt;

&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_108286&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;ProductsController &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;extends&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;AppController{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;02&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;var&lt;/code&gt; &lt;code class=&quot;variable&quot;&gt;$name&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;= &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;Products&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;03&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;04&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;comments&quot;&gt;/**&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;05&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;comments&quot;&gt;* @var Product&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;06&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;comments&quot;&gt;*/&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;07&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;var&lt;/code&gt; &lt;code class=&quot;variable&quot;&gt;$Product&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;08&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;09&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;comments&quot;&gt;/**&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;10&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;comments&quot;&gt;* @var EmailComponent&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;11&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;comments&quot;&gt;*/&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;12&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;var&lt;/code&gt; &lt;code class=&quot;variable&quot;&gt;$Email&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;13&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
You will notice that NetBeans enables auto-complete even in comments.
 Just hit Ctrl + Space when writing the name of any class. This will 
work with associated models in a model class.&lt;br /&gt;

Now you will notice that your CakePHP work is much more easier, but 
we still have auto-complete is not working in views. This problem can be
 solved using NetBeans feature which enables us to define a variable&#39;s 
type using comments. I call this feature var-doc or variable type 
notice. Just write a comment like this before any variable. You even can
 make this with &lt;code class=&quot;brush:php&quot;&gt;$this&lt;/code&gt; variable to define the class you are working with as &lt;code class=&quot;brush:php&quot;&gt;View&lt;/code&gt; class.&lt;br /&gt;

&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_953910&quot;&gt;
&lt;div class=&quot;lines&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;1&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;comments&quot;&gt;/* @var $this View */&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;2&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;comments&quot;&gt;/* @var $html HtmlHelper */&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;3&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;comments&quot;&gt;/* @var $javascript JavascriptHelper */&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;4&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;.....&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
This way you can have auto-complete support for your views and 
helpers included in views and you will notice that NetBeans also has 
support for your classes in comments.&lt;br /&gt;

At last the only thing that I couldn&#39;t have support for is behaviors 
methods&amp;nbsp;which can be called from a model&#39;s instances if you now a way to
 do this please tell me. But we are waiting for more from NetBeans which
 has introduced too much for us, PHP Developers.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/4863109952178226363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-add-cakephp-auto-complete-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4863109952178226363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4863109952178226363'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-add-cakephp-auto-complete-to.html' title='How to add cakePHP auto-complete to netbeans'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-5982662537684848177</id><published>2012-05-01T21:25:00.003-07:00</published><updated>2012-05-01T22:58:09.484-07:00</updated><title type='text'>How to fix ubuntu high CPU temperature</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There is a common problem with some 
laptop owners&amp;nbsp; with Ubuntu OS installed on their laptops to have high 
CPU heat issues. Especially after heavy load of applications running 
(especially 3D/Multimedia/Webcam applications), CPU temperature may rise
 through 70-80 celcius degrees. And that is a real dangerous and 
critical situation for hardware health.&amp;nbsp; Dynamic CPU function at Ubuntu 
or the lack of hardware driver support that manufacturers share for 
Linux is causing that issue according to talks at Ubuntu Community 
Forums.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There are lots of complains 
about that situation and most of em were reported to Ubuntu developers 
but unfortunately yet Ubuntu has not shared any fix against that. 
Fortunately there is a solution for that.&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=5762064040393208356&quot; name=&quot;more&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Well this does not guarantee solving 
your heat issues but at least this solution worked for a lot of users 
(check Ubuntu community forums).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
First of all be sure about that 
your laptop fans and components are cleaned because most of the cpu heat
 issues are related with that.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you think that Ubuntu is the 
reason that causes the problem then you can try this solution. It worked
 for my Dell Inspiron N5010 laptop.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1) To monitor you cpu and other other components, install lm-sensors;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Open the terminal. &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #cc0000; text-align: justify;&quot;&gt;
&lt;i&gt;      sudo apt-get install lm-sensors&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
After that ;&lt;/div&gt;
&lt;div style=&quot;color: #cc0000; text-align: justify;&quot;&gt;
&lt;i&gt;sensors-detect&amp;nbsp;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
and type Y to all questions, so it is going to install some modules to your kernel.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
By typing&lt;i style=&quot;color: #cc0000;&quot;&gt; sensors&lt;/i&gt; you can monitor your components.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2) Instal six important modules to fix your heat issue;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Open the terminal.&lt;/div&gt;
&lt;div style=&quot;color: #cc0000; text-align: justify;&quot;&gt;
&lt;i&gt;sudo gedit /etc/modules&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Then add those lines save the editor and close;&lt;/div&gt;
&lt;div style=&quot;color: #cc0000; text-align: justify;&quot;&gt;
&lt;i&gt;#added to fix heat issue&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;color: #cc0000; text-align: justify;&quot;&gt;
&lt;i&gt;battery&lt;br /&gt;
ac&lt;br /&gt;
thermal&lt;br /&gt;
processor&lt;br /&gt;
acpi-cpufreq&lt;br /&gt;
cpufreq-userspace&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
3) Restart Ubuntu and check the temperature values again by &lt;i&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;sensors&lt;/span&gt;&lt;/i&gt; command.&lt;br /&gt;
&lt;br /&gt;
4) Try updating your hardware drivers. (Especially graphics card drivers)&lt;br /&gt;
&lt;br /&gt;
If this does not solve your problem, avoid using Ubuntu till a solution 
for that appears. Because it may cause unfixable damages to your 
hardware.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/5982662537684848177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/ho-wto-fix-ubuntu-high-cpu-temperature.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/5982662537684848177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/5982662537684848177'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/ho-wto-fix-ubuntu-high-cpu-temperature.html' title='How to fix ubuntu high CPU temperature'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-4205773544524185822</id><published>2012-05-01T21:23:00.000-07:00</published><updated>2012-05-01T21:57:50.673-07:00</updated><title type='text'>How to add wordpress Uploader to plugins</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
WordPress has a nice media uploader dialog that it uses on the editor  pages. Now wouldn’t it be nice if you could use it to handle image  uploads for part of a plugin or theme you’re writing? Maybe you want to  add an easy way to change the logo in a theme? A simple “Upload Image”  button would work quite well for that, wouldn’t it?&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-2906 imgborder&quot; height=&quot;324&quot; src=&quot;http://media.webmaster-source.com/wp-content/uploads/wordpress-uploader-dialog.jpg&quot; title=&quot;WordPress Uploader Dialog&quot; width=&quot;415&quot; /&gt;&lt;/div&gt;
It’s fairly simple to implement, providing you already have a bit of experience with the WordPress API.&lt;br /&gt;
The first step is to prepare your HTML. Put it wherever the code for your &lt;a href=&quot;http://codex.wordpress.org/Adding_Administration_Menus&quot;&gt;admin page&lt;/a&gt; is. You want to have a text input for the image URL, and a button that will launch the uploader dialog.&lt;span id=&quot;more-2905&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_822237&quot;&gt;
&lt;div class=&quot;lines no-wrap&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;tr&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;valign&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;top&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;th&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;scope&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;row&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;Upload Image&amp;lt;/&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;th&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;code&gt;
&lt;/code&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;td&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;label&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;for&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;upload_image&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;input&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;id&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;upload_image&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;type&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;text&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;size&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;36&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;name&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;upload_image&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;value&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;&quot;&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;/&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;input&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;id&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;upload_image_button&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;type&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;button&quot;&lt;/code&gt; &lt;code class=&quot;color1&quot;&gt;value&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;=&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;Upload Image&quot;&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;/&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;br&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;/&amp;gt;Enter an URL or upload an image for the banner.&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;/&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;label&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&amp;lt;/&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;td&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;/&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;tr&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
Now that the easy part is out of the way, it’s time to start making it &lt;i&gt;do&lt;/i&gt; something. You need to enqueue some scripts and styles. Here’s an example function to show how it’s done:&lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_370046&quot;&gt;
&lt;div class=&quot;lines no-wrap&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;my_admin_scripts() {&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;wp_enqueue_script(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;media-upload&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;wp_enqueue_script(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;thickbox&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;wp_register_script(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;my-upload&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, WP_PLUGIN_URL.&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;/my-script.js&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;array&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;jquery&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;,&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;media-upload&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;,&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;thickbox&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;));&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;wp_enqueue_script(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;my-upload&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;my_admin_styles() {&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;wp_enqueue_style(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;thickbox&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword&quot;&gt;if&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;(isset(&lt;/code&gt;&lt;code class=&quot;variable&quot;&gt;$_GET&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;[&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;page&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;]) &amp;amp;&amp;amp; &lt;/code&gt;&lt;code class=&quot;variable&quot;&gt;$_GET&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;[&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;page&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;] == &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;my_plugin_page&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;) {&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;admin_print_scripts&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;my_admin_scripts&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;add_action(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;admin_print_styles&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;my_admin_styles&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
We need the &lt;i&gt;media-upload&lt;/i&gt; and &lt;i&gt;thickbox&lt;/i&gt; scripts for  starters, as well as jQuery, which is already included. Then we have to  register and enqueue our own JavaScript file, &lt;i&gt;my-script.js&lt;/i&gt;, which will handle the media uploader functionality. We also need to load the &lt;i&gt;thickbox&lt;/i&gt; stylesheet in the next function.&lt;br /&gt;
The &lt;i&gt;if (…)&lt;/i&gt; block ensures that the scripts and styles will  only be included if the user is on a specific admin page. If you look at  your plugin’s (or theme’s) admin page, the URL should have a &lt;i&gt;?page=some_string&lt;/i&gt; at the end. Substitute &lt;i&gt;my_plugin_page&lt;/i&gt; for that string.&lt;br /&gt;
Now for the part the actually invokes the uploader: the JavaScript. This will go in the my-script.js file we included earlier.&lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_381024&quot;&gt;
&lt;div class=&quot;lines no-wrap&quot;&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;jQuery(document).ready(&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;function&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;() {&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;jQuery(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;#upload_image_button&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;).click(&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;function&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;() {&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;formfield = jQuery(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;#upload_image&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;).attr(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;name&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;tb_show(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;media-upload.php?type=image&amp;amp;amp;TB_iframe=true&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;keyword&quot;&gt;false&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;});&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;window.send_to_editor = &lt;/code&gt;&lt;code class=&quot;keyword&quot;&gt;function&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;(html) {&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;imgurl = jQuery(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;img&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;,html).attr(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;src&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;jQuery(&lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&#39;#upload_image&#39;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;).val(imgurl);&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;tb_remove();&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt2&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;line alt1&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;});&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
The first &lt;i&gt;click()&lt;/i&gt; event listener opens a ThickBox dialog  when the “Upload Image” button is clicked, and loads the uploader page  inside it. It also stores the name of the URL input field in a variable,  for later use.&lt;br /&gt;
The second function overrides the &lt;i&gt;send_to_editor()&lt;/i&gt; function in the &lt;i&gt;media-upload&lt;/i&gt;  script. This is probably the most important part. When the “Insert into  Post” button is clicked in the uploader dialog, this function fires. It  collects the URL of the image that was uploaded, dumps it into the  awaiting form field, and closes the ThickBox dialog.&lt;br /&gt;
That’s it. Providing everything went according to planned, you should  have a form field that will either accept an arbitrary image URL, or  allow a user to upload one on the spot.&lt;br /&gt;
&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-2907&quot; height=&quot;67&quot; src=&quot;http://media.webmaster-source.com/wp-content/uploads/wordpress-upload-field.jpg&quot; title=&quot;WordPress Media Uploader Field&quot; width=&quot;414&quot; /&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/4205773544524185822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-add-wordpress-uploader-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4205773544524185822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/4205773544524185822'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/05/how-to-add-wordpress-uploader-to.html' title='How to add wordpress Uploader to plugins'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-1667943022485847702</id><published>2012-04-20T04:06:00.002-07:00</published><updated>2012-04-20T04:06:26.151-07:00</updated><title type='text'>how to Strip filename from a URL with php</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Using PHP, you might need to strip the path from a URL, leaving  behind just the filename at the end of the URL. You can achieve this  with a regular expression pattern of course, but I have a much simpler  solution. See the example code below.&lt;br /&gt;
&lt;span id=&quot;more-34&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;dean_ch&quot; style=&quot;white-space: nowrap;&quot;&gt;&lt;span class=&quot;re0&quot;&gt;$url&lt;/span&gt; = &lt;span class=&quot;st0&quot;&gt;&quot;http://www.domain.com/path/to/file/filename.php&quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span class=&quot;re0&quot;&gt;$filename&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/basename&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;basename&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$url&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;;&lt;br /&gt;
&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;re0&quot;&gt;$filename&lt;/span&gt;; &lt;span class=&quot;co1&quot;&gt;//filename.php&lt;/span&gt;&lt;/div&gt;And that’s all there is to it. I hope that you found this useful.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/1667943022485847702/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-strip-filename-from-url-with-php.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1667943022485847702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1667943022485847702'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-strip-filename-from-url-with-php.html' title='how to Strip filename from a URL with php'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-7245903200799789539</id><published>2012-04-20T03:50:00.002-07:00</published><updated>2012-04-20T03:50:50.798-07:00</updated><title type='text'>How to replace all instances of a character in a string with  Javascript</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;votecell&quot;&gt;          &lt;/td&gt;   &lt;td class=&quot;answercell&quot;&gt;     &lt;div class=&quot;post-text&quot;&gt;The easiest would be to use a regular expression with &lt;em&gt;g&lt;/em&gt; flag to replace all instances:&lt;br /&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;/foo/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;This will replace all occurrences. If you just have a string, you can convert it to a RegExp object like this:&lt;br /&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwd&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; pattern &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;foobar&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;
&amp;nbsp; &amp;nbsp; re &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kwd&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;RegExp&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;pattern&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;g&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/7245903200799789539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-replace-all-instances-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/7245903200799789539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/7245903200799789539'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-replace-all-instances-of.html' title='How to replace all instances of a character in a string with  Javascript'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-633373212133259402</id><published>2012-04-20T03:49:00.000-07:00</published><updated>2012-04-20T03:49:39.447-07:00</updated><title type='text'>how to to add options to a select from an array with jQuery</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;votecell&quot;&gt;          &lt;/td&gt;   &lt;td class=&quot;answercell&quot;&gt;     &lt;div class=&quot;post-text&quot;&gt;Using &lt;a href=&quot;http://plugins.jquery.com/project/DOMEC&quot; rel=&quot;nofollow&quot;&gt;DOM Elements Creator plugin&lt;/a&gt; :&lt;br /&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;option&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;value&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;val&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;myText&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;appendTo&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;#mySelect&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;Using the &lt;code&gt;Option&lt;/code&gt; constructor (not sure about browser support):&lt;br /&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kwd&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Option&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;myText&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;val&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;appendTo&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;#mySelect&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;Using &lt;code&gt;document.createElement&lt;/code&gt; (avoiding extra work parsing HTML with &lt;code&gt;$(&quot;&amp;lt;option&amp;gt;&amp;lt;/option&amp;gt;&quot;)&lt;/code&gt;):&lt;br /&gt;
&lt;pre class=&quot;default prettyprint&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;#mySelect&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;option&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;value&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;val&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;myText&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;));&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/633373212133259402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-to-add-options-to-select-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/633373212133259402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/633373212133259402'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-to-add-options-to-select-from.html' title='how to to add options to a select from an array with jQuery'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-2359344177222477277</id><published>2012-04-20T03:48:00.000-07:00</published><updated>2012-04-20T03:48:09.305-07:00</updated><title type='text'>how to Find base name in URL in Javascript</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Simply use this regex :&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;/^.*\/|\.[^.]*$/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td class=&quot;answercell&quot;&gt;&lt;br /&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/2359344177222477277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-find-base-name-in-url-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/2359344177222477277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/2359344177222477277'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-find-base-name-in-url-in.html' title='how to Find base name in URL in Javascript'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-6376188686216068885</id><published>2012-04-17T06:48:00.000-07:00</published><updated>2012-04-17T06:48:40.421-07:00</updated><title type='text'>how to fix PHP Fatal error: Class ‘DOMDocument’ not found</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;from the tail -f /var/log/httpd/error&lt;br /&gt;
&lt;code&gt;[Tue Mar 10 16:01:30 2009] [error] [client 127.0.0.1] PHP Fatal  error:  Class &#39;DOMDocument&#39; not found in /home/namran/src/....php on  line 15, referer: http://...&lt;/code&gt;&lt;br /&gt;
&lt;a class=&quot;fancybox&quot; href=&quot;http://blog.namran.net/wp-content/uploads/2009/03/dom-not-found2.png&quot; rel=&quot;fancybox&quot; title=&quot;dom-not-found2&quot;&gt;&lt;img alt=&quot;dom-not-found2&quot; class=&quot;alignnone size-medium wp-image-1209&quot; height=&quot;15&quot; src=&quot;http://blog.namran.net/wp-content/uploads/2009/03/dom-not-found2-300x15.png&quot; title=&quot;dom-not-found2&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
the solution turn out to be &lt;br /&gt;
&lt;code&gt;yum install php-xml&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;img alt=&quot;complete-php-xml&quot; class=&quot;alignnone size-full wp-image-1210&quot; height=&quot;458&quot; src=&quot;http://blog.namran.net/wp-content/uploads/2009/03/complete-php-xml.png&quot; title=&quot;complete-php-xml&quot; width=&quot;668&quot; /&gt; &lt;br /&gt;
&lt;div class=&quot;fblike_button&quot; style=&quot;margin: 10px 0;&quot;&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/6376188686216068885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-fix-php-fatal-error-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/6376188686216068885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/6376188686216068885'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-to-fix-php-fatal-error-class.html' title='how to fix PHP Fatal error: Class ‘DOMDocument’ not found'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-8228060887923237969</id><published>2012-04-07T06:13:00.004-07:00</published><updated>2012-04-11T03:23:19.421-07:00</updated><title type='text'>How do I Find Out Linux CPU Utilization?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Whenever a Linux system CPU is occupied by a process, it is  unavailable for processing other requests.  Rest of pending requests  must wait till CPU is free. This becomes a bottleneck in the system.  Following command will help you to identify CPU utilization, so that you  can troubleshoot CPU related performance problems.&lt;br /&gt;
Finding CPU  utilization is one of the important tasks. Linux comes with various  utilities to report CPU utilization. With these commands, you will be  able to find out:&lt;br /&gt;
*  CPU utilization&lt;br /&gt;
*  Display the utilization of each CPU individually (SMP cpu)&lt;br /&gt;
*  Find out your system&#39;s average CPU utilization since the last reboot etc&lt;br /&gt;
*  Determine which process is eating the CPU(s)&lt;br /&gt;
&lt;h3&gt;Old good top command to find out Linux cpu load&lt;/h3&gt;The  top program provides a dynamic real-time view of a running system. It  can display system summary information as well as a list of tasks  currently being managed by the Linux kernel.&lt;br /&gt;
The top command  monitors CPU utilization, process statistics, and memory utilization.  The top section contains information related to overall system status -  uptime, load average, process counts, CPU status, and utilization  statistics for both memory and swap space.&lt;br /&gt;
&lt;h4&gt;Top command to find out Linux cpu usage&lt;/h4&gt;Type the top command:&lt;br /&gt;
&lt;code&gt;$ top&lt;/code&gt;&lt;br /&gt;
Output:&lt;br /&gt;
&lt;a href=&quot;http://www.cyberciti.biz/nixcraft/vivek/blogger/uploaded_images/linux-cpu-utilization-780043.png&quot;&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
You  can see Linux CPU utilization under CPU stats. The task’s share of the  elapsed CPU time since the last screen update, expressed as a percentage  of total CPU time. In a true SMP environment (multiple CPUS), top will  operate in number of CPUs. Please note that you need to type q key to  exit the top command display.&lt;br /&gt;
The top command produces a  frequently-updated list of processes. By default, the processes are  ordered by percentage of CPU usage, with only the &quot;top&quot; CPU consumers  shown. The top command shows how much processing power and memory are  being used, as well as other information about the running processes.&lt;br /&gt;
&lt;h3&gt;Find Linux CPU utilization using mpstat and other tools&lt;/h3&gt;Please note that you need to install special package called &lt;b&gt;sysstat&lt;/b&gt;  to take advantage of following commands. This package includes system  performance tools for Linux (Red Hat Linux / RHEL includes these tools  by default).&lt;br /&gt;
&lt;code&gt;# apt-get install sysstat&lt;/code&gt;&lt;br /&gt;
Use up2date command if you are using RHEL:&lt;br /&gt;
&lt;code&gt;# up2date sysstat&lt;/code&gt;&lt;br /&gt;
&lt;h3&gt;Display the utilization of each CPU individually using mpstat&lt;/h3&gt;If  you are using SMP (Multiple CPU) system,  use mpstat command to display  the utilization of each CPU individually. It report processors related  statistics. For example, type command:&lt;br /&gt;
&lt;code&gt;# mpstat &lt;/code&gt;Output:&lt;br /&gt;
&lt;pre&gt;Linux 2.6.15.4 (debian)         Thursday 06 April 2006
05:13:05  IST  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
05:13:05  IST  all   16.52    0.00    2.87    1.09    0.07    0.02    0.00   79.42    830.06&lt;/pre&gt;The  mpstat command display activities for each available processor,  processor 0 being the first  one. Global average activities among all  processors are also reported. The mpstat command can be used  both  on   SMP and UP machines, but in the latter, only global average activities  will be printed.:&lt;br /&gt;
&lt;code&gt;# mpstat  -P ALL&lt;/code&gt;&lt;br /&gt;
Output:&lt;br /&gt;
&lt;pre&gt;Linux 2.6.15.4 (wwwportal1.xxxx.co.in)         Thursday 06 April 2006
05:14:58  IST  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
05:14:58  IST  all   16.46    0.00    2.88    1.08    0.07    0.02    0.00   79.48    835.96
05:14:58  IST    0   16.46    0.00    2.88    1.08    0.07    0.02    0.00   79.48    835.96
05:14:58  IST    1   15.77    2.70    3.17    2.01    0.05    0.03    0.00   81.44    822.54&lt;/pre&gt;Another output from my HP Dual Opteron 64 bit server:&lt;code&gt;# mpstat -P ALL&lt;/code&gt;Output:&lt;br /&gt;
&lt;pre&gt;Linux 2.6.5-7.252-smp (ora9.xxx.in)   04/07/06
07:44:18     CPU   %user   %nice %system %iowait    %irq   %soft   %idle    intr/s
07:44:18     all    3.01   57.31    0.36    0.13    0.01    0.00   39.19   1063.46
07:44:18       0    5.87   69.47    0.44    0.05    0.01    0.01   24.16    262.11
07:44:18       1    1.79   48.59    0.36    0.23    0.00    0.00   49.02    268.92
07:44:18       2    2.19   42.63    0.28    0.16    0.01    0.00   54.73    260.96
07:44:18       3    2.17   68.56    0.34    0.06    0.03    0.00   28.83    271.47&lt;/pre&gt;&lt;h3&gt;Report CPU utilization using sar command&lt;/h3&gt;You can display today’s CPU activity, with sar command:&lt;br /&gt;
&lt;code&gt;# sar&lt;/code&gt;&lt;br /&gt;
Output:&lt;br /&gt;
&lt;pre&gt;Linux 2.6.9-42.0.3.ELsmp (dellbox.xyz.co.in)         01/13/2007
12:00:02 AM       CPU     %user     %nice   %system   %iowait     %idle
12:10:01 AM       all      1.05      0.00      0.28      0.04     98.64
12:20:01 AM       all      0.74      0.00      0.34      0.38     98.54
12:30:02 AM       all      1.09      0.00      0.28      0.10     98.53
12:40:01 AM       all      0.76      0.00      0.21      0.03     99.00
12:50:01 AM       all      1.25      0.00      0.32      0.03     98.40
01:00:01 AM       all      0.80      0.00      0.24      0.03     98.92
...
.....
..
04:40:01 AM       all      8.39      0.00     33.17      0.06     58.38
04:50:01 AM       all      8.68      0.00     37.51      0.04     53.78
05:00:01 AM       all      7.10      0.00     30.48      0.04     62.39
05:10:01 AM       all      8.78      0.00     37.74      0.03     53.44
05:20:02 AM       all      8.30      0.00     35.45      0.06     56.18
Average:          all      3.09      0.00      9.14      0.09     87.68
&lt;/pre&gt;&lt;h4&gt;Comparison of CPU utilization&lt;/h4&gt;The sar command writes to  standard output the contents of selected cumulative activity counters  in  the  operating  system.  The  accounting  system, based on the  values in the count and interval parameters. For example display  comparison of CPU utilization; 2 seconds apart; 5 times, use:&lt;br /&gt;
&lt;code&gt;# sar -u 2 5&lt;/code&gt;&lt;br /&gt;
Output (for each 2 seconds. 5 lines are displayed):&lt;br /&gt;
&lt;pre&gt;Linux 2.6.9-42.0.3.ELsmp (www1lab2.xyz.ac.in)         01/13/2007
05:33:24 AM       CPU     %user     %nice   %system   %iowait     %idle
05:33:26 AM       all      9.50      0.00     49.00      0.00     41.50
05:33:28 AM       all     16.79      0.00     74.69      0.00      8.52
05:33:30 AM       all     17.21      0.00     80.30      0.00      2.49
05:33:32 AM       all     16.75      0.00     81.00      0.00      2.25
05:33:34 AM       all     14.29      0.00     72.43      0.00     13.28
Average:          all     14.91      0.00     71.49      0.00     13.61&lt;/pre&gt;Where,&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;-u  12 5&lt;/b&gt; :  Report CPU utilization. The following values are displayed:&lt;/li&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;%user&lt;/b&gt;: Percentage of CPU utilization that occurred while executing at the user level (application).&lt;/li&gt;
&lt;li&gt;&lt;b&gt;%nice&lt;/b&gt;: Percentage of CPU utilization that occurred while executing at the user level with nice priority.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;%system&lt;/b&gt;:  Percentage of CPU utilization that occurred while executing at the system level (kernel).&lt;/li&gt;
&lt;li&gt;&lt;b&gt;%iowait&lt;/b&gt;: Percentage of time that the CPU or CPUs were idle during which the system had  an  outstanding  disk I/O request.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;%idle&lt;/b&gt;: Percentage  of  time  that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;To  get multiple samples and multiple reports set an output file for the  sar  command.  Run the sar command as a background process using.&lt;br /&gt;
&lt;code&gt;# sar -o output.file 12 8 &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/code&gt;&lt;br /&gt;
Better use nohup command so that you can logout and check back report later on:&lt;br /&gt;
&lt;code&gt;# nohup sar -o output.file 12 8 &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/code&gt;&lt;br /&gt;
All   data  is captured in binary form and saved to a file (data.file).  The  data can then be selectively displayed ith the sar command using the -f  option.&lt;br /&gt;
&lt;code&gt;# sar -f data.file&lt;/code&gt;&lt;br /&gt;
&lt;h3&gt;Task: Find out who is monopolizing or eating the CPUs&lt;/h3&gt;Finally,  you need to determine which process is monopolizing or eating the CPUs.  Following command will displays the top 10 CPU users on the Linux  system.&lt;br /&gt;
&lt;code&gt;# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10&lt;/code&gt;&lt;br /&gt;
OR&lt;br /&gt;
&lt;code&gt;# ps -eo pcpu,pid,user,args | sort -r -k1 | less &lt;/code&gt;&lt;br /&gt;
Output:&lt;br /&gt;
&lt;pre&gt;%CPU   PID USER     COMMAND
  96  2148 vivek    /usr/lib/vmware/bin/vmware-vmx -C /var/lib/vmware/Virtual Machines/Ubuntu 64-bit/Ubuntu 64-bit.vmx -@ &quot;&quot;
 0.7  3358 mysql    /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock
 0.4 29129 lighttpd /usr/bin/php
 0.4 29128 lighttpd /usr/bin/php
 0.4 29127 lighttpd /usr/bin/php
 0.4 29126 lighttpd /usr/bin/php
 0.2  2177 vivek    [vmware-rtc]
 0.0     9 root     [kacpid]
 0.0     8 root     [khelper]
&lt;/pre&gt;Now you know vmware-vmx process is eating up lots of CPU power.  ps command displays every process (-e) with a user-defined format (-o  pcpu). First field is pcpu (cpu utilization). It is sorted in reverse  order to display top 10 CPU eating process.&lt;br /&gt;
&lt;h3&gt;iostat command&lt;/h3&gt;You  can also use iostat command  which report Central Processing Unit (CPU)  statistics and input/output statistics for devices and partitions. It  can be use to find out your system&#39;s average CPU utilization since the  last reboot.&lt;br /&gt;
&lt;code&gt;# iostat&lt;/code&gt;Output:&lt;br /&gt;
&lt;pre&gt;Linux 2.6.15.4 (debian)         Thursday 06 April 2006
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
     16.36    0.00    2.99    1.06    0.00   79.59
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
hda               0.00         0.00         0.00         16          0
hdb               6.43        85.57       166.74     875340    1705664
hdc               0.03         0.16         0.00       1644          0
sda               0.00         0.00         0.00         24          0 &lt;/pre&gt;You  may want to use following command, which gives you three outputs every 5  seconds (as previous command gives information since the last reboot):&lt;code&gt;$ iostat -xtc 5 3&lt;/code&gt;&lt;br /&gt;
&lt;h3&gt;GUI tools for your laptops/desktops&lt;/h3&gt;Above  tools/commands are quite useful on remote server. For local system with  X GUI installed you can try out gnome-system-monitor.  It allows  you   to view and control the processes running on your system.  You can  access detailed memory maps, send signals, and terminate the processes.&lt;br /&gt;
&lt;code&gt;$ gnome-system-monitor&lt;/code&gt;&lt;br /&gt;
&lt;a href=&quot;http://files.cyberciti.biz/uploads/tips/2007/01/linux-gui-info-2.jpg&quot;&gt;&lt;img alt=&quot;gnome-system-monitor - view and control the processes&quot; src=&quot;http://files.cyberciti.biz/uploads/tips/2007/01/linux-gui-info-2.jpg&quot; width=&quot;450&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
(Click to enlarge image)&lt;br /&gt;
In  addition, the gnome-system-monitor provides an overall view of the  resource usage on  your  system,  including memory and CPU allocation.&lt;br /&gt;
&lt;a href=&quot;http://files.cyberciti.biz/uploads/tips/2007/01/linux-gui-info.jpg&quot;&gt;&lt;img alt=&quot;gnome-system-monitor - view and control the processes&quot; src=&quot;http://files.cyberciti.biz/uploads/tips/2007/01/linux-gui-info.jpg&quot; width=&quot;450&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
(Click to enlarge image)&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/8228060887923237969/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-do-i-find-out-linux-cpu-utilization.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/8228060887923237969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/8228060887923237969'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/04/how-do-i-find-out-linux-cpu-utilization.html' title='How do I Find Out Linux CPU Utilization?'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-1320728483851391214</id><published>2012-03-28T08:34:00.000-07:00</published><updated>2012-03-28T08:34:50.938-07:00</updated><title type='text'>HOW TO Install phpMyAdmin in CentOS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I am using CentOS 5 in one of my Virtual Servers and I wanted it to  have phpMyAdmin. I tried installing it by doing yum install phpmyadmin  but it said No package phpmyadmin available. So I add to add a repo. I  discovered that &lt;a href=&quot;http://rpmrepo.org/RPMforge&quot;&gt;rpmforge repo&lt;/a&gt; had this package. To add it, I executed the following commands:&lt;span id=&quot;more-1127&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;wget&lt;/span&gt; http:&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;//&lt;/span&gt;packages.sw.be&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;rpmforge-release&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;rpmforge-release-0.5.1-&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;.el5.rf.i386.rpm
rpm &lt;span style=&quot;color: #660033;&quot;&gt;-Uhv&lt;/span&gt; rpmforge-release-0.5.1-&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;.el5.rf.i386.rpm&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;If you have 64-bit version installed, you should try this one out:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;wget&lt;/span&gt; http:&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;//&lt;/span&gt;packages.sw.be&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;rpmforge-release&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;rpmforge-release-0.5.1-&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;.el5.rf.x86_64.rpm
rpm &lt;span style=&quot;color: #660033;&quot;&gt;-Uhv&lt;/span&gt; rpmforge-release-0.5.1-&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;.el5.rf.x86_64.rpm&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;If you get a 404 Not Found, then you will need to figure out the latest updated version of repo url from &lt;a href=&quot;http://rpmrepo.org/RPMforge/Using&quot;&gt;rpmforge usage page&lt;/a&gt;.&lt;br /&gt;
After that, you may like to update your packages by doing this:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;yum update&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;and then continue installing phpmyadmin&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;yum &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;install&lt;/span&gt; phpmyadmin&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;It should ask you for confirmation and you can continue installing phpMyAdmin with dependencies.&lt;br /&gt;
When installation is done, you can edit  /etc/httpd/conf.d/phpmyadmin.conf and allow it to be opened from  anywhere and not just the same computer. You are going to need this if  you have installed it in a remote virtual server.&lt;br /&gt;
To do so, open up /etc/httpd/conf.d/phpmyadmin.conf using:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;nano&lt;/span&gt; &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;etc&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;httpd&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;conf.d&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;phpmyadmin.conf&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;You will see:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;text&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;lt;Directory &quot;/usr/share/phpmyadmin&quot;&amp;gt;
  Order Deny,Allow
  Deny from all
  Allow from 127.0.0.1
&amp;lt;/Directory&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Just change the line “Allow from 127.0.0.1″ to “Allow from [yourip]“,  where [yourip] is IP address of your computer if you have public static  IP. Otherwise, you can also set it to “Allow from all”.&lt;br /&gt;
Press Ctrl+O followed by Enter to save and Ctrl+X to exit nano.&lt;br /&gt;
Now, you must restart apache. To do so, run&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;service httpd restart&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Now, you can access phpMyAdmin by visiting http://vps_server_IP_or_domain/phpmyadmin. But you will get the following error:&lt;br /&gt;
&lt;blockquote&gt; &lt;strong&gt;Error&lt;/strong&gt;&lt;br /&gt;
The configuration file now needs a secret passphrase (blowfish_secret). &lt;/blockquote&gt;To make it work, you will need to edit config.inc.php. To do so, type in:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;nano&lt;/span&gt; &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;usr&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;share&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;phpmyadmin&lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;/&lt;/span&gt;config.inc.php&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Find a line saying:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;php&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #000088;&quot;&gt;$cfg&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&#39;blowfish_secret&#39;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #666666; font-style: italic;&quot;&gt;/* YOU MUST FILL IN THIS
FOR
COOKIE AUTH! */&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Fill in any secret keyword there, eg mysecretpassphrase, so that it looks like:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;php&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #000088;&quot;&gt;$cfg&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&#39;blowfish_secret&#39;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;&#39;mysecretpassphrase&#39;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #666666; font-style: italic;&quot;&gt;/* YOU MUST FILL IN THIS
FOR
COOKIE AUTH! */&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;and then save it.&lt;br /&gt;
If you don’t have mysql server installed, you will get the following error:&lt;br /&gt;
&lt;blockquote&gt;Error&lt;br /&gt;
#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)&lt;/blockquote&gt;To install mysql-server, just run:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;yum &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;install&lt;/span&gt; mysql-server&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;and then start it:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;service mysqld start&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Then change the root password:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;mysqladmin &lt;span style=&quot;color: #660033;&quot;&gt;-u&lt;/span&gt; root password PASSWORD_HERE&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Now, you will have to remove phpmyadmin:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;yum remove phpmyadmin&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;and reinstall it again:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;yum &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;install&lt;/span&gt; phpmyadmin&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Then you will need to edit the config.inc.php again to enter blowfish secret (see above). Then, you can login.&lt;br /&gt;
If however, you want phpMyAdmin to connect to a remote server, you  can change the line by replacing localhost with your server IP:&lt;br /&gt;
&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;php&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #000088;&quot;&gt;$cfg&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&#39;Servers&#39;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #000088;&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&#39;host&#39;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;]&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;&#39;localhost&#39;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Hope this helps.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/1320728483851391214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-install-phpmyadmin-in-centos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1320728483851391214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1320728483851391214'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-install-phpmyadmin-in-centos.html' title='HOW TO Install phpMyAdmin in CentOS'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-6630683337194125279</id><published>2012-03-28T07:44:00.002-07:00</published><updated>2012-03-28T07:44:28.493-07:00</updated><title type='text'>how to fix : No activity within 1800 seconds; please log in again</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;1800 seconds is such a long time, right?&lt;br /&gt;
&lt;ol&gt;&lt;li&gt; It’s &lt;a href=&quot;http://www.google.ie/search?q=convert+1800+seconds+to+minutes&quot;&gt;30 minutes&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt; It’s &lt;a href=&quot;http://www.google.ie/search?q=convert+1800+seconds+to+hours&quot;&gt;0.5 hours&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt; It’s &lt;a href=&quot;http://www.google.ie/search?q=convert+1800+seconds+to+days&quot;&gt;0.0208333333 days&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt; It’s also &lt;a href=&quot;http://www.google.ie/search?q=convert+1800+seconds+to+years&quot;&gt;5.70397764 × 10&lt;sup&gt;-5&lt;/sup&gt; years&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;And it’s not long enough for me. phpMyAdmin logs you out after 1800  seconds, obviously for security reasons. That’s fine if there are other  people about, if I was in an office with people coming and going, but I  work from home. All I see for most of the day is my family, the radio,  my messy desk, computers, and the view out the window. Time to figure  out how to make that 1800 second limit a little longer or remove it  altogether.&lt;br /&gt;
After a little digging, I discovered that extending the time limit to  a day is actually quite easy. Open your phpMyAdmin’s config.inc.php and  search for or add the following line:&lt;br /&gt;
&lt;blockquote&gt;&lt;code&gt;$cfg[&#39;LoginCookieValidity&#39;]     = 86400;&lt;/code&gt;&lt;/blockquote&gt;Refresh your logged out phpMyAdmin and presuming you haven’t left it idle for 24 hours, you’ll be logged in again!&lt;br /&gt;
If the time limit really bugs you, you need http authentication. Look  for the “auth_type” line in the config.inc.php and change that to  “http”. phpMyAdmin won’t log you out as long as your browser is open.  Perfect!&lt;br /&gt;
If you’re concerned about sending your MySQL username and password in  the clear each time you make a request to phpMyAdmin you can either use  SSL or try the “config” auth_type. Make sure you fill in the username  and password fields in the config file, and secure the phpMyAdmin  directory with a htpasswd file.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/6630683337194125279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-fix-no-activity-within-1800.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/6630683337194125279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/6630683337194125279'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-fix-no-activity-within-1800.html' title='how to fix : No activity within 1800 seconds; please log in again'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-455714644746345669</id><published>2012-03-28T03:28:00.000-07:00</published><updated>2012-03-28T03:28:05.320-07:00</updated><title type='text'>How to Install php-mcrypt on CentOS 6.2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Symptoms :&lt;br /&gt;
This error appeared when i try to use phpmyadmin on authentication type as cookie. &lt;b&gt;mcrypt&lt;/b&gt; is necessary if you want to use cookie based authentication with phpymyadmin.&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;The &lt;i&gt;mcrypt&lt;/i&gt; exension is missing. Please check your PHP configuration.&lt;/pre&gt;&lt;img alt=&quot;mcrypt&quot; class=&quot;alignnone&quot; height=&quot;50&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbJ0bZWrzCxjxAHj5nHqEpOegampymRPw2G0KntHMGz5ZJ2rULnnGr93k9JF1JYr1J_nodG1GD5u5a6FdxThLaHRjJVA47SI9wZLkTg_u5Cy-UfL70p-E5W9RnMkQZty1YDbmTD4GxggI/s1600/mcypt.PNG&quot; title=&quot;mcrypt&quot; width=&quot;459&quot; /&gt;&lt;br /&gt;
To install php-&lt;u&gt;mcrypt&lt;/u&gt; on CentOS 6.2, follow the following steps :&lt;br /&gt;
1. Download epel repository :&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;[root@centos62 ~]# [root@centos62 ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
[root@centos62 ~]# wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6&lt;/pre&gt;2. Install epel repository :&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;[root@centos62 ~]# rpm --import RPM-GPG-KEY-EPEL-6
[root@centos62 ~]# rpm -i epel-release-6-5.noarch.rpm&lt;/pre&gt;3. Simply run the following command to install php-mcrypt :&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;[root@centos62 ~]# yum install php-mcrypt -y
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/455714644746345669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-install-php-mcrypt-on-centos-62.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/455714644746345669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/455714644746345669'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-install-php-mcrypt-on-centos-62.html' title='How to Install php-mcrypt on CentOS 6.2'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbJ0bZWrzCxjxAHj5nHqEpOegampymRPw2G0KntHMGz5ZJ2rULnnGr93k9JF1JYr1J_nodG1GD5u5a6FdxThLaHRjJVA47SI9wZLkTg_u5Cy-UfL70p-E5W9RnMkQZty1YDbmTD4GxggI/s72-c/mcypt.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-1799435804140497102</id><published>2012-03-28T03:24:00.002-07:00</published><updated>2012-03-28T03:24:15.868-07:00</updated><title type='text'>How to check CentOS version via command line?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;strong&gt;Via command line, type this:&lt;/strong&gt;&lt;br /&gt;
&lt;pre&gt;cat /etc/redhat-release&lt;/pre&gt;&lt;strong&gt;To safely upgrade CentOS to the latest version, type this:&lt;/strong&gt;&lt;br /&gt;
&lt;pre&gt;yum update&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/1799435804140497102/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-check-centos-version-via-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1799435804140497102'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/1799435804140497102'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2012/03/how-to-check-centos-version-via-command.html' title='How to check CentOS version via command line?'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5762064040393208356.post-8821598360377170110</id><published>2011-10-16T09:25:00.000-07:00</published><updated>2011-10-16T09:25:57.382-07:00</updated><title type='text'>PHP jQuery AJAX Javascript Long Polling</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;h3&gt;Background&lt;/h3&gt;&quot;Long polling&quot; is the name used to describe a technique which:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;An AJAX request is made (utilizing a javascript framework such as jQuery) &lt;/li&gt;
&lt;li&gt;The server waits for the data requested to be available, loops, and sleeps (your server-side PHP script) &lt;/li&gt;
&lt;li&gt;This loop repeats after data is returned to the client and  processed (usually in your AJAX request&#39;s onComplete callback function) &lt;/li&gt;
&lt;/ul&gt;This essentially simulates a continuous real-time stream from the  client to the server.  It can be more efficient than a regular polling  technique because of the reduction in HTTP requests.  You&#39;re not asking  over and over and over again for new data - you ask once and wait for an  answer.  In most cases this reduces the latency in which data becomes  available to your application.&lt;br /&gt;
There are a variety of use cases in which this technique can be  handy.  At the top of the list are real-time web-based chat  applications.  Each client executes a long polling loop for chat and  user events (sign on/sign off/new message).  &lt;a href=&quot;http://www.meebo.com/&quot;&gt;Meebo&lt;/a&gt; is perhaps the greatest example of this.&lt;br /&gt;
It&#39;s important to note some of the server side technical limitations  of long polling.  Because connections remain open for considerably  longer time than a typical HTTP request/response cycle you want your web  server to be able to handle a large number of simultaneous connections.   Apache isn&#39;t the best candidate for this type of situation.  &lt;a href=&quot;http://nginx.net/&quot;&gt;nginx&lt;/a&gt; and &lt;a href=&quot;http://www.lighttpd.net/&quot;&gt;lighttpd&lt;/a&gt;  are two lightweight web servers built from the ground up to handle a  high volume of simultaneous connections.  Both support the FastCGI  interface and as such can be configured to support PHP.  Again, Meebo  uses lighttpd.&lt;br /&gt;
For similar reasons - it&#39;s also a good idea to choose a different  sub-domain to handle long polling traffic.  Because of client side  browser limitations you don&#39;t want long polling connections interfering  with regular HTTP traffic delivering page and media resources for your  application.&lt;br /&gt;
&lt;h3&gt;Implementation&lt;/h3&gt;&lt;a href=&quot;http://www.jquery.com/&quot;&gt;jQuery&lt;/a&gt; makes implementation a breeze.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;div class=&quot;syntaxhighlighter codeClass jscript&quot; id=&quot;highlighter_874242&quot;&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;&lt;code class=&quot;jscript keyword&quot;&gt;var&lt;/code&gt; &lt;code class=&quot;jscript plain&quot;&gt;lpOnComplete = &lt;/code&gt;&lt;code class=&quot;jscript keyword&quot;&gt;function&lt;/code&gt;&lt;code class=&quot;jscript plain&quot;&gt;(response) {&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot;&gt;&lt;code class=&quot;jscript spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;jscript plain&quot;&gt;alert(response);&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot;&gt;&lt;code class=&quot;jscript spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;jscript comments&quot;&gt;// do more processing&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number4 index3 alt1&quot;&gt;&lt;code class=&quot;jscript spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;jscript plain&quot;&gt;lpStart();&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number5 index4 alt2&quot;&gt;&lt;code class=&quot;jscript plain&quot;&gt;};&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number6 index5 alt1&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;line number7 index6 alt2&quot;&gt;&lt;code class=&quot;jscript keyword&quot;&gt;var&lt;/code&gt; &lt;code class=&quot;jscript plain&quot;&gt;lpStart = &lt;/code&gt;&lt;code class=&quot;jscript keyword&quot;&gt;function&lt;/code&gt;&lt;code class=&quot;jscript plain&quot;&gt;() {&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number8 index7 alt1&quot;&gt;&lt;code class=&quot;jscript spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;jscript plain&quot;&gt;$.post(&lt;/code&gt;&lt;code class=&quot;jscript string&quot;&gt;&#39;/path/to/script&#39;&lt;/code&gt;&lt;code class=&quot;jscript plain&quot;&gt;, {}, lpOnComplete, &lt;/code&gt;&lt;code class=&quot;jscript string&quot;&gt;&#39;json&#39;&lt;/code&gt;&lt;code class=&quot;jscript plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number9 index8 alt2&quot;&gt;&lt;code class=&quot;jscript plain&quot;&gt;};&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number10 index9 alt1&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;line number11 index10 alt2&quot;&gt;&lt;code class=&quot;jscript plain&quot;&gt;$(document).ready(lpStart);&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number11 index10 alt2&quot;&gt;&lt;code class=&quot;jscript plain&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number11 index10 alt2&quot;&gt;&lt;code class=&quot;jscript plain&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;Straightforward.  When the document is ready the loop begins.  Each  iteration the returned data is processed and the loop is restarted.&lt;br /&gt;
On the server side - just like we discussed earlier:&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;div class=&quot;syntaxhighlighter codeClass php&quot; id=&quot;highlighter_75661&quot;&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;container&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot;&gt;&lt;code class=&quot;php variable&quot;&gt;$time&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;= time();&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot;&gt;&lt;code class=&quot;php keyword&quot;&gt;while&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;((time() - &lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$time&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;) &amp;lt; 30) {&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php comments&quot;&gt;// query memcache, database, etc. for new data&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number4 index3 alt1&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$data&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;= &lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$datasource&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;-&amp;gt;getLatest();&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number5 index4 alt2&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;line number6 index5 alt1&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php comments&quot;&gt;// if we have new data return it&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number7 index6 alt2&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;if&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;(!&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;empty&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$data&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;)) {&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number8 index7 alt1&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php functions&quot;&gt;echo&lt;/code&gt; &lt;code class=&quot;php plain&quot;&gt;json_encode(&lt;/code&gt;&lt;code class=&quot;php variable&quot;&gt;$data&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;);&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number9 index8 alt2&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php keyword&quot;&gt;break&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;;&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number10 index9 alt1&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number11 index10 alt2&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;line number12 index11 alt1&quot;&gt;&lt;code class=&quot;php spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;php plain&quot;&gt;usleep(25000);&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number13 index12 alt2&quot;&gt;&lt;code class=&quot;php plain&quot;&gt;}&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number13 index12 alt2&quot;&gt;&lt;code class=&quot;php plain&quot;&gt;&amp;nbsp;&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;Actually, a couple points of interest here.  We don&#39;t actually loop &lt;em&gt;infinitely&lt;/em&gt;  server side.  You may have noticed the logic for the while loop - if  we&#39;ve executed for more than 30 seconds we discontinue the loop and  return nothing.  This nearly eliminates the possibility of substantial  memory leaks.  Also, if we didn&#39;t put a cap on execution time we would  need to print a &quot;space&quot; character and flush output buffers every  iteration of the loop to keep PHP abreast to the status of this  process/connection.  &lt;strong&gt;Without output being sent PHP cannot determine if the connection was lost via connection_status() or connection_aborted()&lt;/strong&gt;.   As a result this could lead to a situation where there are an  increasing number of &quot;ghost&quot; processes eating up server resources.  Not  good!&lt;br /&gt;
That pretty much sums it up!  Not that difficult, right?&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://howto-heaven.blogspot.com/feeds/8821598360377170110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://howto-heaven.blogspot.com/2011/10/php-jquery-ajax-javascript-long-polling.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/8821598360377170110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5762064040393208356/posts/default/8821598360377170110'/><link rel='alternate' type='text/html' href='http://howto-heaven.blogspot.com/2011/10/php-jquery-ajax-javascript-long-polling.html' title='PHP jQuery AJAX Javascript Long Polling'/><author><name>TheGeek</name><uri>http://www.blogger.com/profile/02708625811277542217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>