<?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>Ideologics &#187; PHP</title>
	<atom:link href="http://www.ideologics.co.uk/tags/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ideologics.co.uk</link>
	<description>All About Computers</description>
	<lastBuildDate>Fri, 20 May 2011 04:05:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to prevent multiple form submissions in PHP</title>
		<link>http://www.ideologics.co.uk/programming/how-to-prevent-multiple-form-submissions-in-php</link>
		<comments>http://www.ideologics.co.uk/programming/how-to-prevent-multiple-form-submissions-in-php#comments</comments>
		<pubDate>Tue, 30 Dec 2008 03:43:58 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdesign]]></category>

		<guid isPermaLink="false">http://www.eyeonsilicon.co.uk/?p=269</guid>
		<description><![CDATA[A problem that many programmers encounter is trying to prevent the user from submitting a form twice and inadvertently posting two sets of the same data &#8211; or in worse scenarios, charging a credit card twice! It&#8217;s a frustrating problem &#8230; <a href="http://www.ideologics.co.uk/programming/how-to-prevent-multiple-form-submissions-in-php">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A problem that many programmers encounter is trying to prevent the user from submitting a form twice and inadvertently posting two sets of the same data &#8211; or in worse scenarios, charging a credit card twice!</p>
<p>It&#8217;s a frustrating problem that is easily solved if you put your mind to it &#8211; ignoring it is nothing short of lazy.</p>
<p>On the client-side, we can use JavaScript to prevent the user from submitting the form more than once. Observe:</p>
<p><span id="more-269"></span><br />
<code>&lt;form action="script.php" method="post" onclick="validateForm();"&gt;<br />
Your name? &lt;input name="name" value=""&gt; &lt;input type="submit"&gt;<br />
&lt;/form&gt;<br />
&lt;script type="text/javascript"&gt;<br />
var submitted=false;<br />
function validateForm() {<br />
  if (submitted) {<br />
    alert("Please only submit the form once.");<br />
    return false;<br />
  } else {<br />
    return true;<br />
  }<br />
}<br />
&lt;/script&gt;</code></p>
<p>The idea is that when the user clicks the submit button, we flag the action in &#8216;submitted&#8217;. If the user clicks again, the function validateForm() will check &#8216;submitted&#8217; and prevent multiple submissions of the form.</p>
<p>But this isn&#8217;t enough &#8211; not everybody has JavaScript enabled, and assuming so would be lazy.</p>
<p><!--adsense--></p>
<p>We need some internal detection too, and one way to detect multiple submissions would be to use PHP sessions. Observe:</p>
<p><code>&lt;?php<br />
  session_start();<br />
  if ($_SESSION['formsessions'][$_POST['formsession']]) {<br />
    // form already submitted!<br />
    // ideally, at this point, you'd want to forward them to another page.<br />
    exit('form submitted twice.')<br />
  }<br />
// mark the session as submitted.<br />
  $_SESSION['formsessions'][$_POST['formsession']]=true;<br />
?&gt;</code></p>
<p>Again, we&#8217;re checking to see if the form has already been submitted. This script would require that we submit a &#8216;formsession&#8217; field with the form to make it uniquely identifiable. This could be as easy as inserting the following into the form code:</p>
<p><code>&lt;?php<br />
  echo '&lt;input type="hidden" name="formsession" value="'.md5(date('U').'-'.rand(1000000,9999999)).'"&gt;';<br />
?&gt;</code></p>
<p>With these two methods combined, no user should be able to submit the same form twice &#8211; accidentally, at least.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideologics.co.uk/programming/how-to-prevent-multiple-form-submissions-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use SSL / HTTPS effectively in your PHP website</title>
		<link>http://www.ideologics.co.uk/programming/how-to-use-https-effectively-in-your-php-website</link>
		<comments>http://www.ideologics.co.uk/programming/how-to-use-https-effectively-in-your-php-website#comments</comments>
		<pubDate>Thu, 18 Dec 2008 06:25:16 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.eyeonsilicon.co.uk/?p=270</guid>
		<description><![CDATA[So, you&#8217;ve got a big website with thousands of members, it brings in $50 a day, and your community couldn&#8217;t be happier. What could be better? HTTPS could be better. There&#8217;s just something so exciting about that little padlock appearing &#8230; <a href="http://www.ideologics.co.uk/programming/how-to-use-https-effectively-in-your-php-website">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;ve got a big website with thousands of members, it brings in $50 a day, and your community couldn&#8217;t be happier. What could be better? HTTPS could be better.</p>
<p>There&#8217;s just something so exciting about that little padlock appearing beside your domain name. To your customers it shows that you care about their online safety, and that you want them to feel safe.</p>
<p>But, HTTPS can be a complete pain to code, and many people go about it completely the wrong way. So here&#8217;s my entry to help those of you struggling with integrating HTTPS in PHP.</p>
<p><span id="more-270"></span></p>
<p><img class="size-medium wp-image-272 alignright" style="border: 5px solid black;" title="httpslogo" src="http://www.ideologics.co.uk/wp-content/uploads/httpslogo.jpg" alt="" width="300" height="191" /></p>
<p>Look to the right &#8211; wouldn&#8217;t you feel safer seeing padlocks everywhere? Your customers would too. But it really doesn&#8217;t need to be everywhere. If you served 100,000 pages a day, chances are only 1,000 of those pages need to be served securely. If we were running a shop front, selling computer parts, this is how the user&#8217;s actions would look in an ideal world:</p>
<ol>
<li>User types in www.yourshop.co.uk and presses enter.</li>
<li>They type &#8216;computer monitor lead&#8217; into the search box and hit enter.</li>
<li>They see that you have a wide range of leads available and spot the one they want. So they click &#8216;Add To Cart&#8217;.</li>
<li>They notice a cool TV Tuner in the similar items section, so they click that. Then they click &#8216;Add To Cart&#8217; again.</li>
<li>Now they&#8217;ve had enough of running up a bill, so they click &#8216;Checkout&#8217;.</li>
<li>They type in their details, such as their first name, last name and address.</li>
<li>They fill in their credit card numbers.</li>
<li>They click Process and wait.</li>
<li>Your site serves them with the Checkout Complete page.</li>
</ol>
<div>So as you can see, average Joe doesn&#8217;t care much about the fancy decorations on your site, they&#8217;re just looking to get stuff done. There are two things to note about this set of actions, though:</div>
<div>
<ul>
<li>Average Joe doesn&#8217;t submit any sensitive data until action 6. This means that you don&#8217;t need an HTTP connection until Joe checks out.</li>
<li>Average Joe might decide against submitting his details if he notices that you don&#8217;t have a secure connection available at checkout.</li>
</ul>
<div>Conclusion: It&#8217;s worth the time implementing HTTPS, and there are ways to do it effectively. And this is how I&#8217;d go about doing it.</div>
</div>
<h3>1. Users Don&#8217;t Like Unexpected Messages</h3>
<p>First, avoid prompting those horrible error messages that warn the user of insecure data on a secure page. These are usually present when the page includes links to images on other servers that aren&#8217;t secure &#8211; but it can also happen if you use full URLs instead of relative URLs. Example:</p>
<p><span style="color: #ff0000;"><strong><span style="color: #800000;">WRONG:</span></strong></span> &lt;img src=&#8221;http://www.yourshop.co.uk/image/robodog.jpg&#8221;&gt;</p>
<p><span style="color: #339966;"><span style="color: #008000;"><strong>CORRECT:</strong></span></span> &lt;img src=&#8221;/image/robodog.jpg&#8221;&gt;</p>
<p>You see? Use relative paths and you won&#8217;t run into this problem. As for images on other websites, upload them on to your own site. Example:</p>
<div>
<p><span style="color: #ff0000;"><span style="color: #800000;"><strong>WRONG:</strong></span></span> &lt;img src=&#8221;http://www.otherdomain.co.uk/robocat.jpg&#8221;&gt;</p>
<p><span style="color: #339966;"><span style="color: #008000;"><strong>CORRECT</strong></span></span><span style="color: #008000;"><strong>:</strong></span> &lt;img src=&#8221;/image/robocat.jpg&#8221;&gt;</div>
<p>Evading these error messages helps add to the user experience.</p>
<h3>2. Make HTTPS Easy</h3>
<p>Manually linking to HTTPS and HTTP is a nightmare, and you&#8217;ll probably always be correcting links. It also doesn&#8217;t make for good error correction. Here&#8217;s how to do it effectively.</p>
<p><!--adsense--></p>
<p>In every script you think should be served via HTTPS, place $securePage=1 at the very beginning of the script &#8211; that&#8217;s BEFORE your config script.</p>
<p>In your config script, we will place HTTPS detection code to redirect if appropriate.</p>
<pre>      if ($_SERVER['HTTPS']=='on') {
        // we are on a secure page.
        if (!$securepage) {
          // but we shouldn't be!
          $url='http://www.yourshop.co.uk'.$_SERVER['REQUEST_URI'];
          header('location: '.$url);
          exit;
        }
      } else {
        // we aren't on a secure page.
        if ($securepage) {
          // but we should be!
          $url='https://www.yourshop.co.uk'.$_SERVER['REQUEST_URI'];
          header('location: '.$url);
          exit;
        }
      }</pre>
<p>So if we&#8217;re currently in HTTPS mode, but $securePage doesn&#8217;t equal 1, the config script will redirect to HTTP mode. And the same the other way round &#8211; if $securePage says we should be serving secure pages, config will redirect to HTTPS mode.</p>
<p>This is a simple yet effective way of enforcing secure behaviour. It doesn&#8217;t mean that you can&#8217;t provide full URL links where they are appropriate &#8211; and it is recommended that you do so if you can.</p>
<p>Let me know if you use my code in your own projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideologics.co.uk/programming/how-to-use-https-effectively-in-your-php-website/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Flaws in PHP sessions &#8211; session_start causes site to run slowly</title>
		<link>http://www.ideologics.co.uk/programming/flaws-in-php-sessions-session_start-causes-site-to-run-slowly</link>
		<comments>http://www.ideologics.co.uk/programming/flaws-in-php-sessions-session_start-causes-site-to-run-slowly#comments</comments>
		<pubDate>Thu, 27 Nov 2008 02:04:32 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.eyeonsilicon.com/?p=134</guid>
		<description><![CDATA[PHP is a versatile language that gives the programmer many tools to get the job done. One such tool is sessions, but in some cases sessions can have a detrimental effect on your site&#8217;s performance. Since switching from a Windows &#8230; <a href="http://www.ideologics.co.uk/programming/flaws-in-php-sessions-session_start-causes-site-to-run-slowly">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>PHP is a versatile language that gives the programmer many tools to get the job done. One such tool is <a href="http://www.php.net/session">sessions</a>, but in some cases sessions can have a detrimental effect on your site&#8217;s performance.</p>
<p>Since switching from a Windows server to a UNIX server, I noticed a huge increase in overall site performance &#8211; but sometimes, with no noticeable pattern, a page would take a minute to load against the average which was under a second.</p>
<p>After messing with the scripts and painstakingly commenting out sections of code, I discovered that the problem lie quietly in the PHP sessions &#8211; specifically the session_start function. Perhaps it has something to do with disk operations and UNIX operating systems, whatever it was it was causing some frustrating performance problems.</p>
<p><span id="more-134"></span></p>
<p><!--adsense--></p>
<p>I decided to alter rid of all session functions and create my own version that interacted with a MySQL HEAP table &#8211; that&#8217;s a table stored in the server&#8217;s memory instead of on disk. Instantly the site performance was noticeable better, pages loaded more instantaneously.</p>
<p>Looking into the PHP sessions further I discovered another flaw &#8211; if your visitor was to load several pages at once, each page would pause until the previous page had finished loading. This is because no two scripts can access the same session at any given time &#8211; session access is serial, not parallel. If a page takes one minute to process and another page takes a second to process, but the heavier page is loaded first, the reader will have to wait for heavier page to finished processing because they can see the page that would have taken a second to process. This increases the queues to the web server and doesn&#8217;t do much for the user&#8217;s experience.</p>
<p>It may however be helpful in some instances, for example if you were altering a virtual tree structure you wouldn&#8217;t want the functions to collide in operation. For what I had been using sessions for, it wasn&#8217;t helpful at all.</p>
<p>I&#8217;m going to make a modular version of the alternative session code and publish it here, so come back later if you want a copy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideologics.co.uk/programming/flaws-in-php-sessions-session_start-causes-site-to-run-slowly/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Review: PHP Expert Editor &#8211; Script Editing Tool</title>
		<link>http://www.ideologics.co.uk/programming/review-php-expert-editor-php-script-editing-tool</link>
		<comments>http://www.ideologics.co.uk/programming/review-php-expert-editor-php-script-editing-tool#comments</comments>
		<pubDate>Fri, 31 Oct 2008 18:08:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.eyeonsilicon.com/?p=98</guid>
		<description><![CDATA[For anybody coding or wanting to code in PHP, a decent editor is vital. Sticking with old-fashioned notepad just won&#8217;t cut it, what you need is the mothership of editors &#8211; and I think I&#8217;ve found it! PHP Expert Editor &#8230; <a href="http://www.ideologics.co.uk/programming/review-php-expert-editor-php-script-editing-tool">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ideologics.co.uk/wp-content/uploads/php.gif"><img class="alignright size-medium wp-image-99" title="php" src="http://www.ideologics.co.uk/wp-content/uploads/php.gif" alt="" width="120" height="67" /></a>For anybody coding or wanting to code in PHP, a decent editor is vital. Sticking with old-fashioned notepad just won&#8217;t cut it, what you need is the mothership of editors &#8211; and I think I&#8217;ve found it!</p>
<p>PHP Expert Editor is developed by Ankord Development Group, and is one of the more serious entries in this field. And at 35 EUR for a life time license, it won&#8217;t shred your wallet either. (What? You didn&#8217;t expect it to be free, did you?)</p>
<p><span id="more-98"></span></p>
<p>The basics of the editor make writing a PHP script a breeze, with features such as code highlighting &#8211; where the difference between HTML and PHP is blazingly obvious, and identifying quotes that have been left open isn&#8217;t a needle-in-a-haystack job anymore. But other features such as the left hand side structure that allows you to close blocks of text off and just work with the text you need make editing considerably less stressful.</p>
<p>PHP Expert Editor also has an FTP client built in, enabling it to access practically anything.</p>
<p><!--adsense--></p>
<p>What else is there? A built in colour selector, all the usual HTML form tools, HTML symbols, auto indentation, macros, syntax checking and integrated script checking. Basically &#8211; yes &#8211; this is truly the mothership. Get on board.</p>
<p>I think the most useful feature in this editor would be its knowledge of PHP&#8217;s internal functions. When you type &#8216;join&#8217;, a helpful balloon appears above the cursor showing you the appropriate parameters for the function. It does it with everything, and really helps the programmer concentrate on what matters &#8211; the coding.</p>
<p>If you want to try it, it comes with a 30 day trial, so you don&#8217;t have anything to lose. You can download it at <a href="http://www.phpexperteditor.com">www.phpexperteditor.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideologics.co.uk/programming/review-php-expert-editor-php-script-editing-tool/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Part 1) PHP &amp; MySQL: How to create a resource system</title>
		<link>http://www.ideologics.co.uk/programming/part-1-php-mysql-how-to-create-a-resource-system</link>
		<comments>http://www.ideologics.co.uk/programming/part-1-php-mysql-how-to-create-a-resource-system#comments</comments>
		<pubDate>Tue, 28 Oct 2008 00:23:56 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.eyeonsilicon.com/?p=41</guid>
		<description><![CDATA[One of the biggest problems faced with content rich websites is how to store the data than enriches them. Therefore, I&#8217;d like to offer my solution &#8211; something I call &#8216;the resource system&#8217;. Specifically, this is designed for PHP &#38; &#8230; <a href="http://www.ideologics.co.uk/programming/part-1-php-mysql-how-to-create-a-resource-system">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the biggest problems faced with content rich websites is how to store the data than enriches them. Therefore, I&#8217;d like to offer my solution &#8211; something I call &#8216;the resource system&#8217;.</p>
<p>Specifically, this is designed for PHP &amp; MySQL, but in theory could be adapted to work with other platforms.</p>
<p>The idea is to take the large part of the data (the content) and place it into a set of tables where it can be managed by a resource system.</p>
<p><span id="more-41"></span></p>
<p>Suppose we have a table called &#8216;posts&#8217;, which stored a unique ID, title, date and content for each row. Now suppose we used this table to store the daily posts from our members. If we had 1000 members who posted daily, it wouldn&#8217;t be long before our table reached a phenomenal size.</p>
<p><!--adsense--></p>
<p>When you query that table for a list of the entries, you&#8217;ll almost never use the content field. Separating the content from the rest of the information allows for quicker alteration of what we&#8217;ll refer to now as the &#8216;log&#8217;.</p>
<p>This calls for a system that can manage content in its bare form &#8211; text. We need to be able to take the content, submit it to a function that returns a resource-ID that we can store in the &#8216;log&#8217;. Then later retrieve that data using the resource-ID.</p>
<p>Making the system structured like this will allow for further optimisation later using a utility called MEMCACHED, but we&#8217;ll leave that for a later post.</p>
<p>There are many advantages to this system, that we&#8217;ll discuss in the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideologics.co.uk/programming/part-1-php-mysql-how-to-create-a-resource-system/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

