<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Life and Living &#187; PHP</title>
	<atom:link href="http://www.lifenlivin.com/category/university-life/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lifenlivin.com</link>
	<description>Destroyed in the horizon.</description>
	<lastBuildDate>Tue, 08 Jun 2010 20:01:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Buggy header in php</title>
		<link>http://www.lifenlivin.com/2010/02/buggy-header-in-php/</link>
		<comments>http://www.lifenlivin.com/2010/02/buggy-header-in-php/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 16:28:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[University life]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[php header function]]></category>

		<guid isPermaLink="false">http://www.lifenlivin.com/?p=131</guid>
		<description><![CDATA[Today, I got a problem in a php script. I was using header() function in the if-else branching. The code is something like
if(condition1)
{
header(&#8221;Location:dummy.php?err=1&#8243;);
}
else
{
header(&#8221;Location:dummy.php?err=2&#8243;);
}
if(condition2)
{
header(&#8221;Location:dummy.php?err=3&#8243;);
}
else
{
header(&#8221;Location:dummy.php?err=4&#8243;);
}
a contition may fullfill both condition 1 and 2. But in this case I want to go through the first if clause. I run the script and saw that the final page is [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I got a problem in a php script. I was using header() function in the if-else branching. The code is something like</p>
<p>if(condition1)</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=1&#8243;);</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=2&#8243;);</p>
<p>}</p>
<p>if(condition2)</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=3&#8243;);</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=4&#8243;);</p>
<p>}</p>
<p>a contition may fullfill both condition 1 and 2. But in this case I want to go through the first if clause. I run the script and saw that the final page is dummy.php?err=3. But I supposed to get err=1. The question is why this happened? I found its answer. The first condition is fullfilled and the page is directed to dummy.php?err=1, the script does not exit, rather it run from where it was redirected. Then the second condtion is fullfilled. So the page is redirected again to dummy.php?err=3.</p>
<p>The solution is to use exit() function after each header() function so that the script cannot run further after redirection.</p>
<p>The correct code will be,</p>
<p>if(condition1)</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=1&#8243;);</p>
<p>exit();</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=2&#8243;);</p>
<p>exit();</p>
<p>}</p>
<p>if(condition2)</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=3&#8243;);</p>
<p>exit();</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>header(&#8221;Location:dummy.php?err=4&#8243;);</p>
<p>exit();</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lifenlivin.com/2010/02/buggy-header-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Move uploaded file problem</title>
		<link>http://www.lifenlivin.com/2010/02/move-uploaded-file-problem/</link>
		<comments>http://www.lifenlivin.com/2010/02/move-uploaded-file-problem/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 13:14:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[University life]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[move uploaded file]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[shell command]]></category>

		<guid isPermaLink="false">http://www.lifenlivin.com/?p=121</guid>
		<description><![CDATA[Today I faced a new problem in php coding. I was coding a simple file uploader class. I used regular script as I do. A warning is found at move_uploaded_file() function. I passed some time googling about it. I found that the function cannot access the directory I have mentioned. I made a command on [...]]]></description>
			<content:encoded><![CDATA[<p>Today I faced a new problem in php coding. I was coding a simple file uploader class. I used regular script as I do. A warning is found at move_uploaded_file() function. I passed some time googling about it. I found that the function cannot access the directory I have mentioned. I made a command on the bash shell, ls -l, and saw that only the root user have the writing permission on that directory. That is why a client cannot upload file using that script. I againg made a command on the bash shell sudo chmod +w folder. Then  the script run correctly.</p>
<p>I saw another porblem about the directory. If you use ../ in the directory path, the returned path is path of immediate parent of the current folder. But ../../ is not accepted. So to go two or more step beyond the current directory you need to get the destination path name manually. getcwd() returns current working directory. A way to find the directory path of the current script is to use dirname(__FILE__). Once you find the directory path, now you can edit it to go two or more step beyond.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lifenlivin.com/2010/02/move-uploaded-file-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP mail function</title>
		<link>http://www.lifenlivin.com/2009/09/php-mail-function/</link>
		<comments>http://www.lifenlivin.com/2009/09/php-mail-function/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 11:21:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php mail function]]></category>

		<guid isPermaLink="false">http://www.lifenlivin.com/?p=94</guid>
		<description><![CDATA[Many people practise php on a virtual server on the desktop. Since the local hsot of the desktop is not registered to any Internet Service Provider, all the php built in function will not  work in local host.
Few days ago, I was trying to send mail from my localhost. Everytime it says undefined function. I [...]]]></description>
			<content:encoded><![CDATA[<p>Many people practise php on a virtual server on the desktop. Since the local hsot of the desktop is not registered to any Internet Service Provider, all the php built in function will not  work in local host.</p>
<p>Few days ago, I was trying to send mail from my localhost. Everytime it says undefined function. I used mail() function to send the mail. Actually there is no error in the mail code. My fault was that I was running it on my desktop, not in the server. When I moved the code to my domain, it worked successfully.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lifenlivin.com/2009/09/php-mail-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracking an user</title>
		<link>http://www.lifenlivin.com/2009/09/tracking-an-user/</link>
		<comments>http://www.lifenlivin.com/2009/09/tracking-an-user/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 16:56:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[remote_addr]]></category>
		<category><![CDATA[track]]></category>
		<category><![CDATA[track ip]]></category>
		<category><![CDATA[tracking user in php]]></category>

		<guid isPermaLink="false">http://www.lifenlivin.com/?p=89</guid>
		<description><![CDATA[Tracking an user is very easy in php. It requires a single line to get the client ip address.
The line is $ip=$_SERVER['REMOTE_ADDR'];
Easy. Isn&#8217;t it?
Just put the following code in a php file and upload to your domain.
&#60;?php
echo $_SERVER['REMOTE_ADDR'];
?&#62;
Then open the page using your browser. It will print your ip address. Check it.
If you do this [...]]]></description>
			<content:encoded><![CDATA[<p>Tracking an user is very easy in php. It requires a single line to get the client <a href="http://en.wikipedia.org/wiki/IP_address" target="_blank">ip address</a>.</p>
<p>The line is $ip=$_SERVER['REMOTE_ADDR'];</p>
<p>Easy. Isn&#8217;t it?</p>
<p>Just put the following code in a php file and upload to your domain.</p>
<p>&lt;?php<br />
echo $_SERVER['REMOTE_ADDR'];<br />
?&gt;</p>
<p>Then open the page using your browser. It will print your ip address. Check it.</p>
<p>If you do this to your localhost (not in the server), it will print the virtual server ip address that is 127.0.0.1 which is default for all localhost (not in the server but may be built up in desktop)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lifenlivin.com/2009/09/tracking-an-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP header already sent error</title>
		<link>http://www.lifenlivin.com/2009/08/php-header-already-sent-error/</link>
		<comments>http://www.lifenlivin.com/2009/08/php-header-already-sent-error/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 17:13:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[header already sent error]]></category>
		<category><![CDATA[header error]]></category>
		<category><![CDATA[header problem]]></category>

		<guid isPermaLink="false">http://www.lifenlivin.com/?p=81</guid>
		<description><![CDATA[Few days ago I made a silly mistake in my php coding. I have echoed something on the page where I have set the cookie.  It seems that it is not faulty code. I googled the problem and found the solution from php.net. Actually cookie must be called before anything goes to browser from server.
So [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I made a silly mistake in my php coding. I have echoed something on the page where I have set the cookie.  It seems that it is not faulty code. I googled the problem and found the solution from php.net. Actually cookie must be called before anything goes to browser from server.</p>
<p>So If you echo anything or show anything before setting the cookie, the page will say that cannot modify header. Header already sent by&#8230;&#8230;.. or something like this.</p>
<p>Another silly mistake many of my friend made is that they paste some code before the session_start() function. This should not be done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lifenlivin.com/2009/08/php-header-already-sent-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP CAPTCHA generator</title>
		<link>http://www.lifenlivin.com/2009/08/php-captcha-generator/</link>
		<comments>http://www.lifenlivin.com/2009/08/php-captcha-generator/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 13:03:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[captcha stands for]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.lifenlivin.com/?p=54</guid>
		<description><![CDATA[CAPTCHA stands for Completely Automated Public Turing test to tell Computers and Humans Apart. The term captcha was first coined by Luis von Ahn, Manuel Blum, Nicholas J. Hooper and John Langford. The first three are from Carnegie Mellon University and last one is from IBM. We will see how easily we can produce captcha [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.captcha.net" target="_blank">CAPTCHA</a> stands for <strong>C</strong>ompletely <strong>A</strong>utomated <strong>P</strong>ublic <strong>T</strong>uring test to tell <strong>C</strong>omputers and <strong>H</strong>umans <strong>A</strong>part. The term captcha was first coined by Luis von Ahn, Manuel Blum, Nicholas J. Hooper and John Langford. The first three are from Carnegie Mellon University and last one is from IBM. We will see how easily we can produce captcha using the <a href="http://www.php.net" target="_blank">PHP</a> web programming.</p>
<p>Lets define a class called captcha.</p>
<p>&lt;?php</p>
<p>class captcha</p>
<p>{</p>
<p>}</p>
<p>?&gt;</p>
<p>Now we need some variable to show and store captcha string in the webpage. So we need some variable. Lets have some variable in the captcha class.</p>
<p>&lt;?php<br />
class captcha<br />
{<br />
private $final_string;<br />
private $image;<br />
private $height;<br />
private $width;<br />
private $text_color;<br />
private $line_color;<br />
private $bgcolor;</p>
<p>?&gt;</p>
<p>Now we have to generate the captcha string and paint it in an image, so that the bots can&#8217;t read it. We can do this thing in the constructor of the class.</p>
<p>function __construct()<br />
{<br />
session_start();<br />
session_cache_limiter(&#8217;public&#8217;);<br />
session_cache_expire(5);<br />
$height=26;<br />
$width=100;<br />
$image=ImageCreate($width,$height);<br />
$bgcolor=ImageColorAllocate($image,240,255,240);<br />
ImageFill($image,0,0,$bgcolor);<br />
$temp_string=&#8221;";<br />
$final_string=$temp_string;<br />
$length=rand(5,10);<br />
for($a=0;$a&lt;$length;$a++)<br />
{<br />
$t=rand(48,122);<br />
if($t&lt;91||$t&gt;96)<br />
{<br />
$temp_string=chr($t);<br />
$final_string.=$temp_string;<br />
}<br />
else $a&#8211;;</p>
<p>}<br />
$_SESSION['result']=$final_string;<br />
//setTextColor();</p>
<p>$r=rand(20,30);<br />
$b=rand(20,30);<br />
$g=rand(100,120);<br />
$text_color=ImageColorAllocate($image,$r,$b,$g);</p>
<p>//createDotDotDash();</p>
<p>for($a=0;$a&lt;40;$a+=2)<br />
{<br />
$line_color=ImageColorAllocate($image,rand(220,240),rand(220,240),rand(240,260));<br />
imagedashedline($image,0,$a,$width,$a,$line_color);<br />
}<br />
ImageString($image,20,5,5,$final_string,$text_color);<br />
ImageRectangle($image,0,0,$width-1,$height-1,$bgcolor);<br />
header(&#8221;Content-Type: image/jpeg&#8221;);<br />
ImageJpeg($image);<br />
ImageDestroy($image);<br />
}</p>
<p>Now come to description. session_start() is a built-in function to start session for user if not started. We defined our session cache as public. Because the cache control is public and the session will expire sometime in future. Now we defined the expire time as 5 minute using the session_cache_expire() function. $height is the height of our captcha image and $width is the width. $image is our image resource which is created by ImageCreate() function. We have a $bgcolor to hold the color of the background. A color can be allocated to a variable using imagecolorallocate() function with the RGB value. imagefill() function is used to fill the image with background color.$temp_string is for temporary use. We will keep our final captcha string in $final_string. The length of the captcha string is kept in $length. A for loop is used to generate the captcha string tokens with rand() function. The final captcha string is then kept to the session variable. The text color is defined in $text_color. Dashed lines are used inside the captcha image where the dashed lines have a range of random color.</p>
<p>The captcha string is written to the image using imagestring() function. The header function is used to keep the type in the image header. The drawn image is then put to ImageJpeg() function to get an output. Finally imagedestroy() function frees the memory associated with the image in the server.</p>
<p>Let us put the captcha.php file on captcha folder. Now we create another file checkbot.php in the root where the captcha folder exists.</p>
<p>&lt;?php<br />
require(&#8217;captcha/captcha.php&#8217;);<br />
$a=new captcha();<br />
?&gt;</p>
<p>The require() function is not like include(), the captcha.php file is ready to be used in the checkbot.php but its code is not put here. $a is a object of captcha class.</p>
<p>Now the code is ready to generate captcha code for you. We need a refresh function to regenerate the captcha string. A javascript code is a better choice for this. A refresh image is needed for this too.</p>
<p>Just copy and paste the script in the page head.</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
function refresh()<br />
{<br />
var ran=Math.floor(Math.random()*10);<br />
var path=document.getElementById(&#8221;imgsrc&#8221;).src;<br />
document.getElementById(&#8221;imgsrc&#8221;).src=path+&#8221;?rand=&#8221;+ran;<br />
}<br />
&lt;/script&gt;</p>
<p>Variable ran contains a random number and path gets the path of a element which have an id called &#8220;imgsrc&#8221;. Our captcha image id will be &#8220;imgsrc&#8221;. And the image is redrawn by sending a new path of the image source to the document.getElementById().src which is the image source itself.</p>
<p>Put the following html code to generate the captcha where you want to be.</p>
<p>&lt;img id=&#8221;imgsrc&#8221; src=&#8221;checkbot.php&#8221; align=&#8221;absmiddle&#8221;/&gt;&lt;img src=&#8221;refresh.gif&#8221; onClick=&#8221;javascript:refresh();&#8221; align=&#8221;absmiddle&#8221; /&gt;&lt;input type=&#8221;text&#8221; name=&#8221;security_code&#8221; size=&#8221;10&#8243; align=&#8221;absmiddle&#8221; /&gt;</p>
<p>You can change the value of the tag attributes to customize yourself.</p>
<p>Download the captcha.php and checkbot.php file from <a href="http://www.lifenlivin.com/download/captcha.zip">here</a>.</p>
<p>This is one of the simplest captcha, captcha should be hard enough to bypass, so it should not be designed insecuedly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lifenlivin.com/2009/08/php-captcha-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pie diagram in PHP</title>
		<link>http://www.lifenlivin.com/2009/07/pie-diagram-in-php/</link>
		<comments>http://www.lifenlivin.com/2009/07/pie-diagram-in-php/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 10:21:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imagecolorallocate]]></category>
		<category><![CDATA[imagecreate]]></category>
		<category><![CDATA[imagefilledarc]]></category>

		<guid isPermaLink="false">http://www.lifenlivin.com/?p=43</guid>
		<description><![CDATA[PHP is a very powerful web scripting language. We can easily create images on web page using php.
Now the question is there are thousands of image editing software to create marvellous images, why we need php script to draw image for us.
The answer is php is dynamic. Most of the image editing software are designed [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is a very powerful web scripting language. We can easily create images on web page using php.</p>
<p>Now the question is there are thousands of image editing software to create marvellous images, why we need php script to draw image for us.</p>
<p>The answer is php is dynamic. Most of the image editing software are designed to create still images. But in some case we need a dynamic image such as in CAPTCHA, or current web statistics, or progress bar and so on.</p>
<p>Suppose we have to draw a pie chart which will get its value changed every minute or manually by operator. So the pie chart will be changed as the values will be changed.</p>
<p>Lets start with</p>
<p color="yellow">&lt;?php<br />
?&gt;
</p>
<p>That is out php script begining. Let our file name is pie.php and it is a target file of another file say bowler.php which provides the updated data every minutes.</p>
<p>Assume that we are building a pie chart for a cricket score board specially for the bowler&#8217;s statistics.  Let we divide the bowler&#8217;s delivery in some categories say good length, short pitched, full toss. So we have to divide the pie chart by three category.<br />
Assume we get the statistics as POST data and receive the data as</p>
<p>$good=(int)$_POST['good'];<br />
$short=(int)$_POST['short'];<br />
$full_toss=(int)$_POST['full'];</p>
<p>Ok I have taken three data. Now I need to make a sum and calculate their percentage angle with respect to 360 degree.</p>
<p>$tot=$good+$short+$full_toss;<br />
$p_good=$good*360/$tot;<br />
$p_short=$short*360/$tot;<br />
$p_full=$full_toss*360/$tot;</p>
<p>Ok I have calculated the percentage angle now I will create the pie diagram. It can be easily done with <a href="http://www.php.net/manual/en/function.imagefilledarc.php">imagefilledarc()</a> function.</p>
<p>Lets discuss something about imagefilledarc() funciton. The function actually looks like bool imagefilledarc (resource $image,int $center_x,int $center_y,int $width,int $height,int $start_angle, int $end_angle, int $color, int $stylle)</p>
<p>Lets see what the parameter do;<br />
$image= a resource which can be create by imagecreate() funciton;<br />
$center_x= the x coordinate of the center of the arc<br />
$center_y= the y coordinate of the center of the arc<br />
$width= the width of the arc<br />
$height= the height of the arc;<br />
The arc is drown clockwise<br />
$start_angle= the starting angle of the arc in degree;<br />
$end_angle=the ending angle of the arc in degree;<br />
here 0 degree means the position of 3&#8242;O clock position;<br />
$color= it is the integer representing color, which can be obtained by using the funciton imagecolorallocate() function.<br />
And finally the $style takes some built in integer such as IMG_ARC_PIE, IMG_ARC_CHORD, IMG_ARC_NOFILL, IMG_ARC_EDGED;<br />
We will use IMG_ARC_PIE to generate pie diagram.</p>
<p>Lets draw</p>
<p>&lt;?php<br />
$temp_image=ImageCreate(400,400);<br />
// now allocating color<br />
$bg=ImageColorAllocate($temp_image,255,255,255);// this will be our background color<br />
$good_color=ImageColorAllocate($temp_image,0,139,139);// dark cyan<br />
$short_color=ImageColorAllocate($temp_image,255,105,180);// hot pink<br />
$full_color=ImageColorAllocate($temp_image,255,69,0);// orange pink<br />
//good length starts from 0 degree;<br />
$start_angle=0;<br />
$end_angle=$p_good;</p>
<p>imagefilledarc($temp_image,200,200,200,200,$start_angle,</p>
<p>$end_angle,$good_color,IMG_ARC_PIE);</p>
<p>$start_angle=$end_angle;// the second pie start where the first pie ends<br />
$end_angle=$start_angle+$p_short;</p>
<p>imagefilledarc($temp_image,200,200,200,200,$start_angle,</p>
<p>$end_angle,$short_color,IMG_ARC_PIE);</p>
<p>$start_angle=$end_angle;<br />
$end_angle=$start_angle+$p_full;</p>
<p>imagefilledarc($temp_image,200,200,200,200,$start_angle,</p>
<p>$end_angle,$full_color,IMG_ARC_PIE);</p>
<p>header (&#8221;Content-type: image/jpeg&#8221;);<br />
ImageJPEG($temp_image);</p>
<p>ImageDestroy($temp_image);// we have to destroy the image after drawing<br />
// else it will occupy memory in server<br />
?&gt;</p>
<p>We can use a html form to supply data<br />
like the following bowler.php page</p>
<p>bowler.php<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;p align=&#8221;center&#8221;&gt;Enter the data&lt;/p&gt;<br />
&lt;table align=&#8221;center&#8221; width=&#8221;500&#8243;&gt;<br />
&lt;tbody&gt;<br />
&lt;form name=&#8221;form1&#8243; action=&#8221;pie.php&#8221; method=&#8221;post&#8221;&gt;<br />
&lt;tr&gt;<br />
&lt;td width=&#8221;250&#8243;&gt;Good Length bowl&lt;/td&gt;&lt;td&gt;&lt;input type=&#8221;text&#8221; size=&#8221;15&#8243; name=&#8221;good&#8221;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td width=&#8221;250&#8243;&gt;Short pitched bowl&lt;/td&gt;&lt;td&gt;&lt;input type=&#8221;text&#8221; size=&#8221;15&#8243; name=&#8221;short&#8221;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td width=&#8221;250&#8243;&gt;Full toss bowl&lt;/td&gt;&lt;td&gt;&lt;input type=&#8221;text&#8221; size=&#8221;15&#8243; name=&#8221;full&#8221;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td width=&#8221;250&#8243;&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=&#8221;submit&#8221; value=&#8221;submit&#8221; name=&#8221;submit&#8221;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/form&gt;<br />
&lt;/tbody&gt;<br />
&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
And the final code of pie.php will be</p>
<p>pie.php<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
&lt;?php<br />
$good=(int)$_POST['good'];<br />
$short=(int)$_POST['short'];<br />
$full_toss=(int)$_POST['full'];<br />
$tot=$good+$short+$full_toss;</p>
<p>$p_good=$good*360/$tot;<br />
$p_short=$short*360/$tot;<br />
$p_full=$full_toss*360/$tot;</p>
<p>$temp_image=ImageCreate(400,400);<br />
// now allocating color<br />
$bg=ImageColorAllocate($temp_image,255,255,255);// this will be our background color<br />
$good_color=ImageColorAllocate($temp_image,0,139,139);// dark cyan<br />
$short_color=ImageColorAllocate($temp_image,255,105,180);// hot pink<br />
$full_color=ImageColorAllocate($temp_image,255,69,0);// orange pink<br />
//good length starts from 0 degree;<br />
$start_angle=0;<br />
$end_angle=$p_good;<br />
imagefilledarc($temp_image,200,200,200,200,$start_angle,</p>
<p>$end_angle,$good_color,IMG_ARC_PIE);</p>
<p>$start_angle=$end_angle;// the second pie start where the first pie ends<br />
$end_angle=$start_angle+$p_short;</p>
<p>imagefilledarc($temp_image,200,200,200,200,$start_angle,</p>
<p>$end_angle,$short_color,IMG_ARC_PIE);</p>
<p>$start_angle=$end_angle;<br />
$end_angle=$start_angle+$p_full;</p>
<p>imagefilledarc($temp_image,200,200,200,200,$start_angle,</p>
<p>$end_angle,$full_color,IMG_ARC_PIE);</p>
<p>header (&#8221;Content-type: image/jpeg&#8221;);<br />
ImageJPEG($temp_image);</p>
<p>ImageDestroy($temp_image);<br />
?&gt;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
I will discuss how a captcha generator work in the next <a href="http://www.lifenlivin.com/category/university-life/php/">PHP</a> post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lifenlivin.com/2009/07/pie-diagram-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<script type="text/javascript">var infolink_pid = 35265;</script>
<script type="text/javascript" src="http://resources.infolinks.com/js/infolinks_main.js"></script>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
try {
_uacct = "UA-4832193-1";
urchinTracker();
} catch(err) {}</script>

