<?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>3cc Internet - Southampton, UK</title>
	<atom:link href="http://www.3cc.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3cc.org</link>
	<description>Making web design work.</description>
	<lastBuildDate>Wed, 25 Aug 2010 15:57:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Google Maps, Geocoding and PHP to find the distance between UK Postcodes</title>
		<link>http://www.3cc.org/2010/08/using-google-maps-geocoding-and-php-to-find-the-distance-between-uk-postcodes/</link>
		<comments>http://www.3cc.org/2010/08/using-google-maps-geocoding-and-php-to-find-the-distance-between-uk-postcodes/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:57:11 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postcodes]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=140</guid>
		<description><![CDATA[If you&#8217;re looking to make any kind of radius checker, delivery calculator etc, you will need to have some method of calculating this distance. Unfortunately for us in the UK, Royal Mail keep a tight grip on postcode data. As &#8230; <a href="http://www.3cc.org/2010/08/using-google-maps-geocoding-and-php-to-find-the-distance-between-uk-postcodes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking to make any kind of radius checker, delivery calculator etc, you will need to have some method of calculating this distance. Unfortunately for us in the UK, Royal Mail keep a tight grip on postcode data.</p>
<p>As a result, the best low-budget way of finding postcodes is by using the Google Maps api &#8211; which in itself isn&#8217;t 100% accurate (but good enough).</p>
<p>So we can use the following code:</p>
<pre class="brush:php">&lt;?php
// Specify Postcodes to Geocode
$postcode1 = 'BH151DA';
$postcode2 = 'BH213AP';

// Geocode Postcodes &amp; Get Co-ordinates 1st Postcode
$pc1 = 'http://maps.google.com/maps/geo?q='.$postcode1.',+UK&amp;output=csv&amp;sensor=false';
$data1 = @file_get_contents($pc1);
$result1 = explode(",", $data1);
$custlat1 = $result1[2];
$custlong1 = $result1[3];

// Geocode Postcodes &amp; Get Co-ordinates 2nd Postcode
$pc2 = 'http://maps.google.com/maps/geo?q='.$postcode2.',+UK&amp;output=csv&amp;sensor=false';
$data2 = @file_get_contents($pc2);
$result2 = explode(",", $data2);
$custlat2 = $result2[2];
$custlong2 = $result2[3];

// Work out the distance!
$pi80 = M_PI / 180;
$custlat1 *= $pi80;
$custlong1 *= $pi80;
$custlat2 *= $pi80;
$custlong2 *= $pi80;

$r = 6372.797; // mean radius of Earth in km
$dlat = $custlat2 - $custlat1;
$dlng = $custlong2 - $custlong1;
$a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));

// Distance in KM
$km = round($r * $c, 2);

// Distance in Miles
$miles = round($km * 0.621371192, 2);

echo 'The distance between '.$postcode1.' and '.$postcode2.' is '.$km.'Km ('.$miles.' miles).';

