
<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>PHP, Web and IT stuff &#187; PHP</title>
	<atom:link href="http://www.webdigi.co.uk/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdigi.co.uk/blog</link>
	<description>Little words of wisdom</description>
	<lastBuildDate>Sat, 04 Sep 2010 22:35:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Run PHP on the Google App Engine</title>
		<link>http://www.webdigi.co.uk/blog/2009/run-php-on-the-google-app-engine/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/run-php-on-the-google-app-engine/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 22:25:26 +0000</pubDate>
		<dc:creator>php-manual</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[quercus]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=313</guid>
		<description><![CDATA[
Google launched their Google App Engine (GAE) a year ago. The free hosting in App Engine is allocated 500 MB of persistent storage and enough CPU and bandwidth for about 5 million page views a month. Also, if you really want more you can see pricing plans.
GAE will support Java going forward. Unfortunately PHP support on the App [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-659" title="Google Appengine Running PHP" src="http://www.webdigi.co.uk/blog/wp-content/uploads/2009/04/appengine-java-php.jpg" alt="Google Appengine Running PHP" width="640" height="417" /></p>
<p>Google launched their <a rel="nofollow" href="http://code.google.com/appengine/">Google App Engine</a> (GAE) a year ago. The <strong>free</strong> hosting in App Engine is allocated <strong>500 MB</strong> of persistent storage and enough CPU and bandwidth for about <strong>5 million page views</strong> a month. Also, if you really want more you can see <a rel="nofollow" href="http://code.google.com/appengine/kb/billing.html#freequota">pricing plans</a>.</p>
<p>GAE will support <a rel="nofollow" href="http://googleappengine.blogspot.com/2009/04/seriously-this-time-new-language-on-app.html">Java going forward</a>. Unfortunately <a rel="nofollow" href="http://code.google.com/p/googleappengine/issues/list">PHP support on the App Engine</a> is still left as the top item in the wishlist. So until Google announces their official PHP support we have a workaround to run PHP using <a rel="nofollow" href="http://www.caucho.com/resin-3.0/quercus/">Quercus</a>. Quercus is basically a 100% Java implementation of the PHP language (requires JDK 1.5).  Since the App Engine now supports Java this means we can use Quercus to run PHP scripts on the App Engine.</p>
<p><span style="text-decoration: underline;">So all you need to use the GAE and run PHP</span><br />
1) Register a <a rel="nofollow" href="http://appengine.google.com/">free account</a>.<br />
2) <a href="http://www.webdigi.co.uk/fun/php-appengine/phpwithjava.zip">Download this file</a> to your computer.<br />
3) Edit application XML tag in the file war\WEB-INF\appengine-web.xml to the name of the application you have registered.<br />
4) Finally <a href="http://code.google.com/appengine/docs/java/gettingstarted/uploading.html">upload your application</a>. I downloaded Google App Engine <strong>SDK for Java</strong> and use the following command in windows.<br />
appcfg.cmd update C:\projects\phpwithjava\war</p>
<p>To see this in action just visit:<br />
<a href="http://phpwithjava.appspot.com/webdigi.php">http://phpwithjava.appspot.com/webdigi.php</a> and <a href="http://phpwithjava.appspot.com/info.php">http://phpwithjava.appspot.com/info.php</a></p>
<p>NOTE: phpwithjava is my app name with GAE. Image by Aral Balkan.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/run-php-on-the-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>78</slash:comments>
		</item>
		<item>
		<title>What is new in PHP 5.3 for PHP amateurs?</title>
		<link>http://www.webdigi.co.uk/blog/2009/what-is-new-in-php-53-for-php-amateurs/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/what-is-new-in-php-53-for-php-amateurs/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 19:33:59 +0000</pubDate>
		<dc:creator>iphp</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[lambdas]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[phar]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=256</guid>
		<description><![CDATA[In a recent PHP conference in London some great speakers spoke about new features in PHP to be released in PHP 5.3. PHP 5.3 contains functionality that was scheduled for PHP 6, which takes PHP 5.3 from being a minor release to a significant and huge release. A release that no PHP developer should ignore. [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent <a rel="nofollow" href="http://www.phpconference.co.uk/">PHP conference in London</a> some great speakers spoke about new features in PHP to be released in PHP 5.3. PHP 5.3 contains functionality that was scheduled for PHP 6, which takes PHP 5.3 from being a minor release to a significant and huge release. A release that no PHP developer should ignore. Most of these features are pretty complicated additions for novice PHP programmers. I have listed some features and some ways to use them.</p>
<p><strong>1) Namespaces for classes and functions</strong><br />
This feature will help us shorten the class names and function names. To appreciate this feature, we need to go back to the days before there was Object Oriented Programming in PHP. Imagine all the function names with name save(). How would you differentiate if the call save() was to save a blogs or save comments? The solution was to use blog_save() or comment_save() before the introduction of classes in which we could write the save() function within the Blog class or the Comment class. Using classes is obviously a much more elegant solution.</p>
<p>We now have the same situation with the large number of classes and functions. Using namespaces, we could simply separate the two functions above in the code below:</p>
<pre name="code" class="php">

&lt;?php
namespace Blog;
function save()
{
echo &quot;Now saving the blog!&quot;;
}

namespace Comment;
function save()
{
echo &quot;Now saving the comment!&quot;;
}

// To invoke the functions
Blog\save();    // This prints - Now saving the blog!
Comment\save(); // This prints - Now saving the comment!
?&gt;
</pre>
<p>EDIT: A final decision was made on October 2008.  Developers will have to use \ backslash operator to dereference namespaces.</p>
<p><strong>2) MySQL Native Driver</strong><br />
PHP 5.3 has a native driver specific to PHP, optimised for the ZEND engine. It is an alternative to connect to MySQL server versions newer than 4.1. Being a native driver we should be able to get much faster execution times. The native driver will also be licensed under the PHP license. If you are like most users, you are currently using libmysql (A MySQL database client library) you will be able to easily switch over to mysqlnd <strong>without</strong> making any changes to your existing PHP Scripts!<br />
<strong><br />
3) phar &#8211; PHp ARchive</strong><br />
This is a cool new feature.  Think of it like an archive, like a .zip file or a .tar file. Besides just being able to group all the files into one simple file, we will be able to deliver and run an entire PHP application from a single file!</p>
<p>We will also be able to use phar archives within PHP, so the following will work in PHP 5.3 and above</p>
<pre name="code" class="php">

