<?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>Matthew Steven Kelly &#187; PHP</title>
	<atom:link href="http://www.matthewstevenkelly.com/blog/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.matthewstevenkelly.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 05 Feb 2012 04:43:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Generating an image from text</title>
		<link>http://www.matthewstevenkelly.com/blog/random/generating-image-from-text.html</link>
		<comments>http://www.matthewstevenkelly.com/blog/random/generating-image-from-text.html#comments</comments>
		<pubDate>Tue, 24 Mar 2009 01:23:24 +0000</pubDate>
		<dc:creator>Matthew Steven Kelly</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.matthewstevenkelly.com/blog/?p=496</guid>
		<description><![CDATA[&#8221; /> How did I do that? Generating an image from text can be easy with PHP and GD. This requires GD 1.8 or higher. Check out www.php.net for an exact description of the php functions used in this code. &#8230; <a href="http://www.matthewstevenkelly.com/blog/random/generating-image-from-text.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><?php<br />
if(!isset($_POST['text_value']))<br />
{<br />
$_POST['text_value'] = "This is an image displaying text from the input box";<br />
}<br />
?></p>
<p><img src="/includes/generate_image.php?text=<?php echo $_POST['text_value'];?>&#8221; alt=&#8221;<?php echo $_POST['text_value'];?>&#8221; /></p>
<form method="post" action="http://www.matthewstevenkelly.com/blog/kb/php/generating-image-from-text.html">
<p>Text to display:<br />
<input type="text" maxlength="60" style="width:100%;" name="text_value" value="<?php echo $_POST['text_value'];?>&#8221; /></p>
<input type="submit" name="Generate image" />
</form>
<p>How did I do that?</p>
<p>Generating an image from text can be easy with PHP and GD. This requires GD 1.8 or higher.</p>
<p>Check out www.php.net for an exact description of the php functions used in this code. They are all pretty much built in GD functions.</p>
<p>Now the part that make this code great is that there is no temporary files saved on the server, it is all done in memory. </p>
<p>Save this code as <i>generate_image.php</i></p>
<div style="background-color:#CCCCCC;overflow-x:auto;width:100%;">
<p>&lt;?php<br />
function trimLength($data,$len)<br />
{<br />
  if(strlen($data)>$len)<br />
  {<br />
    $data = substr($data,0,$len);<br />
  }<br />
  return $data;<br />
}</p>
<p>function filterText($data)<br />
{<br />
  return preg_replace(&quot;/[^A-Za-z0-9.,\s\s+]/&quot;,&quot;&quot;,$data);<br />
}</p>
<p>$text = filterText($_GET[&apos;text&apos;]); // remove all illegal characters<br />
$text = trimLength($text, 60); // trim to sixty characters<br />
if($text == &quot;&quot;) { $text = &quot;Text&quot;; }</p>
<p>$font  = 4;<br />
$width  = ImageFontWidth($font) * strlen($text);<br />
$height = ImageFontHeight($font);</p>
<p>header(&quot;Content-type: image/gif;&quot;);<br />
$im = @imagecreatetruecolor($width, $height)<br />
      or die(&apos;Cannot Initialize new GD image stream&apos;);<br />
$text_color = imagecolorallocate($im, 0, 0, 0);<br />
$COULEUR_BLANC=imagecolorallocate($im,255,255,255) ;<br />
imagefilledrectangle($im,0,0,$width,$height,$COULEUR_BLANC) ;<br />
imagestring($im, $font, 0, 0, $text, $text_color);<br />
imagegif($im);<br />
imagedestroy($im);<br />
?&gt;</p></div>
<p>And then on the page you want the image created add this code</p>
<div style="background-color:#CCCCCC;overflow-x:auto;width:100%;">
&lt;img src=&quot;generate_image.php?text=The security code is 9999&quot; alt=&quot;&quot; /&gt;
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.matthewstevenkelly.com/blog/random/generating-image-from-text.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Task Schedule Web Script From Windows</title>
		<link>http://www.matthewstevenkelly.com/blog/random/task-schedule-web-script-from-windows.html</link>
		<comments>http://www.matthewstevenkelly.com/blog/random/task-schedule-web-script-from-windows.html#comments</comments>
		<pubDate>Tue, 10 Feb 2009 03:26:40 +0000</pubDate>
		<dc:creator>Matthew Steven Kelly</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.matthewstevenkelly.com/blog/?p=425</guid>
		<description><![CDATA[If your website hosting is of the Linux variety, you know you can schedule scripts to automatically run using cron jobs. But what if your servers are all of the Windows variety? Not a problem, Windows provides the Windows Task &#8230; <a href="http://www.matthewstevenkelly.com/blog/random/task-schedule-web-script-from-windows.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If your website hosting is of the Linux variety, you know you can schedule scripts to automatically run using cron jobs. But what if your servers are all of the Windows variety? Not a problem, Windows provides the Windows Task Scheduler.</p>
<p>Lets say you have a php script that sends out emails to a newsletter list, but because you do not want to flood your email servers, you would like to have the server send out (20) emails every 30 minutes to keep your daily total under 1000 emails/day. You could generate a script that every time it was executed grabbed the next 20 emails from a database list and send them a predefined email.</p>
<p>Or if you have a database that has a large amount of volume, so to conserve space you only want to keep data that is less than 30 days old. You could create a script that executes a query to delete any content older than 30 days. With the task scheduler, you could have this script run every night.</p>
<p>Or if you have a production database and need to email a report out every hour, you could create a script to do so and task schedule it.</p>
<p>Or any other task you wish to have repeated on a scheduled basis and can easily script the task. This is a great tool for developers who are only familiar with scripting languages like PHP, ASP, etc and can complete advanced tasks in them that would otherwise be done by coding a C++ or C# server application.</p>
<p>Lets go with scheduling the email script example above for a walk through on setting up the Windows Task Scheduler.</p>
<p>On the Windows server (note this does not have to be the web server &#8211; it can be any Windows machine that will be running 24/7 to be able to execute the script when scheduled) go to &#8220;Start | Control Panel | Scheduled Tasks&#8221;.</p>
<ol>
<li>Click the Add Scheduled Task button</li>
<li>Click Next</li>
<li>Select Internet explorer from the list and click Next</li>
<li>Select Perform this task Daily (we&#8217;ll change it later) and click Next</li>
<li>Click Next on the task start time</li>
<li>Enter your username and password of the computer</li>
<li>Check the open advanced properties checkbox and click Finish</li>
</ol>
<p>In advanced properties</p>
<ol>
<li>Add &#8220;www.mywebsite.com/mail.php&#8221; after &#8220;C:\PROGRA~1\INTERN~1\iexplore.exe&#8221; in the &#8220;Run&#8221; Section. The field will look like this: &#8220;<i>C:\PROGRA~1\INTERN~1\iexplore.exe www.mywebsite.com/mail.php</i>&#8220;</li>
<li>Click on the schedule tab and click advanced</li>
<li>Check &#8220;Repeat Task&#8221; and say every 30 minutes for 24 hours.</li>
<li>Click OK</li>
<li>Click OK</li>
<li>Enter the Windows user name and password again</li>
</ol>
<p>Internet explorer will pop up and execute the script every 30 minutes now.</p>
<p>Need the script to have a few layers of security? Here are a few things you can add:</p>
<ul>
<li>Utilize SSL encryption and setup the task scheduler to access the page via https:// instead of http:// this ensures any data transmitted between the web server and computer running the task scheduler is encrypted.</li>
<li>Have the web page look for a specific cookie on the computer making the request to execute the script. Then add a method to the script to allow for the one time creation of the cookie, such as <i>mail.php?generatecookie=1</i>. Now on any computer you need to run the task scheduler, first generate the cookie on the computer, then run the scheduler.</li>
<li>Have the script check the IP address of where the request is coming from and only allow it to execute if it is the IP address of the server running task scheduler. With PHP you can detect the IP address of where the web request is coming from using &#8220;$_SERVER['REMOTE_ADDR']&#8221; (note: only works if you have a static IP address and keep in mind IP addresses can be spoofed).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.matthewstevenkelly.com/blog/random/task-schedule-web-script-from-windows.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Input Validation</title>
		<link>http://www.matthewstevenkelly.com/blog/kb/php-input-validation.html</link>
		<comments>http://www.matthewstevenkelly.com/blog/kb/php-input-validation.html#comments</comments>
		<pubDate>Thu, 05 Feb 2009 02:25:44 +0000</pubDate>
		<dc:creator>Matthew Steven Kelly</dc:creator>
				<category><![CDATA[The Knowledgebase]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">https://www.matthewstevenkelly.com/blog/?p=315</guid>
		<description><![CDATA[Any time time a user inputs data to your site the input should be validated to ensure it cannot cause any harm to the system. The obvious characters that cause problems are double and single quotes which are used in &#8230; <a href="http://www.matthewstevenkelly.com/blog/kb/php-input-validation.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Any time time a user inputs data to your site the input should be validated to ensure it cannot cause any harm to the system. The obvious characters that cause problems are double and single quotes which are used in injection attacks to trick the server into executing malicious code. However, there are many other special characters and situations that can cause problems. This is especially important with taking input data and storing it a database, or emailing it off, etc.</p>
<p>PHP has built in functions to handle these tasks including <em>preg_replace</em> and <em>substr</em>. I created some functions below that I use for field validation:</p>
<p>They can be called like this:</p>
<div style="width: 100%; background-color: #cccccc; overflow: auto;">
<div>&lt;?php</div>
<div>echo trimLength(&#8220;This is a long string that needs to be cut down to ten characters&#8221;,10);</div>
<div>echo &#8220;&lt;br&gt;&#8221;;</div>
<div>echo filterText(&#8220;This @is$ t%ex&amp;t w*ith $bad character*()@&#8217;s that need filtered&#8221;);</div>
<div>echo &#8220;&lt;br&gt;&#8221;;</div>
<div>echo filterNumeric(&#8220;1234ABCD&#8221;);</div>
<div>echo &#8220;&lt;br&gt;&#8221;;</div>
<div>echo filterEmail(&#8220;fake&#8217;s_email@^liar.com&#8221;);</div>
<div>echo &#8220;&lt;br&gt;&#8221;;</div>
<div>?&gt;</div>
</div>
<p><a href="http://www.php.net/substr">substr</a> is used to trim the length of text like below. This is especially useful when inputting data into a database fields such as varchar that have limited character lengths.</p>
<div style="width: 100%; background-color: #cccccc; overflow: auto;">function trimLength($data,$len)<br />
{<br />
if(strlen($data)&gt;$len)<br />
{<br />
$data = substr($data,0,$len);<br />
}<br />
return $data;<br />
}</div>
<p>For the rest of my filtering, I always use regular expressions to filter out bad characters. I do this because regular expressions allow you to filter characters by specifying what characters you allow &#8211; not what characters you want to reject. This is an important distinction because there are so many different character sets and special characters that if you only filter by character replacement, instead of character exclusion, you open yourself up to faulty characters entering the system. If you are currently using <a href="http://www.php.net/str_replace">str_replace</a> to remove apostrophe&#8217;s and quote&#8217;s consider upgrading to regular expressions.</p>
<p>This text filtering allows for periods, comma&#8217;s and spaces to be used in the text:</p>
<div style="width: 100%; background-color: #cccccc; overflow: auto;">
<div>function filterText($data)</div>
<div>{</div>
<div>return preg_replace(&#8220;/[^A-Za-z0-9.,\s\s+]/&#8221;,&#8221;",$data);</div>
<div>}</div>
</div>
<p>Only numbers are returned with this function:</p>
<div style="width: 100%; background-color: #cccccc; overflow: auto;"><code>function filterNumeric($data)<br />
{<br />
return preg_replace("/[^0-9]/","",$data);<br />
}</code></div>
<p>When you need to filter a URL, different special characters such as ?, % and / are to be allowed</p>
<div style="width: 100%; background-color: #cccccc; overflow: auto;"><code>function filterURL($data)<br />
{<br />
return preg_replace("/[^A-Za-z0-9:_\%\-.\/\?,+]/","",$data);<br />
}</code></div>
<p>This email filtering function doesn&#8217;t just filter the characters in email address it also validates it is in username@domain.domaintype format:</p>
<div style="width: 100%; background-color: #cccccc; overflow: auto;"><code>function filterEmail($data)<br />
{<br />
list($username, $domain) = explode("@", $data, 2);<br />
$username = preg_replace("/[^a-z0-9._-]+/i", "", $username);<br />
$domain = preg_replace("/[^a-z0-9._-]+/i", "", $domain);<br />
if ( $username == "" || $domain == "" || !strpos($domain,"."))<br />
{<br />
return "";<br />
}<br />
else<br />
{<br />
return $username."@".$domain;<br />
}<br />
}</code></div>
]]></content:encoded>
			<wfw:commentRss>http://www.matthewstevenkelly.com/blog/kb/php-input-validation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Master</title>
		<link>http://www.matthewstevenkelly.com/blog/career/php-master.html</link>
		<comments>http://www.matthewstevenkelly.com/blog/career/php-master.html#comments</comments>
		<pubDate>Wed, 03 Dec 2008 02:14:32 +0000</pubDate>
		<dc:creator>Matthew Steven Kelly</dc:creator>
				<category><![CDATA[My Career]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">https://www.matthewstevenkelly.com/blog/?p=127</guid>
		<description><![CDATA[Matthew Steven Kelly Click here: View Profile to view my Experts Exchange profile. Click here: View Certificate to view my PHP certificate. And more information about Experts-Exchange and me: http://www.matthewstevenkelly.com/blog/technology/experts-exchange.html]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="0" width="366">
<tbody>
<tr>
<td style="height: 20px; padding: 0px;"><img style="padding:0px;" src="http://www.matthewstevenkelly.com/images/php-cert/masterRankTop.gif" border="0" alt="" /></td>
<td style="padding: 0px; height: 20px; background-image: url(http://www.matthewstevenkelly.com/images/php-cert/masterTitleTop.gif); font: bold 16px Arial; color: #666; text-decoration: none;" colspan="2">Matthew Steven Kelly</td>
</tr>
<tr>
<td valign="top"><img style="padding:0px;" src="http://www.matthewstevenkelly.com/images/php-cert/masterRankMiddle.gif" border="0" alt="" /></td>
<td valign="top"><img style="padding:0px;" src="http://www.matthewstevenkelly.com/images/php-cert/masterTitleMiddle.gif" border="0" alt="Master" /></td>
<td valign="top"><img style="padding:0px;" src="http://www.matthewstevenkelly.com/images/php-cert/masterPointsMiddle.gif" border="0" alt="50,000 Expert Points" /></td>
</tr>
<tr>
<td valign="top"><img style="padding:0px;" src="http://www.matthewstevenkelly.com/images/php-cert/masterRankBottom.gif" border="0" alt="" /></td>
<td colspan="2" valign="top"><img style="padding:0px;" src="http://www.matthewstevenkelly.com/images/php-cert/l_103.gif" border="0" alt="PHP Scripting Language" /></td>
</tr>
</tbody>
</table>
<p>Click here: <a href="http://www.experts-exchange.com/M_4475722.html">View Profile</a> to view my Experts Exchange profile.</p>
<p>Click here: <a href="http://www.matthewstevenkelly.com/pdf/php-certified.pdf">View Certificate</a> to view my PHP certificate.</p>
<p>And more information about Experts-Exchange and me:<br />
<a href="http://www.matthewstevenkelly.com/blog/technology/experts-exchange.html">http://www.matthewstevenkelly.com/blog/technology/experts-exchange.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthewstevenkelly.com/blog/career/php-master.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpBB forum</title>
		<link>http://www.matthewstevenkelly.com/blog/technology/phpbb-forum.html</link>
		<comments>http://www.matthewstevenkelly.com/blog/technology/phpbb-forum.html#comments</comments>
		<pubDate>Tue, 28 Nov 2006 00:34:51 +0000</pubDate>
		<dc:creator>Matthew Steven Kelly</dc:creator>
				<category><![CDATA[Technology and Me]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">https://www.matthewstevenkelly.com/blog/?p=86</guid>
		<description><![CDATA[A while ago I evaluated many PHP based discussion forums for integration into a project a work. phpBB (PHP Bulletin Board) was found to be the best of the bunch. We were able to completely skin it into our application &#8230; <a href="http://www.matthewstevenkelly.com/blog/technology/phpbb-forum.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A while ago I evaluated many PHP based discussion forums for integration into a project a work. <a href="http://www.phpbb.com">phpBB</a> (PHP Bulletin Board) was found to be the best of the bunch. We were able to completely skin it into our application so that it appeared to be a seamless integration between our application page and the discussion forum.</p>
<p>I set up a sample of phpBB (with the default theme) on my site as a demonstration:<br />
<a href="http://www.matthewstevenkelly.com/forum/">https://www.matthewstevenkelly.com/forum/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matthewstevenkelly.com/blog/technology/phpbb-forum.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Email</title>
		<link>http://www.matthewstevenkelly.com/blog/random/php-email.html</link>
		<comments>http://www.matthewstevenkelly.com/blog/random/php-email.html#comments</comments>
		<pubDate>Wed, 05 Apr 2006 23:28:40 +0000</pubDate>
		<dc:creator>Matthew Steven Kelly</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">https://www.matthewstevenkelly.com/blog/?p=249</guid>
		<description><![CDATA[Are you going to be sending email in PHP? Don&#8217;t use the mail() function, unless your site&#8217;s email needs are very basic and you are running on a Linux/Unix machine. It is light on features and not built into the &#8230; <a href="http://www.matthewstevenkelly.com/blog/random/php-email.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Are you going to be sending email in PHP? Don&#8217;t use the mail() function, unless your site&#8217;s email needs are very basic and you are running on a Linux/Unix machine. It is light on features and not built into the Windows version.</p>
<p>The best approach is to use a 3rd party mail program. In the past I have used PHPMailer as it is has all features I have needed. This script is the fix to many SMTP email problems in PHP!</p>
<p><a href="http://sourceforge.net/projects/phpmailer">http://sourceforge.net/projects/phpmailer</a></p>
<p>Below is the PHP code to use it. Place <i>class.phpmailer.php</i> into your php includes directory.</p>
<p>Replace text in &lt;&lt; &gt;&gt; with your server information:<br />
<a href="http://www.emailaddressmanager.com/tips/mail-settings.html">http://www.emailaddressmanager.com/tips/mail-settings.html</a></p>
<div style="background-color:#CCCCCC;width:100%;overflow:auto;">
<p>&lt;?php</p>
<p>require(&quot;class.phpmailer.php&quot;);</p>
<p>$mail = new PHPMailer();</p>
<p>$mail-&gt;IsSMTP(); // send via SMTP<br />
$mail-&gt;Host     = &quot;&lt;&lt;smtpserver&gt;&gt;:&lt;&lt;stmpport&gt;&gt;&quot;; // SMTP servers<br />
$mail-&gt;SMTPAuth = true; // turn on SMTP authentication<br />
$mail-&gt;Username = &quot;&lt;&lt;uname&gt;&gt;&quot;; // SMTP username<br />
$mail-&gt;Password = &quot;&lt;&lt;pword&gt;&gt;&quot;; // SMTP password<br />
$mail-&gt;From = &quot;&lt;&lt;email address from&gt;&gt;&quot;;<br />
$mail-&gt;FromName = &quot;&lt;&lt;email name from&gt;&gt;&quot;;<br />
$mail-&gt;AddAddress(&quot;&lt;&lt;email address to&gt;&gt;&quot;);<br />
$mail-&gt;AddReplyTo(&quot;&lt;&lt;email address from&gt;&gt;&quot;,&quot;&lt;&lt;email name from&gt;&gt;&quot;);<br />
$mail-&gt;WordWrap = 50; // set word wrap<br />
$mail-&gt;IsHTML(true); // send as HTML<br />
$mail-&gt;Subject  =  &quot;Subject&quot;;<br />
$mail-&gt;Body     =  &quot;Body text&quot;;<br />
$mail-&gt;AltBody  =  $mail-&gt;Body;</p>
<p>$mail-&gt;Send();</p>
<p>?&gt;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.matthewstevenkelly.com/blog/random/php-email.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