?&gt;
</pre>
<p>You could use $result1[0] and $result2[0] to check codes. If the value is anything other than 200 the postcode is invalid. Also note UK is also searched for to guarantee correct results!</p>
<p>The result is also rounded to make sure we only have 2 decimal places. Make sure your postcodes do not have any spaces in when they go to Google, if you&#8217;re collecting them from a form maybe use:</p>
<pre class="brush:php">function nowhitespace($data) {
return preg_replace('/\s/', '', $data);
}
$postcode1 = nowhitespace($postcode1);</pre>
<p>to remove all spaces before processing, and the following to check it&#8217;s ok after processing:</p>
<pre class="brush:php">if (($result1[0] != 200) || ($result2[0] != 200)) {
echo "&lt;p&gt;Invalid Postcode(s) Entered. Please try again.&lt;/p&gt;";
} else {</pre>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/using-google-maps-geocoding-and-php-to-find-the-distance-between-uk-postcodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vertical Align and Centering Images in Div tags</title>
		<link>http://www.3cc.org/2010/08/vertical-align-and-centering-images-in-div-tags/</link>
		<comments>http://www.3cc.org/2010/08/vertical-align-and-centering-images-in-div-tags/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:26:13 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=197</guid>
		<description><![CDATA[Just thought I&#8217;d share my preferred solution for vertical aligning an image within a Div. You can&#8217;t use &#60;p&#62; tags, text align, vertical align or even image align as this messes up the display? I had this problem with thumbnails &#8230; <a href="http://www.3cc.org/2010/08/vertical-align-and-centering-images-in-div-tags/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just thought I&#8217;d share my preferred solution for vertical aligning an image within a Div.</p>
<p>You can&#8217;t use &lt;p&gt; tags, text align, vertical align or even image align as this messes up the display? I had this problem with thumbnails or varying sizes which needed to be centered in a div of specific size.</p>
<p>Using the approach suggested <a href="http://www.w3.org/Style/Examples/007/center#vertical" target="_blank">here</a> and classing it as a table cell wasn&#8217;t great as it messed up the display&#8230;so I just set the image as a background which you can center &amp; put a transparent gif over it to link to. Not ideal but it works!</p>
<pre class="brush:html;">&lt;div style="background-image: url('thumbnail.gif');  background-repeat: no-repeat; background-position: center; width: 100px;  height: 100px"&gt;
&lt;a href="page.php"&gt;
&lt;img src="transparent  gif" width="100" height="100" /&gt;
&lt;/a&gt;
&lt;/div&gt;
</pre>
<p>You could also consider using absolute div tags but that also tends to interfere with surrounding design elements! Other solutions welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/vertical-align-and-centering-images-in-div-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resubmitting forms upon page refresh or reload in PHP</title>
		<link>http://www.3cc.org/2010/08/resubmitting-forms-upon-page-refresh-or-reload-in-php/</link>
		<comments>http://www.3cc.org/2010/08/resubmitting-forms-upon-page-refresh-or-reload-in-php/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 19:03:13 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=191</guid>
		<description><![CDATA[A common problem with forms is the annoying resubmit when the user reloads or refreshes a page. This can result in duplicate database records if not dealt with properly. There are a number of simple solutions to this problem, I&#8217;ll &#8230; <a href="http://www.3cc.org/2010/08/resubmitting-forms-upon-page-refresh-or-reload-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A common problem with forms is the annoying resubmit when the user reloads or refreshes a page. This can result in duplicate database records if not dealt with properly.</p>
<p>There are a number of simple solutions to this problem, I&#8217;ll go through a couple below.</p>
<p><strong>1. Use two files (one with the form on and one to process), and redirect back to the first page when the processing is done.</strong></p>
<p>Here&#8217;s some sample code for the form page (form.htm):</p>
<pre class="brush: php">&lt;form name="form1" method="post" action="process.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
</pre>
<p>and here&#8217;s some sample code for the processing page (process.php):</p>
<pre class="brush: php">&lt;?php
if (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
header("Location: form.htm");
}
?&gt;
</pre>
<p>This uses PHP header to redirect the user back to the form page when the form is processed, or if the user directly visits process.php without the form submission. Bear in mind this is only example code and so is not complete or secure.</p>
<p><strong>2. Use two files (one with the form on and to process and one when finished), redirecting to the second page when finished.</strong></p>
<p>Here is some sample code for the process/form page (form.php):</p>
<pre class="brush: php">&lt;?php
if (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
}
header("Location: thanks.htm");
?&gt;
&lt;form name="form1" method="post" action="form.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
</pre>
<p>and here&#8217;s the code for the final page (thanks.htm):</p>
<pre class="brush: php">&lt;p&gt;Thanks for filling out our form!&lt;/p&gt;
</pre>
<p>The user can still refresh the final page as much as they want as the processing was done elsewhere.</p>
<p><strong>3. Use one file, doing all the processing and then displaying a thank you message.</strong></p>
<p>This uses a $_GET to tell the script we&#8217;ve finished and display a message (form.php):</p>
<pre class="brush: php">&lt;?php
if ($_GET['success']) {
echo "Your text was saved successfully!";
} elseif (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
header("Location: form.php?success=1");
}
?&gt;
&lt;form name="form1" method="post" action="form.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
</pre>
<p>I suppose you could change the echo to a die if you didn&#8217;t want to show the form, or add in a final else like this:</p>
<pre class="brush: php">&lt;?php
if ($_GET['success']) {
echo "Your text was saved successfully!";
} elseif (isset($_POST['submit'])) {
$text = $_POST['text'];
$query = mysql_query("Insert into our database etc");
header("Location: form.php?success=1");
} else {
?&gt;
&lt;form name="form1" method="post" action="form.php"&gt;
&lt;input type="text" name="text" id="text"&gt;
&lt;input type="submit" name="submit" id="submit" value="Submit"&gt;
&lt;/form&gt;
&lt;?php } ?&gt;
</pre>
<p>so that the form would not be displayed when the Success text was.</p>
<p><strong>4. Involve sessions<br />
</strong></p>
<p>You could also involve sessions in your form by storing the POST variables in a session before processing, eg:</p>
<pre class="brush: php">$_SESSION['postdata'] = $_POST;
</pre>
<p>and clearing the session once the processing had been done, eg:</p>
<pre class="brush: php">unset($_SESSION['postdata'])
</pre>
<p>You could also enter a timestamp with each posted form and store this in a database, checking before processing for identical timestamps, it depends on the nature of your application and your personal preference.</p>
<p>Any comments/improvements welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/resubmitting-forms-upon-page-refresh-or-reload-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mediatemple Grid Server (gs) MySQL and Support Problems</title>
		<link>http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/</link>
		<comments>http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 11:28:01 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[mediatemple]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.3cc.org/?p=145</guid>
		<description><![CDATA[Let me be honest, I really REALLY want to like Mediatemple. Their website is extremely well designed, there&#8217;s loads of support information in their customer area, their GPU system gives you detailed information on high-resource scripts and files on your &#8230; <a href="http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Let me be honest, I really REALLY want to like Mediatemple. Their website is extremely well designed, there&#8217;s loads of support information in their customer area, their GPU system gives you detailed information on high-resource scripts and files on your server and their file system has excellent uptime and good speeds.</p>
<div id="attachment_173" class="wp-caption aligncenter" style="width: 610px"><a rel="attachment wp-att-173" href="http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/gs-control-panel/"><img class="size-large wp-image-173" title="Mediatemple GS Control Panel" src="http://www.3cc.org/wp-content/uploads/2010/08/gs-control-panel-600x400.png" alt="" width="600" height="400" /></a><p class="wp-caption-text">Mediatemple GS Control Panel</p></div>
<p>However, as I write this one of our personal projects which we put on it&#8217;s own Mediatemple server is displaying a MySQL connection error &#8211; again. Over the last week it&#8217;s been a constant on/off battle made many times worse by the very slow Mediatemple support.</p>
<div id="attachment_170" class="wp-caption aligncenter" style="width: 610px"><a rel="attachment wp-att-170" href="http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/gs-support-20h/"><img class="size-large wp-image-170" title="Mediatemple Sport a Speedy 20Hr Response Time" src="http://www.3cc.org/wp-content/uploads/2010/08/gs-support-20h-600x183.png" alt="" width="600" height="183" /></a><p class="wp-caption-text">Mediatemple Sport a Speedy 20Hr Response Time</p></div>
<p>It was acceptable to begin with, 5 hours for the first reply, 13 hours for the second that informed me there was a bigger issue (mediatemple always seem to have MySQL issues), 7 hours later they informed me the issue had been fixed.</p>
<p>25 hours later (yes, TWENTY FIVE), after I had replied saying there was still a problem, they told me it was all running ok&#8230;which it was THEN but it had been too slow to work for hours before they replied.</p>
<p>I should probably point out that all of this was mid-week so the only reason I can see for the slow responses is that everyone was busy working on the problem?</p>
<div id="attachment_175" class="wp-caption aligncenter" style="width: 610px"><a rel="attachment wp-att-175" href="http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/gs-support-home/"><img class="size-large wp-image-175" title="Mediatemple Support Home" src="http://www.3cc.org/wp-content/uploads/2010/08/gs-support-home-600x274.png" alt="" width="600" height="274" /></a><p class="wp-caption-text">Mediatemple Support Home</p></div>
<p>In the past I have had timely replies to my tickets (2 hour average) which is not as good as some (VPSLatch and PowerVPS being the best I&#8217;ve seen) but decent. In fact the response time is estimated at 4 hours 28 mins in the control panel right now. I have had only one instance of downtime for my files but unfortunately there are a couple of other shortcomings of their system including overly complicated domain setup (for subdomains) and how they work with the system. Whereas cPanel (for example) has seperate stats and settings for each domain, Mediatemple&#8217;s control panel mixes them together so the Urchin stats show all sites as one.</p>
<p>This post isn&#8217;t completely one sided, as the amount of space &amp; bandwidth you&#8217;re given is very generous; along with the actual computing &#8216;budget&#8217; they provide you with being pretty high (with their GPU system). Their website is beautifully designed and works pretty well but is let down by their MySQL system and slightly confusing control panel. You can of course fix the MySQL fault by purchasing a MySQL container at $20/mo, offering excellent response times; but this doubles the monthly cost of the service.</p>
<div id="attachment_174" class="wp-caption aligncenter" style="width: 574px"><a rel="attachment wp-att-174" href="http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/grid-mysql/"><img class="size-full wp-image-174" title="Extra MySQL Packages Are Available" src="http://www.3cc.org/wp-content/uploads/2010/08/grid-mysql.png" alt="" width="564" height="164" /></a><p class="wp-caption-text">Extra MySQL Packages Are Available</p></div>
<p>I&#8217;d also point out that the Mediatemple terms of use are similar to those found on VPS and dedicated servers, much more relaxed than shared servers. This is still very useful (combined with the high storage space and inclusive bandwidth) for image hosting sites etc that you can&#8217;t put elsewhere.</p>
<p>Hopefully this has given you a fairly round view of my time with mediatemple, everybody&#8217;s views differ and you&#8217;ll have a different experience depending on what cluster you&#8217;re on; but I&#8217;d suggest a VPS is a better way to go until Mediatemple sort out the annoying MySQL lag.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/mediatemple-grid-server-gs-mysql-and-support-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple PHP Login Systems and PHP Header &#8211; Break them with cURL</title>
		<link>http://www.3cc.org/2010/08/simple-php-login-systems-and-php-header-break-them-with-curl/</link>
		<comments>http://www.3cc.org/2010/08/simple-php-login-systems-and-php-header-break-them-with-curl/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 21:37:32 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://3cc.org.s92871.gridserver.com/?p=120</guid>
		<description><![CDATA[Most of the simple, free PHP scripts out there for user login systems have several large flaws in them, and I&#8217;ll admit that my earliest sites weren&#8217;t safe from what I&#8217;m going through today. cURL is a valuable tool for &#8230; <a href="http://www.3cc.org/2010/08/simple-php-login-systems-and-php-header-break-them-with-curl/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Most of the simple, free PHP scripts out there for user login systems have several large flaws in them, and I&#8217;ll admit that my earliest sites weren&#8217;t safe from what I&#8217;m going through today.</p>
<p>cURL is a valuable tool for any PHP developer and has extremely useful applications, one of which is logging into remote sites to post forms. This illustrates a flaw with many sites in that they user header redirects (as shown below) in their login systems to keep people away from pages they shouldn&#8217;t see, and log them in and out.</p>
<pre class="brush: php">if ($_SESSION['logged'] != 1) {
header("Location: login.php");
}</pre>
<p>That very simple bit of code checks to see whether a session has been found where logged = 1. If it doesn&#8217;t find one then it will redirect the user to login.php without showing them the page.</p>
<p>The problem here is that header location ONLY works when it&#8217;s the first thing on a page, otherwise you&#8217;ll see an error and then the rest of the page we shouldn&#8217;t be seeing &#8211; which is what happens with a cURL request. This means the header location redirect doesn&#8217;t work and anyone can grab your &#8220;protected&#8221; page easily and quickly without logging in.</p>
<p>To solve this quickly (without changing your basic login script at all) make sure you have failsafes! The most simple would be to add a die statement as below so that if your redirect fails, they won&#8217;t get to see your private page.</p>
<pre class="brush: php">if ($_SESSION['logged'] != 1) {
header("Location: login.php") or die("Please &lt;a href='login.php'&gt;login&lt;/a&gt; before accessing this page.");
}</pre>
<p>Very simple stuff, but there&#8217;s lots of sites without it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/08/simple-php-login-systems-and-php-header-break-them-with-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Register_Globals and Session Side Effects in PHP</title>
		<link>http://www.3cc.org/2010/07/register_globals-and-session-side-effects-in-php/</link>
		<comments>http://www.3cc.org/2010/07/register_globals-and-session-side-effects-in-php/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 16:11:14 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[register_globals]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.3cc.org/backyard/?p=108</guid>
		<description><![CDATA[Wrote a little login script (as part of a larger project) which uses PHP to store sessions with a user&#8217;s data in and got the following error. Warning: Unknown: Your script possibly relies on a session side-effect which existed until &#8230; <a href="http://www.3cc.org/2010/07/register_globals-and-session-side-effects-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Wrote a little login script (as part of a larger project) which uses PHP to store sessions with a user&#8217;s data in and got the following error.</p>
<p><em>Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0</em></p>
<p>Oh, well that&#8217;s no good. Looked through the code, and found I had spelt one variable wrong.</p>
<pre class="brush: php">$_SESSION['user_id'] = $user;</pre>
<p>but $user did not exist, it should have been</p>
<pre class="brush: php">$_SESSION['user_id'] = $user_id;</pre>
<p>So the error/warning appeared because I was referencing a null (or undefined) variable into a session; something which would require register_globals to work.</p>
<p>Register globals would allow you to call file.php?foo=bar; and the script would create a variable $foo with a value of bar automatically &#8211; which is not very secure as variables can be pushed into a script (perhaps bypassing form validation etc). Personally I would never use register_globals (set it to off in PHP.ini or your .htaccess) as mistakes like the one I made would go unnoticed &amp; could be abused.</p>
<p>I googled the error after I found that mistake to confirm that was the problem and was amazed to see people simply turning the warnings off rather than fixing the problem&#8230;talk about short cuts!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/07/register_globals-and-session-side-effects-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validating email addresses in PHP with Preg filters, DNS, MX Servers and other checks</title>
		<link>http://www.3cc.org/2010/04/validating-email-addresses-in-php-with-preg-filters-dns-mx-servers-and-other-checks/</link>
		<comments>http://www.3cc.org/2010/04/validating-email-addresses-in-php-with-preg-filters-dns-mx-servers-and-other-checks/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 10:27:17 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[preg]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.3cc.org/backyard/?p=46</guid>
		<description><![CDATA[There are many tutorials online that show users how to validate an email address, but most do it wrong. This means many websites will reject valid addresses such as customer/department=shipping@example.com or abc!def!xyz%yyy@example.com (yes, they are valid!) with the following expression: &#8230; <a href="http://www.3cc.org/2010/04/validating-email-addresses-in-php-with-preg-filters-dns-mx-servers-and-other-checks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are many tutorials online that show users how to validate an email address, but most do it wrong. This means many websites will reject valid addresses such as customer/department=shipping@example.com or abc!def!xyz%yyy@example.com (yes, they are valid!) with the following expression:</p>
<pre class="brush: php">"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"
</pre>
<p>If you&#8217;re here through search then you&#8217;ve probably already seen a load of these!</p>
<p>The code I&#8217;m going to provide:</p>
<ol>
<li>Allows international domains, and special characters in the email address</li>
<li>Checks for domain existance</li>
<li>Checks for mx records</li>
</ol>
<p>So&#8230;to the code. This was put together from a number of sources, then simply based off an article over at <a href="http://www.linuxjournal.com/article/9585">LinuxJournal</a>.</p>
<pre class="brush: php">function ValidateEmail($email) {
// Set test to pass
$valid = true;
// Find the last @ in the email
$findats = strrpos($email, "@");
// Check to see if any @'s were found
if (is_bool($findats) &amp;&amp; !$findats) {
$valid = false;
}
else {
// Phew, it's still ok, continue...
// Let's split that domain up.
$domain = substr($email, $findats+1);
$local = substr($email, 0, $findats);
// Find the local and domain lengths
$locallength = strlen($local);
$domainlength = strlen($domain);
// Check local (first part)
if ($locallength &lt; 1 || $locallength &gt; 64) {
$valid = false;
}
// Better check the domain too
elseif ($domainlength &lt; 1 || $domainlength &gt; 256) {
$valid = false;
}
// Can't be having dots at the start or end
elseif ($local[0] == '.' || $local[$locallength-1] == '.') {
$valid = false;
}
// Don't want 2 (or more) dots in the email
elseif ((preg_match('/\\.\\./', $local)) || (preg_match('/\\.\\./', $domain))) {
$valid = false;
}
// Make sure the domain has valid chars
elseif (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
$valid = false;
}
// Make sure the local has valid chars, make sure it's quoted right
elseif (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&amp;`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) {
if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) {
$valid = false;
}
}
// Whoa, made it this far? Check for domain existance!
elseif (!(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
$valid = false;
}
}
if ($valid) {
echo $email.' is valid!';
}
else {
echo $email.' is not valid!';
}
}
</pre>
<p>You&#8217;d call this with:</p>
<pre class="brush: php">ValidateEmail("test@3cc.org");
</pre>
<p>Fancy trying it? <a title="Validate Email Demo" href="http://www.3cc.org/projects/demos/validateemail.php" target="_blank">Click here to demo.</a></p>
<p>Or if you want this code with all the spaces, <a title="Validate Email text" href="http://www.3cc.org/projects/demos/validateemail.txt" target="_blank">click here to view the txt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/04/validating-email-addresses-in-php-with-preg-filters-dns-mx-servers-and-other-checks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPF Records for Google Apps Hosted Mail &#8211; avoiding rejected emails</title>
		<link>http://www.3cc.org/2010/04/spf-records-for-google-apps-hosted-mail-avoiding-rejected-emails/</link>
		<comments>http://www.3cc.org/2010/04/spf-records-for-google-apps-hosted-mail-avoiding-rejected-emails/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 10:23:58 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[domainkeys]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[google apps]]></category>
		<category><![CDATA[spf]]></category>

		<guid isPermaLink="false">http://www.3cc.org/backyard/?p=43</guid>
		<description><![CDATA[Using Google Apps for your domain&#8217;s email? Well you definately need to set up some SPF records. Reason I&#8217;m posting this? Made this mistake myself and had quite a few bounced emails! It seems yahoo is extremely strict when it &#8230; <a href="http://www.3cc.org/2010/04/spf-records-for-google-apps-hosted-mail-avoiding-rejected-emails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Using Google Apps for your domain&#8217;s email? Well you definately need to set up some SPF records.<br />
Reason I&#8217;m posting this? Made this mistake myself and had quite a few bounced emails! It seems yahoo is extremely strict when it comes to checking for SPF records on a domain, and bounces anything with missing records. Many other email providers like hotmail simply SPAM your message straight away.</p>
<p>Google provide the following resource for this problem: <a href="http://www.google.com/support/a/bin/answer.py?hl=en&amp;answer=33786" target="_blank">http://www.google.com/support/a/bin/answer.py?hl=en&amp;answer=33786</a></p>
<p>But, they recommend using</p>
<p>v=spf1 include:aspmx.googlemail.com ~all</p>
<p>That&#8217;s all fine and well&#8230;but what about the official website? Oddly, they recommend using &#8211; instead of ~ (<a href="http://www.openspf.org/FAQ/Common_mistakes" target="_blank">http://www.openspf.org/FAQ/Common_mistakes</a>)</p>
<p>v=spf1 include:aspmx.googlemail.com -all</p>
<p>But seeing as it&#8217;s google hosting my mail, I&#8217;ve been using ~ successfully for some time now, with no more bounces.</p>
<h2>Testing whether you&#8217;re configured correctly</h2>
<p>Easy, just send an email to <a href="mailto:spf-test@openspf.org">spf-test@openspf.org</a> and you&#8217;ll get a bounce right back with the SPF status in (<a href="http://www.openspf.org/Tools" target="_blank">http://www.openspf.org/Tools</a>).</p>
<h2>How can I configure my server?</h2>
<p>If you have access to all your DNS records for your domain you can add it yourself (for example through WHM or root plesk panel) but on most shared hosts just fire off an email to the support team who will add the record for you.</p>
<p>On Plesk &amp; Cpanel you can add either a SPF record or a TXT record through your DNS editor, making it easy to do this yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/04/spf-records-for-google-apps-hosted-mail-avoiding-rejected-emails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic Local, FTP &amp; Email Backups of MySQL Databases with Cron</title>
		<link>http://www.3cc.org/2010/04/automatic-local-ftp-email-backups-of-mysql-databases-with-cron/</link>
		<comments>http://www.3cc.org/2010/04/automatic-local-ftp-email-backups-of-mysql-databases-with-cron/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 10:20:39 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[automatic backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[email backup]]></category>
		<category><![CDATA[ftp backup]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.3cc.org/backyard/?p=38</guid>
		<description><![CDATA[I&#8217;ll start by saying this is not all my own code, it is based on dagon design&#8217;s original release in 2007 (Automatic MySql Backup Script) but this version builds on their version 2.1 to add FTP support. What this script &#8230; <a href="http://www.3cc.org/2010/04/automatic-local-ftp-email-backups-of-mysql-databases-with-cron/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll start by saying this is not all my own code, it is based on dagon design&#8217;s original release in 2007 (<a href="http://www.dagondesign.com/articles/automatic-mysql-backup-script/">Automatic MySql Backup Script</a>) but this version builds on their version 2.1 to add FTP support.</p>
<p>What this script can do:</p>
<ul>
<li>Backup all of your MySQL databases on a server individually, then package them into a single tar.</li>
<li>Save that tar locally, on a FTP server or even email it to you</li>
</ul>
<p>What you need:</p>
<ul>
<li>PHP</li>
<li>MySQL</li>
<li>Preferably the root mysql login &amp; password (allows you to backup all databases in one go)</li>
</ul>
<p>I do not guarantee:</p>
<ul>
<li>That this will definately work on your server, or Windows servers out of the box.</li>
</ul>
<p>However it is here for people to use. I have tested it on several linux machines and it runs great.</p>
<h2>Download:</h2>
<p>Zip containing dbbackup.php &amp; dbbackupconfig.php &#8211; <a href="http://3cc.org.s92871.gridserver.com/wp-content/uploads/2010/04/dbbackup.zip">dbbackup.zip</a></p>
<h2>What I&#8217;ve added:</h2>
<p>To upload to a remote FTP server, I added this to the config file:</p>
<pre class="brush: php">
######################################################################
## FTP Options
######################################################################

// Use FTP Option?
$useftp = true;

// Use passive mode?
$usepassive = true;

// FTP Server Address
$ftp_server = 'host';

// FTP Username &amp; Password
$ftp_user_name = 'username';
$ftp_user_pass = 'password';
</pre>
<p>and this to the main file below email sending:</p>
<pre class="brush: php">
// do we ftp the file?
if ($useftp == true) {
$file = $BACKUP_DEST.'/'.$BACKUP_NAME;
$remote_file = $BACKUP_NAME;

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// turn passive mode on?
ftp_pasv($conn_id, $usepassive);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
 echo "successfully uploaded to ftp: $remotefile\n";
} else {
 echo "There was a problem while uploading $remotefile\n";
}

// close the connection
ftp_close($conn_id);
}</pre>
<p>That&#8217;s all!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/04/automatic-local-ftp-email-backups-of-mysql-databases-with-cron/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Stripping everything but letters and numbers from a string in PHP with preg_replace</title>
		<link>http://www.3cc.org/2010/04/stripping-everything-but-letters-and-numbers-from-a-string-in-php-with-preg_replace/</link>
		<comments>http://www.3cc.org/2010/04/stripping-everything-but-letters-and-numbers-from-a-string-in-php-with-preg_replace/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 11:23:00 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[sanitize string]]></category>

		<guid isPermaLink="false">http://www.3cc.org/backyard/?p=33</guid>
		<description><![CDATA[Useful for a number of things including username and anything else you don&#8217;t want ANY special chars in, leaving only alphanumeric digits. &#60;?php $string = 'us$$er*&#38;^nam@@e'; $string = cleanabc123($string); function cleanabc123($data) { $data = preg_replace("/[^a-zA-Z0-9\s]/", "", $data); return $data; } &#8230; <a href="http://www.3cc.org/2010/04/stripping-everything-but-letters-and-numbers-from-a-string-in-php-with-preg_replace/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Useful for a number of things including username and anything else you don&#8217;t want ANY special chars in, leaving only alphanumeric digits.</p>
<pre class="brush: php">&lt;?php
$string = 'us$$er*&amp;^nam@@e';
$string = cleanabc123($string);
function cleanabc123($data)
{
$data = preg_replace("/[^a-zA-Z0-9\s]/", "", $data);
return $data;
}
// This will be 'username' now
echo $string;
?&gt;</pre>
<p>And if you wanted it to also remove whitespace, you could change the function by removing the \s whitespace character.</p>
<pre class="brush: php">$data = preg_replace("/[^a-zA-Z0-9]/", "", $data);</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.3cc.org/2010/04/stripping-everything-but-letters-and-numbers-from-a-string-in-php-with-preg_replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