&lt;?php
include &quot;singlefilelibrary.phar&quot;
?&gt;
</pre>
<p>Obviously, there will be a performance hit but the possibilities are endless, imagine being able to upload phpMyAdmin to the server as a single phar file instead of hundreds of small files.</p>
<p><strong>4) Closures &amp; Lambdas</strong><br />
This gets into the list because this is something most web developers would have been familiar with while working on Javascript. A lambda can be declared anywhere and they can be assigned to a variable. A closure on the other hand are lambda funcions but have access to the variables where they were declared. This is something called lexical scoping. To see this in action take a look at this example.</p>
<pre name="code" class="php">

&lt;?php
$hellolambda = function () {
echo &quot;Hello world via Lambda&quot;;

}
$hellolambda(); // Outputs Hello world via Lambda
?&gt;
</pre>
<p><strong>5) All of the rest!</strong><br />
There are a lot of other things in PHP 5.3 which I thought are nice, I have just described all of them very succinctly.<br />
<em><strong>Functors:</strong> </em>This allows an object to be invoked as a function.<br />
<strong><em>Traits:</em> </strong>This is a new unit of reuse, traits can be incomplete, provides reusability, modularity and structure. In short it is copy-paste glorified!<br />
<strong><em>Magic functions: </em> </strong>We have a couple of new magic functions for classes (interceptors) __callstatic() and invoke()<br />
<strong><em>Ternary operator:</em> </strong>You can now display the a value that exists $value1 or $value2 using this simple statement<em> </em>echo $value1?:$value2;<br />
There are many more things added like Late Static Binding, Variable Static Calls, Changes to PHP Error Levels, new PHP functions, improvements to help with OpenID, Command line and many more.</p>
<p><strong>Final Thought</strong><br />
Well, this gives us much more to play with. It is definitely a lot to include into PHP 5.3 and I would have expected so many changes to go into PHP 6. I sometimes wonder if there will be anything new left to add into PHP 6 given the fact that so much has been released already.  If you are interested in PHP 5.3, do give it a try <a title="Link to PHP 5.3" rel="nofollow" href="http://qa.php.net/">here</a>, it is in beta at the time of the writing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/what-is-new-in-php-53-for-php-amateurs/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>How to detect if your webserver is hacked and get alerted</title>
		<link>http://www.webdigi.co.uk/blog/2009/how-to-detect-if-your-webserver-is-hacked-and-get-alerted/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/how-to-detect-if-your-webserver-is-hacked-and-get-alerted/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 15:36:53 +0000</pubDate>
		<dc:creator>php-manual</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=31</guid>
		<description><![CDATA[We all do our best to write excellent code and also keep our installations of popular open source tools like Wordpress, Joomla, Oscommerce, Drupal, phpmyadmin and all its plugins always updated to prevent any attack or hackers using known exploits on them. This article is not aimed at going through all those methods to help you secure [...]]]></description>
			<content:encoded><![CDATA[<p>We all do our best to write excellent code and also keep our installations of popular open source tools like Wordpress, Joomla, Oscommerce, Drupal, phpmyadmin and all its plugins always updated to prevent any attack or hackers using known exploits on them. This article is not aimed at going through all those methods to help you secure your website BUT focuses on how to send you an alert once your website is hacked and running &#8220;hidden&#8221; code that you didnt write.</p>
<p><span id="more-31"></span></p>
<p><span style="text-decoration: underline;">The problem</span></p>
<p>Once hackers get into your website either by exploiting known vulnerabilities in any of the installed programs OR by getting FTP access to your server, the first thing they usually do is to plant backdoor scripts to log them in again at a later date. They need some executable script on the server to gain access to MySQL passwords, installation passwords or even edit settings in your wordpress or other installations.  We have also seen situations where the site was left largely unchanged except for malicious javascript code added to the bottom of the index.php or index.html files.</p>
<p>So in short the bad guys have taken over your server and running anything from a backdoor script or launching phishing attacks or sending tons of spam emails. You will not know that your server is hacked until you get blacklisted on spamhaus or your customers get redirected to some random site or worser still when you are contacted by ebay/paypal/some bank saying that your website is phisihing their customers. <strong>The problem is that we dont even have an idea that our site is hacked until it is too late or too embrassing.</strong></p>
<p><span style="text-decoration: underline;">Simple Solution &#8211; Website Change Detection System</span></p>
<p>We need a script on the server that detects any changes or to any executable file on the server or any new file on the server from HTML, JS, to PHP, ASP, Perl, Python files etc.  If we generate a <strong>hash </strong>value of all our files and then compare them periodically, then we will be able to detect when our codebase has changed on the server.</p>
<p>These are the steps that our change detection system performs (It takes about 500ms to execute on a typical server):</p>
<ol>
<li>Load configuration file (contains password, exclude list)</li>
<li>Check password from request before starting (recommended)</li>
<li>Recursively run through every file and sub folder on the server within the current directory of the script.</li>
<li>Generate a hash for each file and arrive at the master hash.</li>
<li>Compare master hash with hash the user has and alert if different!</li>
</ol>
<p>Notes:</p>
<ul>
<li>This script at this simple level is almost 100% fool proof in detecting changes to the codebaes give that the hacker or bots don&#8217;t know of websiteCDS presence.</li>
<li>At this stage the script cannot detect SQL injection attacks and changes to code that are saved to the database.</li>
<li>The users hash is not stored on the server at any time, the comparison with master hash can be done at cron script level or using siteup as discussed below.</li>
</ul>
<p>We have the following code written in PHP but you can do the same with any other scripting language to perform similar checks. We have started the project under google code and is available here: <a title="websiteCDS version in PHP" href="http://websitecds.googlecode.com/files/websitecds%20version1.zip" target="_blank">PHP code for WebsiteCDS</a><br />
See the readme file in the download for help with setup.</p>
<p><span style="text-decoration: underline;">Different ways to automate the alert system</span></p>
<p>Method 1: Using our trusted cron job<br />
A cron job can be setup to run the website CDS, compare the results with the last known valid hash and send out an email alert.</p>
<p>Method 2: With Siteup<br />
Siteup is a free tool for windows systems that can be set to periodically check if your website is reachable. This is recommended for those of us who don&#8217;t want to setup a cron job. It can be downloaded here <a rel="nofollow" href="http://www.xequte.com/other/index.html#siteup"  target="_blank">http://www.xequte.com/other/index.html#siteup</a> We can use this to frequently call our change detection system and then use the siteup word search to check if the hash value is the same as what we have from our last codebase update. ( <a title="websiteCDS setup in SiteUP" href="http://blogcdn.webdigi.co.uk.s3.amazonaws.com/blog/wp-content/uploads/2009/screenshot/SiteUPeditSite.jpg" target="_blank">See screenshot</a> )</p>
<p>NOTE: The project &amp; code included is the first version of the change detection system and kindly submit your ideas and comments here or an issue or feature request in <a title="WebsiteCDS issue tracking" href="http://code.google.com/p/websitecds/issues/list" target="_blank">google code project for websitecds</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/how-to-detect-if-your-webserver-is-hacked-and-get-alerted/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>How to check if an email address exists without sending an email?</title>
		<link>http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 14:24:04 +0000</pubDate>
		<dc:creator>php-manual</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=19</guid>
		<description><![CDATA[We have all been doing email address validation for a very long time to make sure that the email is correctly formatted. This is to avoid users entering wrongly formatted email address but still they can accidentally give us a wrong email address.
Example of a correctly formatted email address but still wrong:
mailbox.does.not.exist@reddit.com [VALID email fromat [...]]]></description>
			<content:encoded><![CDATA[<p>We have all been doing email address validation for a very long time to make sure that the email is correctly formatted. This is to avoid users entering wrongly formatted email address but still they can accidentally give us a wrong email address.</p>
<p style="text-align: left;">Example of a correctly formatted email address but still wrong:</p>
<p style="text-align: center;"><strong>mailbox.does.not.exist@reddit.com</strong> [VALID email fromat but still not correct]</p>
<p style="text-align: left;">Above case specifically happens when you take important customer email on phone and you type in the wrong email. So is there a QUICK solution to really check the email without sending a test message to the user? Yes.<br />
<span id="more-19"></span></p>
<p><span style="text-decoration: underline;">The solution</span></p>
<p style="text-align: left;">A quick &amp; simple check below can be implemented in most programming language including PHP, Python etc. It relies on using the same SMTP which is used to send emails.</p>
<p>To check if user entered email <strong>mailbox.does.not.exist</strong><strong>@reddit.com</strong> really exists go through the following in command prompt.</p>
<p><strong>First </strong>- Find mail exchanger of reddit.com</p>
<p style="padding-left: 30px;">COMMAND:<br />
nslookup &#8211; q=mx reddit.com<br />
RESPONSE:<br />
reddit.com      MX preference = 10, mail exchanger = mail.reddit.com<br />
mail.reddit.com internet address = 208.96.53.70</p>
<p style="text-align: left;"><strong>Second </strong>- Connect to mail server mail.reddit.com</p>
<p style="text-align: left; padding-left: 30px;">COMMAND:<br />
telnet mail.reddit.com 25<br />
RESPONSE:<br />
220 mail.reddit.com ESMTP Postfix NO UCE NO UEMA  C=US L=CA Unsolicated electronic mail advertisements strictly prohibited, subject to fine under CA law CBPC 17538.45.  This electronic mail service provider&#8217;s equipment is located in the State of California.  See http://www.reddit.com/static/inbound-email-policy.html for more information.</p>
<p style="text-align: left; padding-left: 30px;">COMMAND:<br />
helo hi<br />
RESPONSE:<br />
250 mail.reddit.com</p>
<p style="padding-left: 30px;">COMMAND:<br />
mail from: &lt;youremail@gmail.com&gt;<br />
RESPONSE:<br />
250 2.1.0 Ok</p>
<p style="padding-left: 30px;">COMMAND:<br />
rcpt to: &lt;mailbox.does.not.exist@reddit.com&gt;<br />
RESPONSE:<br />
<strong>550 </strong>5.1.1 &lt;mailbox.does.not.exist@reddit.com&gt;: Recipient address rejected: User unknown in local recipient table</p>
<p style="padding-left: 30px;">COMMAND:<br />
quit<br />
RESPONSE:<br />
221 2.0.0 Bye</p>
<p>NOTES:</p>
<p>1) the <strong>550 </strong>response indicates that the email address is not valid and you have caught a valid but wrong email address. This code can be on the server and called on AJAX when user tabs out of the email field.  The entire check will take less than 2 seconds to run and you can make sure that the email is correct.<br />
2) If email was present the server will respond with a 250 instead of 550<br />
3) There are certain servers with a CATCH ALL email and this means all email address are accepted as valid on their servers (RARE but some servers do have this setting).<br />
4) Please do not use this method to continuously to check for availability of <span>gmail</span> / yahoo / <span>msn</span> accounts etc as this may cause your IP to be added to a blacklist.<br />
5) This is to supplement the standard email address javascript validation.</p>
<p><span style="text-decoration: underline;">Telnet screenshot in windows &#8211; Check email using SMTP commands</span></p>

