<?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>Harry Bailey &#187; Methods</title>
	<atom:link href="http://harrybailey.com/category/php/methods/feed/" rel="self" type="application/rss+xml" />
	<link>http://harrybailey.com</link>
	<description>just a little bit geeky</description>
	<lastBuildDate>Tue, 24 Aug 2010 12:15:01 +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>Using PHP_SELF Safely and submitting forms to the same page</title>
		<link>http://harrybailey.com/2009/12/using-php_self-safely-and-submitting-forms-to-the-same-page/</link>
		<comments>http://harrybailey.com/2009/12/using-php_self-safely-and-submitting-forms-to-the-same-page/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 00:54:55 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[The Web]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=374</guid>
		<description><![CDATA[I&#8217;ve lost count of the number of times i&#8217;ve seen this bit of HTML / PHP:

&#60;form method=&#34;post&#34; action=&#34;&#60;?php print $_SERVER&#91;'PHP_SELF&#34;]; ?&#62;&#34;&#62;

Looks pretty harmless doesn&#8217;t it, but it is a pretty dangerous shortcut to use. Imagin I get a user to visit the page the form is on by following this link, maybe hiding it in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve lost count of the number of times i&#8217;ve seen this bit of HTML / PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">print</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="">'PHP_SELF&quot;]; ?&gt;&quot;&gt;</span></pre></div></div>

<p>Looks pretty harmless doesn&#8217;t it, but it is a pretty dangerous shortcut to use. Imagin I get a user to visit the page the form is on by following this link, maybe hiding it in a short url:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">http<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//example.com/formpage.php?&quot;&gt;&lt;script&gt;alert(document.cookie);&lt;/script&gt;</span></pre></div></div>

<p>where I&#8217;ve added some html into the url which contains a script tag.</p>
<p>I could use this method to grab all your cookies and log in as you, or send ajax requests back to the site on your behalf. All very frightening. The quick solution is to turn html characters into their harmless entities using the php function htmlspecialchars. So the code would be</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">print</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;</pre></div></div>

<p>But wait! The best way to submit to the same page with a form is to use and empty action attribute. It&#8217;s valid and it works.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;</pre></div></div>

<p> Don&#8217;t believe me? Go tell Jesse. He also wrote about <a href="http://www.thefutureoftheweb.com/blog/use-empty-form-action-submit-to-current">empty action attributes</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2009/12/using-php_self-safely-and-submitting-forms-to-the-same-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pipe / Send Email to a PHP Script</title>
		<link>http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/</link>
		<comments>http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 16:52:31 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=211</guid>
		<description><![CDATA[Sending (or piping) emails to a php script would allows a whole world of fun. I had a spare 30 minutes the other night so I sat down, read a few blog posts and forums and set up emails to pipe to a php script.

The first step for me was to set up a new [...]]]></description>
			<content:encoded><![CDATA[<p>Sending (or piping) emails to a php script would allows a whole world of fun. I had a spare 30 minutes the other night so I sat down, read a few blog posts and forums and set up emails to pipe to a php script.</p>
<p><span id="more-211"></span></p>
<p>The first step for me was to set up a new subdomain in cPanel (a control panel my <a href="http://www.orchardhosting.com">affordable host</a> includes). This allows me to only send (or pipe) specific email to the script and means I can run a catch-all wildcard forwarder on all emails to that subdomain.</p>
<p>In cPanel I created the subdomain in the normal way. Then I navigated to &#8216;Email Management Tools -> Default E-mail account&#8217;, chose the new subdomain from the dropdown list, clicked &#8216;Advanced Options&#8217; and selected the radio button for &#8216;Pipe to a Program&#8217;.<br />
In the textbox I added the name of the file that would be used to process the emails. In my case <strong>catcher.php</strong> which I had already created in the <strong>root of my site</strong> (not in public_html).</p>
<p>Cpanel is clever enough to add your sites root folder to the name you specify, so will be altered to something like <strong>&#8216;/home/youraccount/catcher.php&#8217;</strong></p>
<p>The next step was to prepare catcher.php to deal with the emails being piped to it. Open the file and change the contents to something along the lines of:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">#!/usr/bin/php -q
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// read from stdin</span>
<span style="color: #000088;">$fd</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php://stdin&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span>;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fd</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$email</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fd</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fd</span><span style="color: #009900;">&#41;</span>;
&nbsp;
&nbsp;
<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="">'you@yoursite.com'</span><span style="color: #339933;">,</span><span style="">'From my email pipe!'</span><span style="color: #339933;">,</span><span style="">'&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">.</span> <span style="">'&quot;'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The first line of the script is <strong>very</strong> important and will <strong>tell the email pipe to use php</strong>. If your php install is not found at the location show, change it so it is. The -q part tells the pipe not to bounce an email back to the sender. A good thing as we can do that manually in the script.</p>
<p>Make sure you change the permissions of the script to be executable by the email pipe. chmod 755 should do fine.</p>
<p>The script itself will grab the emails contents using fopen on <strong>php://stdin</strong> which is where the email is temporarily stored. You can then manipulate it using such functions as preg_match to grab the parts you want.</p>
<p>The beauty of this method is it will catch all email to that subdomain, so you can create addresses which include the users id and a hash which can be temporary:</p>
<p>1294710241-w98fqwfhi3ho2ih3f@emailin.mysite.com</p>
<p>which you can use to ensure you only act on emails from the intended user.</p>
<p>Note: If you are using -q but still getting bounces, be sure the script is not outputting any data. That means once you have tested it, no print, no echo, no var_dump. When you run the script directly you should see a blank screen and the source code should be empty.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>PHP coding standards I agree with</title>
		<link>http://harrybailey.com/2008/11/php-coding-standards-i-agree-with/</link>
		<comments>http://harrybailey.com/2008/11/php-coding-standards-i-agree-with/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 23:02:09 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Methods]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=12</guid>
		<description><![CDATA[In all my time coding php I have read a lot of php coding standards.
Finally I have found one that I almost agree with completely. My only wobble is regarding the suggestion not to use getters and setters in classes.
PHP Coding standards
The PHP Coding Standard is with permission based on Todd Hoff&#8217;s C++ Coding Standard.
Rewritten [...]]]></description>
			<content:encoded><![CDATA[<p>In all my time coding php I have read <strong>a lot</strong> of php coding standards.</p>
<p>Finally I have found one that I <em>almost</em> agree with completely. My only wobble is regarding the suggestion not to use getters and setters in classes.</p>
<p><a href="http://www.dagbladet.no/development/phpcodingstandard/">PHP Coding standards</a></p>
<p>The PHP Coding Standard is with permission <strong>based on</strong> <a href="mailto:tmh@possibility.com">Todd Hoff</a>&#8217;s <a href="http://www.possibility.com/Cpp/CppCodingStandard.html">C++ Coding Standard</a>.<br />
Rewritten for PHP by <script>writemail('russlndr', 'online.no');</script><a href="mailto:russlndr@online.no"> Fredrik Kristiansen</a> / <a href="http://db.no/db">DB Medialab</a>, Oslo 2000-2003.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2008/11/php-coding-standards-i-agree-with/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
