| 
Archives for: July 200930/07/09
				
		
		Create data graph on the fly
				Generating graph from data collected on the internet and shows it on the web can be very useful.  I found 2 ways to create data graph/chart on the fly:
 1. Use the google apihttp://code.google.com/apis/chart/basics.html
 To create a simple pie chart, all you need is one line of html
 XML: |  | <img src="http://chart.apis.google.com/chart?chs=350x100&chd=t:60,40&cht=p3&chl=Web_designers|Programmers"  alt="Sample chart" /> | 
And you will have 
   2. Use php +  GD Libraryto create the same chart you need the following codes. Codes are based on
 http://www.talkphp.com/advanced-php-programming/2508-3d-pie-charts-php-gd.html with small changes 
 PHP: |  | $image = imagecreatetruecolor(300, 300); |  |  |  |  |  | $white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); |  |  | $gray     = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); |  |  | $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90); |  |  | $navy     = imagecolorallocate($image, 0x00, 0x00, 0x80); |  |  | $darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50); |  |  | $red      = imagecolorallocate($image, 0xFF, 0x00, 0x00); |  |  | $darkred  = imagecolorallocate($image, 0x90, 0x00, 0x00); |  |  |   |  |  |  |  |  | imageFill($image, 0, 0, $white); |  |  | imageColorTransparent($image, $white); |  |  |   |  |  |   |  |  | for ($i = 160; $i > 150; $i--) { |  |  |    imagefilledarc($image, 150, $i, 200, 100, 0, 45, $darknavy, IMG_ARC_PIE); |  |  |    imagefilledarc($image, 150, $i, 200, 100, 45, 75 , $darkgray, IMG_ARC_PIE); |  |  |    imagefilledarc($image, 150, $i, 200, 100, 75, 360 , $darkred, IMG_ARC_PIE); |  |  | } |  |  |   |  |  | imagefilledarc($image, 150, 150, 200, 100, 0, 45, $navy, IMG_ARC_PIE); |  |  | imagefilledarc($image, 150, 150, 200, 100, 45, 75 , $gray, IMG_ARC_PIE); |  |  | imagefilledarc($image, 150, 150, 200, 100, 75, 360 , $red, IMG_ARC_PIE); |  |  |   |  |  |  |  |  | header('Content-type: image/png'); |  |  | imagepng($image); |  |  | imagedestroy($image); | 
If you need to know more about using GD Lib to create graph on the web, please visit a tutorial at http://php.about.com/od/advancedphp/ss/gd_library_6.htm You need to be careful when you are using server side script to generate graph as it is CPU intensive.              29/07/09
				
		
		Windows Small Business Server (SBS)'s backup disconnect remote desktop
				I don’t anyone of you know why this could happen: A Windows SBS 2003 would disconnect a remote desktop session when it starts its backup. The default windows backup verifies the backup copy and it takes forever. I have to edit the executive file to stop the verification following this guide: http://www.slickit.ca/2009/05/turn-verify-off-sbs-2003-backup.html  This allows me to re-schedual backup to starts later at night so people can do their work at the early evenings. But this just avoids the problem.  Please let me know if you any idea …              
				
		
		Are you are web design agent?
				If you are  a web design agent and looking for good quality web script programmer, please feel free to contact us. We provide programming service for web design agents in UK.  We have good experience in writing CMS, e-commerce and web-based application in PHP/Mysql, Javascript (Ajax). If you have questions in technical issues, please also feel free to ask.  WE will provide a strong portfolio if required.  Have a good day!             
				
		
		Javascript form validator script
				I have been using the a javascript from   http://www.javascript-coder.com/html-form/javascript-form-validation.phtml for awhile and I totally like it. It’s very easy to use in order to validate the web form. What’s more, it is very easy to extend.  Here is how to extend the script so that it can find out if a user input the right confirm email address or not.     Code: |  | function confirmEmail () |  |  |         { |  |  |           var frm = document.forms["custForm"]; |  |  |           if(frm.email.value != frm.confirm_email.value) |  |  |           { |  |  |             sfm_show_error_msg("Confirm email does not match "); |  |  |             return false; |  |  |           } |  |  |           else |  |  |           { |  |  |             return true; |  |  |           } |  |  |         } |  |  |   |  |  |   frmvalidator.setAddnlValidationFunction("confirmEmail"); | 
            27/07/09
				
		
		How to force a download using php 
				
		
		Image button submit value
				For example, if you have a image button like 
 Code: |  | <input type="image" name="Submit" value='Register' class="btn" src="images/register_form_btn.jpg" /> | 
When the form is submitted via POST. there is nothing for $_POST[’Submit’]. However, you will have $_POST[’Submit_x’] and $_POST[’Submit_y’] that records the x and y coordinates of the click.  You can not do  Code: |  | if($_POST['Submit_x'] ) { |  |  |   //do something  |  |  | } | 
that’s because a user might press the Enter key to submit the form. In this case, $_POST[’Submit_x’] and $_POST[’Submit_y’] are both 0!!
 A convenient solution is to put a hidden field such as 
 Code: |  | <input type='hidden' name='form_sent' value='1'/> | 
within the form. Then in your php code 
 Code: |  | if($_POST['form_sent'] ){ |  |  |  //process form  |  |  | } | 
            22/07/09
				
		
		Harden web server with suhosin
				Suhosin is a “hardened php” project which can improve security of a web server running php script.  If you are having some troubles running some scripts after you’ve installed, you will have to change some of the configuration values. I learned that when one customer has a very large html form to submit data using POST. However, only part of the form data can be accessed via the $_POST variable.  One way to sort it out is to put Code: |  | suhosin.post.max_array_depth = 1024 | 
in the account’s php.ini file.  Another way is to put 
 Code: |  | php_value suhosin.post.max_array_depth = 1024 | 
in your .htaccess file. This only works if your administrator put 
 Code: 
in the global php.ini file. 
 – Ben              
					 |  |