<a href='http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/checkemailtelnet/' title='Telnet on windows to check mail server using SMTP commands'><img width="150" height="150" src="http://www.webdigi.co.uk/blog/wp-content/uploads/2009/01/checkemailtelnet-150x150.png" class="attachment-thumbnail" alt="" title="Telnet on windows to check mail server using SMTP commands" /></a>

<p><strong><span style="text-decoration: underline;">UPDATE: PHP code added on 26th January 08</span></strong></p>
<p>1) <a rel="attachment wp-att-79" href="http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/smtpvalidateclassphp/">SMTP check code in PHP &#8211; DOWNLOAD</a></p>
<p>2) <a href="http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/checkemailexamplephp/">Usage example - DOWNLOAD</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>PHP session fixation attacks</title>
		<link>http://www.webdigi.co.uk/blog/2009/php-session-fixation-attacks/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/php-session-fixation-attacks/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 12:45:05 +0000</pubDate>
		<dc:creator>php-manual</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=6</guid>
		<description><![CDATA[Session fixation attacks attempt to exploit the vulnerability of a system which allows one person to fixate (set) another person's session identifier (SID). Most session fixation attacks are web based, and most rely on session identifiers being accepted from URLs (query string) or POST data.]]></description>
			<content:encoded><![CDATA[<p>Session fixation attacks attempt to exploit the vulnerability of a system which allows one person to fixate (set) another person&#8217;s session identifier (SID). Most session fixation attacks are web based, and most rely on session identifiers being accepted from URLs (query string) or POST data.</p>
<p><span style="text-decoration: underline;">Example of such an attack</span>: Lets take an example of a banking website which provides login to access banking features. (this can be any site which allows users to login).<br />
EG: http://www.poorbanking.com</p>
<p>1) Hacker<br />
Creates a very a link and sends visitors to the site as http://www.poorbanking.com/index.php?PHPSESSID=1234<br />
Lets assume PHPSESSID is the name of the cookie / variable used to store session information. It is very easy for anyone to find this by just visiting the site once.</p>
<p>2) Hacker sends link to the target user.<br />
http://www.poorbanking.com/index.php?PHPSESSID=1234 by email or placed in a blog etc.</p>
<p>3) Victim<br />
Sees the link and clicks on it. The site looks genuine and the victim logs in to the site. At this stage the PHPSESSID is set to PHPSESSID=1234 and user is logged in.</p>
<p>4) The happy hacker<br />
Hacker can keep checking if they can login by simply going to http://www.poorbanking.com/showmeaccount.php?PHPSESSID=1234<br />
where showmeaccount.php is the page after login. They can see that once the user has logged in they can easily get access to the page.</p>
<p><span style="text-decoration: underline;">Work around to this problem</span></p>
<p>Just prior to setting such a session variable, a call to session_regenerate_id() can help to protect against a session fixation attack.</p>
<p>See more information at http://en.wikipedia.org/wiki/Session_fixation</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/php-session-fixation-attacks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
