<?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:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-5114420386457021844</id><updated>2009-09-21T11:46:54.394-07:00</updated><title type='text'>Programming Solutions - Coding Tips</title><subtitle type='html'>asp, php, asp.net, javascript, css, html coding tips and programming solutions</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5114420386457021844.post-8008712727717393042</id><published>2008-04-14T05:54:00.001-07:00</published><updated>2008-04-14T05:54:44.351-07:00</updated><title type='text'>Multiple Language Welcome PHP Script</title><content type='html'>How to have a multilingual welcome on your website!&lt;br /&gt;&lt;br /&gt;If you would like to welcome visitors to your own website, by directing visitors based on their prefered language, this is how I do it.&lt;br /&gt;&lt;br /&gt;The technology is PHP, which is a simple language that adds a level of capability and dynamic that you can't have with Javascript and HTML. Obviously you need access to PHP. Most hosts do provide it.. but this is one step beyond Geocities. If your host doesn't offer PHP.. maybe get one that does - it's not expensive.&lt;br /&gt;&lt;br /&gt;The script below simply redirects incoming requests to pages associated with the first two letters of the code in the language preference of the visitors browser settings.&lt;br /&gt;&lt;br /&gt;The two files you need are index.txt and fish-config.txt&lt;br /&gt;&lt;br /&gt;Download these text files by right-clicking the links and choosing save-as. Rename the first 'index.html' and the second 'fish-config.php'.&lt;br /&gt;&lt;br /&gt;The index.html is the root index file you'll likely recognise. This doesn't actually do any more than redirect requests to files listed in  the config file. fish-config.php is a file that index includes when it is run. i.e. you need PHP includes enabled, and to put this file in the PHP includes folder.&lt;br /&gt;&lt;br /&gt;The script is an improved version of one I found on the net years ago. It has better security and handles more variety of input from browsers language preference.. stripping the dialects to find the core language.. it can also now handle upto 100 languages. Don't try changing it unless you are confident in PHP, you can open holes in security with badly coded PHP.&lt;br /&gt;&lt;br /&gt;Four things to do..&lt;br /&gt;&lt;br /&gt;   1. fish-config.php - add lines to as needed but adjust the $count variable, keeping it one above the last array record number.&lt;br /&gt;&lt;br /&gt;   2. fish-config.php &amp;amp; index.html - change the http://www.example.com/ to reflect your own site.&lt;br /&gt;&lt;br /&gt;   3. index.html - Change line 40  $redirect = 'babel/index.html'; to suggest the location of a default file.. for when someone doesn't have a language preference in the get request.&lt;br /&gt;&lt;br /&gt;   4. index.html - Change line 35  $redirect = 'error/bad-request.html'; to suggest the location of your error file for HTTP code 400 Bad Request&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's about it..&lt;br /&gt;&lt;br /&gt;You can find the codes for languages on The ISO639-1 language code list&lt;br /&gt;&lt;br /&gt;Good luck.. any problems let me know.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5114420386457021844-8008712727717393042?l=helpingpeoples.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/8008712727717393042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=5114420386457021844&amp;postID=8008712727717393042' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/8008712727717393042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/8008712727717393042'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/2008/04/multiple-language-welcome-php-script.html' title='Multiple Language Welcome PHP Script'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14979786506830002507'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5114420386457021844.post-9221071211495491367</id><published>2008-04-09T03:14:00.000-07:00</published><updated>2008-04-09T03:18:55.160-07:00</updated><title type='text'>The PNG problem in Windows Internet Explorer</title><content type='html'>&lt;p&gt;This site is all about a JavaScript-based PNG fix for Internet Explorer 5.5 and 6 on Windows. The fix allows IE to properly render PNG alpha transparency. If you want to get  straight to the script, go to the &lt;a href="http://homepage.ntlworld.com/bobosola/pnghowto.htm"&gt;how-to&lt;/a&gt; page and follow  the instructions there. If you have the time for a description and demo of the problem, then read on...&lt;/p&gt;  &lt;p&gt;Why only versions 5.5 &amp;amp; 6? Because Windows IE versions prior to 5.5 do not support the filter which fixes the PNG problem, and version 7 (not yet released at the time of writing in January 2006) is reported to have fixed the issue entirely.&lt;/p&gt;  &lt;p&gt;The code can be used either by a one-time copy-and-paste or as an include file.  The entire thing is completely ignored by all other browsers - in fact it is treated as an HTML comment - thanks to IE's &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/ccomment_ovw.asp"&gt; conditional comments&lt;/a&gt;. This solution is therefore light, portable and non-invasive to other browsers.&lt;/p&gt;  &lt;p&gt;Already use the script? You can check the &lt;a href="http://homepage.ntlworld.com/bobosola/changelog.htm"&gt;change log&lt;/a&gt; for details of what's new. Please feel free to use or amend this routine you as see fit.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;March 2008:&lt;/strong&gt; This script has been up for over 4 years now but I'm afraid I haven't the time to update it. I will leave it here for those who still can use it, but there may be better solutions around these days,  such as &lt;a href="http://24ways.org/2007/supersleight-transparent-png-in-ie6"&gt;Drew McLellans.&lt;/a&gt; I'm very sorry but I can no longer respond to any email about it - I just don't have the time. There is no official licence of any kind on this - it's simply freeware. Use it or change it as you wish.&lt;/p&gt;&lt;p&gt;Consider a standard GIF image with the halo problem. GIFs only allow one colour for background transparency, so a GIF placed over the intersection of another colour looks ghastly:&lt;/p&gt;  &lt;div class="plainbackground"&gt;  &lt;img src="http://homepage.ntlworld.com/bobosola/logo.gif" alt="a GIF logo" height="100" width="100" /&gt; &lt;/div&gt;  &lt;div id="car"&gt;    &lt;img style="visibility: hidden;" name="mini" src="http://homepage.ntlworld.com/bobosola/car.png" alt="transparent car PNG" height="95" width="149" /&gt;    &lt;p class="caption"&gt;Drag me around the page!&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Compare the above GIF to the same image below saved as a PNG. On modern browsers (Firefox, Opera etc), the halo problem is solved - but not in Windows Internet Explorer prior to version 7. IE 6 and under render the image with an ugly background which looks even worse than the GIF halo.&lt;/p&gt;  &lt;div class="plainbackground"&gt;  &lt;img src="http://homepage.ntlworld.com/bobosola/logo2.png" alt="a PNG logo" height="100" width="100" /&gt; &lt;/div&gt;  &lt;p&gt;&lt;img src="http://homepage.ntlworld.com/bobosola/logo2.png" alt="a PNG logo" align="right" height="100" width="100" /&gt; Finally, here is the same PNG right-aligned to this paragraph using the very common (deprecated)  &lt;span class="monospace"&gt;img align="right"&lt;/span&gt; construct. The PNG can be positioned in the same way as JPGs or GIFs, but the transparency issue remains a problem.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The GIF with the halo is still here, but the PNGs should now be working in IE versions 5.5 and 6. The only difference between this page and the previous one is a chunk of JavaScript.&lt;/p&gt;  &lt;div class="plainbackground"&gt; &lt;img src="http://homepage.ntlworld.com/bobosola/logo.gif" alt="a GIF logo" height="100" width="100" /&gt; &lt;/div&gt;  &lt;div id="car"&gt;    &lt;img style="visibility: hidden;" name="mini" src="http://homepage.ntlworld.com/bobosola/car.png" alt="transparent car PNG" height="95" width="149" /&gt;    &lt;p class="caption"&gt;Drag me around the page!&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Compare the above GIF to the same image below saved as a PNG. The transparency should now be working in IE. Try dragging the car image around the screen and notice how it is "see-through".&lt;/p&gt;  &lt;div class="plainbackground"&gt; &lt;img src="http://homepage.ntlworld.com/bobosola/logo2.png" alt="a PNG logo" height="100" width="100" /&gt; &lt;/div&gt;  &lt;p&gt;&lt;img src="http://homepage.ntlworld.com/bobosola/logo2.png" alt="a PNG logo" align="right" height="100" width="100" /&gt; Finally, here is the same PNG right-aligned to this paragraph using the very common (deprecated)  &lt;span class="monospace"&gt;img align="right"&lt;/span&gt; construct. The PNG can be positioned in the same way as JPGs or GIFs, and the transparency issue is now fixed.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The JS code can be seen if you do a "View Source" on the &lt;a href="http://homepage.ntlworld.com/bobosola/pngtestfixed.htm"&gt;Solution&lt;/a&gt; page. There are two ways to use it - simple copy &amp;amp; paste or the JS include file method. Note that you &lt;strong&gt;must&lt;/strong&gt; have height and width attributes specified for each image. Other attributes (class, alt, title &amp;amp; style) are optional so far as this routine is concerned, but are respected if specified.&lt;/p&gt;  &lt;p&gt;There is also an &lt;a href="http://homepage.ntlworld.com/bobosola/imagemap.htm"&gt;imagemap version&lt;/a&gt; if you want to use imagemaps and/or  form input images and a &lt;a href="http://homepage.ntlworld.com/bobosola/png_mouseover.htm"&gt;rollover version&lt;/a&gt; which enables the use of transparent PNGs in rollovers.&lt;/p&gt;  &lt;h2&gt;Method 1: Copy &amp;amp; Paste&lt;/h2&gt;  &lt;p&gt;For single page or occasional usage, copy the JS code in its entirety  (from &lt;span class="monospace"&gt;&lt;!--[if lt IE 7]&gt;&lt;/span&gt; to  &lt;span class="monospace"&gt;&lt;![endif]--&gt;&lt;/span&gt;) and paste it into your page somewhere in the the &lt;span class="monospace"&gt;&lt;/span&gt; section. That's it. &lt;/p&gt;  &lt;h2&gt;Method 2: (recommended) JS Include File&lt;/h2&gt;  &lt;p&gt;If you wish to use the code on multiples of pages, you may prefer to use a JS include file. First,  download the JS file here: &lt;a href="http://homepage.ntlworld.com/bobosola/pngfix.js"&gt;pngfix.js&lt;/a&gt;. Place the file in your webpage directory, then add the following construct on each of your pages somewhere in the &lt;span class="monospace"&gt;&lt;/span&gt; section:&lt;/p&gt;  &lt;pre&gt;&lt;!--[if lt IE 7.]&gt;&lt;br /&gt;&lt;script type="text/javascript" src="pngfix.js"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;![endif]--&gt;&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt;Note the use of the &lt;span class="monospace"&gt;defer&lt;/span&gt; keyword. This trick causes the images to be replaced before they are rendered. Earlier versions of this script did not use this method, occasionally resulting in an unpleasant screen flicker as the PNGs were being filtered. The code in the include file is slightly different from the copy and paste code referred to above, so I recommend downloading my file rather than making your own.&lt;/p&gt;  &lt;p&gt;Here is a &lt;a href="http://homepage.ntlworld.com/bobosola/pngtestfixed_JS_inc_file.htm"&gt;demo page&lt;/a&gt; using the Include file method. This method is arguably better for use with multiples of pages, as it only requires three lines of code per page. The JS file is only 2KB in size and will be cached after the first download. It will therefore incur no further download overhead on subsequent pages. The download time should be around 0.3 seconds on an average 48kbps dial-up modem connection.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5114420386457021844-9221071211495491367?l=helpingpeoples.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/9221071211495491367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=5114420386457021844&amp;postID=9221071211495491367' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/9221071211495491367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/9221071211495491367'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/2008/04/png-problem-in-windows-internet.html' title='The PNG problem in Windows Internet Explorer'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14979786506830002507'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5114420386457021844.post-447335376025047798</id><published>2008-03-24T21:11:00.000-07:00</published><updated>2008-03-24T21:15:39.772-07:00</updated><title type='text'>PHP Coding Tips - Strings</title><content type='html'>1) As a finesse thing, I use single quotes around strings whenever possible (e.g. strings that don't contain variables, single quotes, \n, etc.). This is supposed to make less work for the PHP parser.2) When an array variable isn't in a string, put quotes around string-literal keys so they are not regarded as constants:&lt;br /&gt;PHP Code:&lt;br /&gt;// OK&lt;br /&gt;echo $row[$key];&lt;br /&gt;// Wrong, unless key is a constant&lt;br /&gt;echo $row[key];&lt;br /&gt;// Right&lt;br /&gt;echo $row['key'];&lt;br /&gt;// OK, since it's in a string&lt;br /&gt;echo "Text: $row[key]";&lt;br /&gt;3) Remember, you can break out of PHP mode for large sections of HTML. This is faster than echo'ing and you don't need to escape quotes.&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;br /&gt; Personally I avoid any code that looks like this:&lt;br /&gt;PHP Code:&lt;br /&gt;$something = 'this';&lt;br /&gt;$something .= 'and this';&lt;br /&gt;$something .= 'and this';&lt;br /&gt;$something .= 'and this';&lt;br /&gt;$something .= 'and this';&lt;br /&gt;or this:&lt;br /&gt;PHP Code:&lt;br /&gt;$something = 'this'&lt;br /&gt;. 'and this'&lt;br /&gt;. 'and this'&lt;br /&gt;. 'and this'&lt;br /&gt;. 'and this'&lt;br /&gt;. 'and this'&lt;br /&gt;. 'and this';&lt;br /&gt;I much prefer the following:&lt;br /&gt;PHP Code:&lt;br /&gt;$something = 'this&lt;br /&gt;and this&lt;br /&gt;and this&lt;br /&gt;and this';&lt;br /&gt;Why? Because in the first two examples PHP is having to allocate memory for multiple strings and then go through the (relatively) expensive process of "sticking" them together again. If you just declare a string over multiple lines you are avoiding that overhead. You have to be careful to make code readable if you do this but I've never had any problems with it.Here's a handy (relatively undocumented) tip. PHP supports the following method of assigning strings (borrowed from Perl):&lt;br /&gt;PHP Code:&lt;br /&gt;$string = &lt;&lt;&lt;ENDOFSTRING&lt;br /&gt;This is a string&lt;br /&gt;It can include both 'single' and "double" quotes&lt;br /&gt;without needing to escape them. However, $variables&lt;br /&gt;will still be interpolated as they are in double&lt;br /&gt;quoted strings. Complex variable expressions such as&lt;br /&gt;{$array['element']} or {$object-&gt;property} can also&lt;br /&gt;be included and will be evaluated if they are included&lt;br /&gt;in curly braces (they may work without curly braces&lt;br /&gt;but I tend to include them for added clarity). The&lt;br /&gt;string will terminate with whatever you specified&lt;br /&gt;at the start like this:&lt;br /&gt;ENDOFSTRING;&lt;br /&gt;&gt;&gt;&gt;&gt;&lt;a href="http://uk2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc" target="_blank"&gt;See php.net for more info.&lt;/a&gt;&lt;&lt;&lt;&lt;&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;br /&gt;You can eek a bit more speed out of your code, especially if you have LOTS of strings, by using single quotes and concanetating variables in (I can't spell today...sigh)&lt;br /&gt;PHP Code:&lt;br /&gt;$string = 'this is a string with '.$foo.' in it';&lt;br /&gt;// is marginally faster than&lt;br /&gt;$string = "this is a string with $foo in it";&lt;br /&gt;The reason is php has to search through the string to find the variable.&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;br /&gt; It's better to use a comma instead of a dot, because it saves some overhead (no string concatenation).&lt;br /&gt;PHP Code:&lt;br /&gt;// Example:&lt;br /&gt;echo 'foo', 'bar';&lt;br /&gt;// translates to:&lt;br /&gt;echo 'foo';&lt;br /&gt;echo 'bar';&lt;br /&gt;// whereas:&lt;br /&gt;echo 'foo' . 'bar'&lt;br /&gt;// translates to:&lt;br /&gt;echo 'foobar'&lt;br /&gt;The first is cheaper, because PHP doesn't first have to create the new string 'foobar', but can instead send the two strings to output directly.&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;br /&gt;to echo big chunks of html with vars in the middle using single quotes, instead of double quotes (slower) or jumping in and out of php, even if using shorthand, I do it like this&lt;br /&gt;PHP Code:&lt;br /&gt;echo '&lt;br /&gt;   Hello,&lt;br /&gt;&lt;br /&gt;   My name is ',$name,' ',$lastname,' and am ',$age,' years old.&lt;br /&gt;&lt;br /&gt;   I live in ',$city,', ',$country,' since I was born.&lt;br /&gt;&lt;br /&gt;   You can contact me at ',$email,' or by phone at ',$phone,'&lt;br /&gt;&lt;br /&gt;   Regards,&lt;br /&gt;&lt;br /&gt;   ',$name,' ',$lastname,'&lt;br /&gt;&lt;br /&gt;';&lt;br /&gt;it's very shorthand and fast... it can be very comfortable to use in a simple php template system&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;br /&gt;Consider using str_replace instead of the preg_replace or ereg_replace functions. The only reason why you would use preg_replace or ereg_replace functions would be that you REALLY need to use regular expressions. Also, as of PHP 4.0.5, every parameter in str_replace() can be an array, so theres no excuse to use preg or ereg fucntions when replacing simpel strings anymore.A useful use of str_replace() :&lt;br /&gt;PHP Code:&lt;br /&gt;$string="The quick brown fox jumps over the lazy dog.";&lt;br /&gt;$patterns[0] = "quick";&lt;br /&gt;$patterns[1] = "brown";&lt;br /&gt;$patterns[2] = "fox";&lt;br /&gt;$replacements[0] = "slow";&lt;br /&gt;$replacements[1] = "black";&lt;br /&gt;$replacements[2] = "bear";&lt;br /&gt;$string=str_replace($patterns, $replacements, $string);&lt;br /&gt;//$string="The slow black bear jumps over the lazy dog."&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;br /&gt;ereg vs pregWhen it comes to the regular expression functions, ereg* and preg*, the preg functions are the clear choice. The preg functions are generally twice as fast as their ereg counterpart. They also support more advanced regular expression operations. I can't think of any reason why you would need to use the ereg functions.&lt;a href="http://www.php.net/manual/en/ref.pcre.php" target="_blank"&gt;preg manual page&lt;/a&gt; and &lt;a href="http://www.php.net/manual/en/pcre.pattern.syntax.php" target="_blank"&gt;pattern syntax&lt;/a&gt; (long and confusing but pretty good).&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;br /&gt; Here's a bit of code I use to change new lines into XHTML &lt;p&gt;'s and &lt;br /&gt;'s.&lt;br /&gt;PHP Code:&lt;br /&gt;// the first bit is to make both "\r\n" and "\r" line endings into "\n"&lt;br /&gt;$string = str_replace("\r\n", "\n", $string);&lt;br /&gt;$string = str_replace("\r", "\n", $string);&lt;br /&gt;// this next bit first adds an opening &lt;p&gt; then makes all double line breaks into &lt;/p&gt;&lt;p&gt;&lt;br /&gt;$string = "&lt;p&gt;".str_replace("\n\n", "&lt;/p&gt;&lt;p&gt;", $string);&lt;br /&gt;// finally this turns any single line breaks into &lt;br /&gt;'s and closes the last &lt;p&gt;&lt;br /&gt;$string = str_replace("\n", "&lt;br /&gt;", $string)."&lt;/p&gt;";&lt;br /&gt;-------------------------------------------------------------------------------------------------&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5114420386457021844-447335376025047798?l=helpingpeoples.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/447335376025047798/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=5114420386457021844&amp;postID=447335376025047798' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/447335376025047798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/447335376025047798'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/2008/03/php-coding-tips-strings.html' title='PHP Coding Tips - Strings'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14979786506830002507'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5114420386457021844.post-6875643558831627897</id><published>2008-03-19T02:40:00.000-07:00</published><updated>2008-03-19T02:41:17.209-07:00</updated><title type='text'>Joomla! Wins Best PHP Open Source Web CMS</title><content type='html'>&lt;p&gt;As Packt Press continues to rattle off the awards this week, its&lt;a href="http://www.cmswire.com/news/topic/joomla"&gt; Joomla’s&lt;/a&gt; turn in the  spotlight. Today’s prize is for “&lt;strong&gt;Best &lt;span class="caps"&gt;PHP&lt;/span&gt; Open  Source Content Management System&lt;/strong&gt;”.&lt;/p&gt; &lt;p&gt;Quoting the Packt site, “Joomla! is possibly one of the biggest success  stories in open source of late. Its first release came in only September 2005  and since then has grown to be one of the most downloaded Content Management  Systems on the web.”&lt;/p&gt; &lt;p&gt;The runners up in this category were Drupal and e107 respectively. Previous  winners this week were WordPress for &lt;a href="http://www.cmswire.com/cms/web-cms/wordpress-wins-best-social-networking-cms-001889.php"&gt;Best  Open Source Social Networking &lt;span class="caps"&gt;CMS&lt;/span&gt;&lt;/a&gt; and mojoPortal for  &lt;a href="http://www.cmswire.com/cms/web-cms/mojoportal-wins-best-other-open-source-content-management-system-001896.php"&gt;Best  Other Open Source Content Management System&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;And the fun’s not over yet. No sir. Rolling right along you avid &lt;span class="caps"&gt;CMS’&lt;/span&gt;ers have both the &lt;strong&gt;Most Promising Open Source &lt;span class="caps"&gt;CMS&lt;/span&gt;&lt;/strong&gt; award and the &lt;strong&gt;Overall Winner&lt;/strong&gt;  award to look forward to.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5114420386457021844-6875643558831627897?l=helpingpeoples.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/6875643558831627897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=5114420386457021844&amp;postID=6875643558831627897' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/6875643558831627897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/6875643558831627897'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/2008/03/joomla-wins-best-php-open-source-web.html' title='Joomla! Wins Best PHP Open Source Web CMS'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14979786506830002507'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5114420386457021844.post-8963359575468956460</id><published>2008-03-19T02:25:00.000-07:00</published><updated>2008-03-19T02:35:31.948-07:00</updated><title type='text'>Export ASP.NET page to Word, Excel or PDF</title><content type='html'>&lt;div class="postText"&gt; &lt;p&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Many times we would like to export our page as an  Excel sheet, Word doc or PDF file. This can be simply achieved by changing the  ContentType of the Response object and overriding the RenderControl method of  the control to be exported:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Page Load()&lt;br /&gt;{&lt;br /&gt; //bind data to data bound  controls and do other stuff&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;Response.Clear(); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//this clears the  Response of any headers or previous output&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;Response.Buffer = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;; &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//make sure that the entire output is  rendered simultaneously&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;remarks&gt;&lt;br /&gt;&lt;/remarks&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;Set content type to MS Excel  sheet&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;Use &lt;strong&gt;"application/msword"&lt;/strong&gt; for MS Word doc  files&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;strong&gt;"application/pdf"&lt;/strong&gt; for PDF files&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;remarks&gt;&lt;/remarks&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;Response.ContentType = &lt;/span&gt;&lt;span style="font-size:85%;color:#800000;"&gt;"application/vnd.ms-excel"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008080;"&gt;StringWriter&lt;/span&gt;&lt;span style="font-size:85%;"&gt; stringWriter =  &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#008080;"&gt;StringWriter&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//System.IO namespace should be used&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#008080;"&gt;HtmlTextWriter&lt;/span&gt;&lt;span style="font-size:85%;"&gt;  htmlTextWriter = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt;  &lt;/span&gt;&lt;span style="font-size:85%;color:#008080;"&gt;HtmlTextWriter&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(stringWriter);&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;remarks&gt;&lt;br /&gt;&lt;/remarks&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;Render the entire Page control in  the HtmlTextWriter object&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;We can render individual controls also, like a DataGrid to  be&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;exported in custom format (excel, word etc)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.RenderControl(htmlTextWriter);&lt;br /&gt;Response.Write(stringWriter.ToString());&lt;br /&gt;Response.End();&lt;br /&gt;}  //end page load&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;For exporting ASP.NET pages as PDF files, you need  to know the Adobe PDF specs for generating the PDf correctly. There is already a  wonderful component which does the same and its free! See this article along  with sample source code on how to export a page to PDF:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.codeproject.com/cs/library/giospdfnetlibrary.asp"&gt;http://www.codeproject.com/cs/library/giospdfnetlibrary.asp&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Hope this would be helpful...!&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5114420386457021844-8963359575468956460?l=helpingpeoples.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/8963359575468956460/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=5114420386457021844&amp;postID=8963359575468956460' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/8963359575468956460'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/8963359575468956460'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/2008/03/export-aspnet-page-to-word-excel-or-pdf.html' title='Export ASP.NET page to Word, Excel or PDF'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14979786506830002507'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5114420386457021844.post-6637941087238680542</id><published>2008-03-19T02:19:00.000-07:00</published><updated>2008-03-19T02:23:46.562-07:00</updated><title type='text'>Backing Up and Restoring Your MySQL Database</title><content type='html'>Do you need to change your web host or switch your database server? This is  probably the only time when you really think of backing up your MySQL data. If  you've got a website with a database or your custom database running for your  applications, it is imperative that you make regular backups of the database. In  this article, I will outline two easy ways of backing up and restoring databases  in MySQL. &lt;p align="left"&gt;The easiest way to backup your database would be to telnet to the  your database server machine and use the &lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump&lt;/span&gt; command to dump your whole  database to a backup file. If you do not have telnet or shell access to your  server, don't worry about it; I shall outline a method of doing so using the  PHPMyAdmin web interface, which you can setup on any web server which executes  PHP scripts.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Playing with mysqldump&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;If you have either a shell or telnet access to your database server, you can  backup the database using &lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump&lt;/span&gt;. By default, the output of  the command will dump the contents of the database in SQL statements to your  console. This output can then be piped or redirected to any location you want.  If you plan to backup your database, you can pipe the output to a sql file,  which will contain the SQL statements to recreate and populate the database  tables when you wish to restore your database. There are more adventurous ways  to use the output of &lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump&lt;/span&gt;.  &lt;/p&gt; &lt;p&gt;&lt;strong&gt;A Simple Database Backup:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;You can use mysqldump to create a simple backup of your database using the  following syntax. &lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump -u [username] -p [password]  [databasename] &gt; [backupfile.sql]&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;ul&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;[username]&lt;/span&gt; - this is your  database username  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;[password]&lt;/span&gt; - this is the  password for your database  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;[databasename]&lt;/span&gt; - the name of  your database  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;[backupfile.sql]&lt;/span&gt; - the file  to which the backup should be written.&lt;br /&gt; &lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;The resultant dump file will contain all the SQL statements needed to create  the table and populate the table in a new database server. To backup your  database 'Customers' with the username 'sadmin' and password 'pass21' to a file  custback.sql, you would issue the command:&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump -u sadmin -p pass21  Customers &gt; custback.sql&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;You can also ask &lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump&lt;/span&gt; to  add a drop table command before every create command by using the option &lt;span style="font-family:courier new, courier, mono;"&gt;--add-drop-table&lt;/span&gt;. This option is useful  if you would like to create a backup file which can rewrite an existing database  without having to delete the older database manually first.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump --add-drop-table -u sadmin  -p pass21 Customers &gt; custback.sql&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;Backing up only specified tables&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;If you'd like restrict the backup to only certain tables of your database,  you can also specify the tables you want to backup. Let's say that you want to  backup only &lt;em&gt;customer_master&lt;/em&gt; &amp;amp; &lt;em&gt;customer_details&lt;/em&gt; from the  Customers database, you do that by issuing&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump --add-drop-table -u sadmin  -p pass21 Customers customer_master customer_details&gt; custback.sql&lt;/span&gt;  &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;So the syntax for the command to issue is:&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump -u [username] -p [password]  [databasename] [table1 table2 ....]&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;ul&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;[tables]&lt;/span&gt; - This is a list of  tables to backup. Each table is separated by a space&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;If you are a database administrator who has to look after multiple databases,  you'll need to back up more than one database at a time. Here's how you can  backup multiple databases in one shot. &lt;/p&gt; &lt;p&gt;If you want to specify the databases to backup, you can use the &lt;span style="font-family:courier new, courier, mono;"&gt;--databases&lt;/span&gt; parameter followed by the  list of databases you would like to backup. Each database name has to be  separated by at least one space when you type in the command. So if you have to  backup 3 databases, let say Customers, Orders and Comments, you can issue the  following command to back them up. Make sure the username you specify has  permissions to access the databases you would like to backup.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump -u root -p pass21  --databases Customers Orders Comments &gt; multibackup.sql&lt;/span&gt;  &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This is okay if you have a small set of databases you want to backup. Now how  about backing up all the databases in the server? That's an easy one, just use  the &lt;span style="font-family:courier new, courier, mono;"&gt;--all-databases&lt;/span&gt; parameter to  backup all the databases in the server in one step.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump --all-databases&gt;  alldatabases.sql&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;Backing up only the Database Structure&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Most developers need to backup only the database structure to while they are  developing their applications. You can backup only the database structure by  telling mysqldump not to back up the data. You can do this by using the &lt;span style="font-family:courier new, courier, mono;"&gt;--no-data parameter&lt;/span&gt; when you call  mysqldump.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump --no-data --databases  Customers Orders Comments &gt; structurebackup.sql&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;Compressing your Backup file on the Fly&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Backups of databases take up a lot of space. You can compress the output of  mysqldump to save valuable space while you're backing up your databases. Since  mysqldump sends its output to the console, we can pipe the output through gzip  or bzip2 and send the compressed dump to the backup file. Here's how you would  do that with bzip2 and gzip respectively.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump --all-databases | bzip2 -c  &gt;databasebackup.sql.bz2&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump --all-databases | gzip  &gt;databasebackup.sql.gz&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;A Shell Script for Automating Backups?&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;You can automate the backup process by making a small shell script which will  create a daily backup file. How do you get cron to back up your database without  overwriting the older backup? You can use a tiny shell script to add the date to  your backup file. An example of a shell script you could use is shown below.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;#!/bin/sh&lt;br /&gt;date=`date  -I`&lt;br /&gt;mysqldump --all-databases | gzip &gt; /var/backup/backup-$date.sql.gz&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Now that you've got backups of your database, let's learn how to restore your  backup in case your database goes down. Here's how you can restore your backed  up database using the mysql command.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Restore using mysql&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;If you have to re-build your database from scratch, you can easily restore  the &lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump&lt;/span&gt; file by using the  mysql command. This method is usually used to recreate or rebuild the database  from scratch. &lt;/p&gt; &lt;p&gt;Here's how you would restore your &lt;span style="font-family:courier new, courier, mono;"&gt;custback.sql&lt;/span&gt; file to the Customers  database.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysql -u sadmin -p pass21 Customers  &lt;&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Easy isn't it ? Here's the general format you would follow:&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysql -u [username] -p [password]  [database_to_restore] &lt; [backupfile]&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Now how about those zipped files? You can restore your zipped backup files by  first uncompressing its contents and then sending it to mysql.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;gunzip &lt;&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;You can also combine two or more backup files to restore at the same time,  using the cat command. Here's how you can do that.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;cat backup1.sql backup.sql | mysql -u  sadmin -p pass21&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;Moving Data Directly Between Databases&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;How would you like to replicate your present database to a new location? When  you are shifting web hosts or database servers, you can directly copy data to  the new database without having to create a database backup on your machine and  restoring the same on the new server. mysql allows you to connect to a remote  database server to run sql commands. Using this feature, we can pipe the output  from mysqldump and ask mysql to connect to the remote database server to  populate the new database. Let's say we want to recreate the Customers database  on a new database server located at 202.32.12.32, we can run the following set  of commands to replicate the present database at the new server.&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt;&lt;span style="font-family:courier new, courier, mono;"&gt;mysqldump -u sadmin -p pass21  Customers | mysql --host=202.32.12.32 -C Customers&lt;/span&gt; &lt;/p&gt;&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5114420386457021844-6637941087238680542?l=helpingpeoples.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/6637941087238680542/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=5114420386457021844&amp;postID=6637941087238680542' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/6637941087238680542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/6637941087238680542'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/2008/03/backing-up-and-restoring-your-mysql.html' title='Backing Up and Restoring Your MySQL Database'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14979786506830002507'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5114420386457021844.post-7013268755000266229</id><published>2008-03-19T02:02:00.000-07:00</published><updated>2008-03-19T02:11:30.251-07:00</updated><title type='text'>Creating a CAPTCHA with PHP</title><content type='html'>&lt;span style="font-weight: bold;"&gt;How does a CAPTCHA work?&lt;br /&gt;&lt;/span&gt;To put it simply a captcha works by generating a random string, writing it to an  image, then storing the string inside of a session or cookie or by some other  method. This is then checked when the form or operation is performed. Below is a  step by step layout of how it works. 1. Random text generated 2. Text written to  image 3. Text stored in session/cookie/database 4. Image displayed to user 5.  User enters the code 6. User entered code is checked against the stored key 7.  If they match then something is done&lt;br /&gt;&lt;br /&gt;&lt;span class="contentpagetitle"&gt;&lt;b&gt;Creating the random text&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;Right now we are up to generating the random text. To do this I will use the  php functions, microtime() and mktime() to generate a number. This number will  then be encrypted using md5(). With this 32 character long encrypted string we  will then use substr() to cut it down to a 5 letter long string. This is our  random text.&lt;/p&gt; &lt;p&gt;Note: You may notice session_start() at the top of this script, this is to  start the session which will be used later....&lt;/p&gt; &lt;table style="font-size: 9px; background-color: rgb(222, 223, 181);" border="1" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Start the session so we can store what the code actually is. &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;session_start&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Now lets use md5 to generate a totally random string &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$md5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;md5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;microtime&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() * &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mktime&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()); &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;We dont need a 32 character long string so we trim it down to 5&lt;br /&gt;*/ &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;substr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$md5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span class="contentpagetitle"&gt;&lt;b&gt;Writing the text to the image&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;Now that we have the text to write we actually need to write it to the image  and display it to the user. This is made fairly easy with GD.&lt;/p&gt; &lt;table style="font-size: 9px; background-color: rgb(222, 223, 181);" border="1" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Now for the GD stuff, for ease of use lets create &lt;br /&gt; the image from a background image.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$captcha &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;imagecreatefrompng&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"./captcha.png"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Lets set the colours, the colour $line is used to generate lines. &lt;br /&gt; Using a blue misty colours. The colour codes are in RGB&lt;br /&gt;*/ &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$black &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;imagecolorallocate&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$captcha&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;imagecolorallocate&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$captcha&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;233&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;239&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;239&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Now to make it a little bit harder for any bots to break,  &lt;br /&gt;assuming they can break it so far. Lets add some lines &lt;br /&gt;in (static lines) to attempt to make the bots life a little harder&lt;br /&gt;*/ &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;imageline&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$captcha&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;39&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;29&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;imageline&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$captcha&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;40&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;64&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;29&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;As you can see from the code above we are loading the basic image from  CAPTCHA.png instead of building the image itself which could be a little complex  for this basic tutorial. When we use colour in GD we need to allocate the colour  to a variable, we do this with imagecolorallocate(). Once we have the colours  stored inside of the respected variables we then use them to draw the lines  through the image. This is to make the robots job of cracking the captcha just  that little bit harder, because we are nice to the robots like that :)&lt;/p&gt; &lt;p&gt;Finally we have to write the text to the image which is made easy with  imagestring() . The only thing left to do on this image is to output it which is  done by setting the content type of the page to image/png with header() and  outputting the image to the browser with imagepng(). It is also worth mentioning  that the string is encrypted and stored in the session variable  $_SESSION['key']&lt;/p&gt; &lt;table style="font-size: 9px; background-color: rgb(222, 223, 181);" border="1" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Now for the all important writing of the randomly generated string to the image. &lt;br /&gt;*/&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;imagestring&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$captcha&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;20&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$black&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Encrypt and store the key inside of a session&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SESSION&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'key'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;md5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Output the image&lt;br /&gt;*/&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;header&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Content-type: image/png"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;imagepng&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$captcha&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span class="contentpagetitle"&gt;&lt;b&gt;Check if the user entered the code correctly&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;To check if the user entered the code correctly you must first allow the user  to do this. You can do this with a simple text form that requires a code to be  entered, a simple text field called code or something similar should do nicely.  Then you just display the image to the user with a simple &lt;img xsrc="captcha.php" border="0" /&gt; tag. It is really too low a level to show you  how to make a form like this, if you don't know how to make a form like I  described above then this tutorial is probably not for you.&lt;/p&gt; &lt;p&gt;Now assuming that this form has been submitted we need to check if the code  matches what was on the image, after all this is the whole point of a captcha  system. You can do this in any php file as long as the form described above  submits to it. For basic checking we will use the code below.&lt;/p&gt; &lt;table style="font-size: 9px; background-color: rgb(222, 223, 181);" border="1" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;session_start&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Encrypt the posted code field and then compare with the stored key &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;md5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'code'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]) != &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SESSION&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'key'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])&lt;br /&gt;{&lt;br /&gt;  die(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Error: You must enter the code correctly"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}else{&lt;br /&gt;  echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'You entered the code correctly'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;The session_start() you see here simply continues the session from the  previous page, easy enough. Then its just a case of simple text matching which  you can see is done by the if statement&lt;/p&gt;&lt;br /&gt;&lt;span class="contentpagetitle"&gt;&lt;b&gt;Improvements and Conclusion&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;Well that is all there is to CAPTCHA images just a simple writing of text to  an image and storing of the text (key). However the captcha I just described how  to build is not the best in the world by a long shot. If you're feeling  adventurous you could try the following things:&lt;/p&gt;&lt;list&gt; &lt;li&gt;Use a TTF font  &lt;/li&gt;&lt;li&gt;Move the lines randomly  &lt;/li&gt;&lt;li&gt;Randomly position the text on the image  &lt;/li&gt;&lt;li&gt;Rotate the text randomly  &lt;/li&gt;&lt;li&gt;Use words instead of that string (ie: have a randomly picked word out of say  a file of about 1000)&lt;/li&gt;&lt;/list&gt;&lt;subtitle&gt;&lt;/subtitle&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5114420386457021844-7013268755000266229?l=helpingpeoples.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://helpingpeoples.blogspot.com/feeds/7013268755000266229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=5114420386457021844&amp;postID=7013268755000266229' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/7013268755000266229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5114420386457021844/posts/default/7013268755000266229'/><link rel='alternate' type='text/html' href='http://helpingpeoples.blogspot.com/2008/03/creating-captcha-with-php.html' title='Creating a CAPTCHA with PHP'/><author><name>Javal</name><uri>http://www.blogger.com/profile/18071207990208212685</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14979786506830002507'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>