<?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>RubberNeck Designs &#187; PHP</title>
	<atom:link href="http://www.rubberneckdesigns.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rubberneckdesigns.com</link>
	<description>Web Developer Notes &#38; Sharing</description>
	<lastBuildDate>Sat, 10 Apr 2010 15:22:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Drupal Comments In A Block</title>
		<link>http://www.rubberneckdesigns.com/drupal-6/drupal-comments-in-a-block/</link>
		<comments>http://www.rubberneckdesigns.com/drupal-6/drupal-comments-in-a-block/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 15:22:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Drupal 6]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[User Iterface Design]]></category>
		<category><![CDATA[Web Security]]></category>

		<guid isPermaLink="false">http://www.rubberneckdesigns.com/?p=298</guid>
		<description><![CDATA[Why would you need to put Drupal comments into a block?  Well, recently I was working with another developer that decided to use Quick Tabs to create a menu that would show the current content type&#8217;s comments. Quick Tabs uses blocks, so there is one reason I can think of.
Ok, so getting the content type&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Why would you need to put Drupal comments into a block?  Well, recently I was working with another developer that decided to use Quick Tabs to create a menu that would show the current content type&#8217;s comments. Quick Tabs uses blocks, so there is one reason I can think of.</p>
<p>Ok, so getting the content type&#8217;s comments into a block is pretty easy once you know how.</p>
<p>This method will require you to use PHP code from within the block you will create to show the comments. So the first thing is to make sure that this is possible by going to site building and then modules and turning on the <strong>PHP Filter</strong> under the category of Core Optional (if it is not already on that is).</p>
<p><strong>NOTE: </strong>Check at <code>admin/settings/filters</code> to be sure that only trusted roles can use the PHP filter, otherwise your web site could be vulnerable to attack. By default, only the administrator can use this filter.</p>
<p>Create a new block and select a region for it. Put the following code on the <strong>body</strong> textarea:</p>
<p><img class="alignnone size-medium wp-image-308" title="comments in block php code for drupal" src="http://www.rubberneckdesigns.com/wp-content/uploads/2010/04/Screen-shot-2010-04-10-at-11.04.14-AM-300x186.jpg" alt="comments in block php code for drupal" width="300" height="186" /></p>
<p>Do not forget to select the <strong>PHP filter</strong> from the list of the <em>input filters</em>. After entering the rest of the settings for your block click save.</p>
<p>Now your new block should be ready to assign to whatever region you want. If the page you load has comments related to it. They should now appear via the block.</p>
<p>The arg() funtion may seem a bit cryptic if you&#8217;re new to Drupal. Here is a quick explanation from <a href="http://www.g-loaded.eu/2009/05/07/drupal-tip-list-a-nodes-taxonomy-terms-inside-a-block/#comment-12266">George Notaras</a> in his post: <a title="Drupal Tip: List a node’s taxonomy terms inside a Block" rel="bookmark" href="http://www.g-loaded.eu/2009/05/07/drupal-tip-list-a-nodes-taxonomy-terms-inside-a-block/">Drupal Tip: List a node’s taxonomy terms inside a Block</a> which I found helpful in compiling this information.</p>
<blockquote><p><span style="color: #0000ff;"><em>&#8220;Now to some technical details about <strong>arg(0)</strong> and <strong>arg(1)</strong>, which probably seem a bit cryptic to a user that is not experienced with Drupal (like me). Assume we have the following <strong>URL</strong> to a node: <code>www.example.org/node/23</code>, which means that the <strong>path</strong> to the page is <code>/node/23</code>. Well, </em><em>arg(0) is the <code>node</code> part and </em><em>arg(1) is the second part; <code>23</code> that is. Read about the <a href="http://api.drupal.org/api/function/arg">arg()</a> function.&#8221;</em></span></p></blockquote>
<p>I hope this was helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/drupal-6/drupal-comments-in-a-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX  Shopping Cart Design Using PayJuntion as the Gateway</title>
		<link>http://www.rubberneckdesigns.com/php/ajax-shopping-cart-design-using-payjuntion-as-the-gateway/</link>
		<comments>http://www.rubberneckdesigns.com/php/ajax-shopping-cart-design-using-payjuntion-as-the-gateway/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 14:22:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Search Engine Optimization]]></category>

		<guid isPermaLink="false">http://www.rubberneckdesigns.com/?p=279</guid>
		<description><![CDATA[I am working on a new shopping cart where all the action happens on one page in a simple non-distracted environment. PayJunction inc. will be the gateway I am using. I&#8217;ll keep you posted once I have made significant progress. If you have any specific question or issues you need addressed or even suggestions feel [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a new shopping cart where all the action happens on one page in a simple non-distracted environment. PayJunction inc. will be the gateway I am using. I&#8217;ll keep you posted once I have made significant progress. If you have any specific question or issues you need addressed or even suggestions feel free to post your comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/php/ajax-shopping-cart-design-using-payjuntion-as-the-gateway/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Schema Data Structure Documentation in Drupal</title>
		<link>http://www.rubberneckdesigns.com/drupal-6/schema-data-structure-documentation-in-drupal/</link>
		<comments>http://www.rubberneckdesigns.com/drupal-6/schema-data-structure-documentation-in-drupal/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 23:06:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Drupal 6]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal database scheme]]></category>
		<category><![CDATA[Drupal install file]]></category>
		<category><![CDATA[Drupal module install]]></category>

		<guid isPermaLink="false">http://rubberneckdesigns.com/?p=210</guid>
		<description><![CDATA[I have been working on a project on the Drupal 6 platform that requires the web application to recognize dynamically created sub-domains so the functionality of the database can be adjusted according to what sub-domain is in the current URL.
To get Drupal 6 to do this, I am creating a custom module. One of the [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a project on the Drupal 6 platform that requires the web application to recognize dynamically created sub-domains so the functionality of the database can be adjusted according to what sub-domain is in the current URL.</p>
<p>To get Drupal 6 to do this, I am creating a custom module. One of the things I have learned about creating a custom module in Drupal 6 is the implementation of the module&#8217;s “install” file.</p>
<p>If you create a module named say,  my_module.module then the module&#8217;s install file name would be  my_module.install and will reside in the directory named my_module located at&#8230;.</p>
<p>my_site/sites/all/modules/my_module</p>
<p><a href="http://http://drupal.org/node/323314">Drupal 6 Module Install File Documentation</a></p>
<p>The  .install file will be run by Drupal 6 the 1st time my_module has been enabled. The my_module.install file will then be used to run setup procedures as stipulated by your module. The most common task for the my_module.install file to perform is creating database tables and fields. There is no special syntax for the install file. It is simply a PHP file with a .install extension to properly identify it to the Drupal 6 platform.</p>
<p>There is special function used in the .install file called hook_schema(). Where hook would be replaced by the name of your module. For example, if  the module you create is named my_module, then you would create a PHP file and name it my_module.install. Inside that file you will create a function named  my_module_schema(). The my_module_schema() function is used to create arrays representingthe database tables you wish the module to create in the Drupal database. You can see how this works here.</p>
<h3>Why do it this way?</h3>
<p>Once you build the Drupal API Schema there is no more need for  separate CREATE TABLE or ALTER TABLE statements on each database. As a module developer, you only need to create a schema structure and/or use the Drupal Schema API functions, and Drupal takes care of the rest. This greatly simplifies  writing install and update functions.</p>
<p>This way of creating the module install files also allows for support in multiple database platforms.</p>
<p>According to Drupal&#8217;s Blog this also allows for “Several advanced capabilities, such as incremental database updates, a simple and consistent CRUD API, form scaffolding, simpler CCK and Views, schema and data validation, become much easier to implement in future enhancements.”</p>
<p><a href="http://http://drupal.org/node/146866">Schema Data Structure Documentation by Drupal</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/drupal-6/schema-data-structure-documentation-in-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wild Card Sub Domains</title>
		<link>http://www.rubberneckdesigns.com/apache/wild-card-sub-domains/</link>
		<comments>http://www.rubberneckdesigns.com/apache/wild-card-sub-domains/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 23:04:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[dynamic sub domain]]></category>
		<category><![CDATA[recognise sub domains]]></category>
		<category><![CDATA[sub domains Drupal]]></category>
		<category><![CDATA[sub domains in Plesk]]></category>
		<category><![CDATA[sub-domain]]></category>

		<guid isPermaLink="false">http://rubberneckdesigns.com/?p=212</guid>
		<description><![CDATA[I am working on a web site that will be taking on many Individual Business Owners. The web site is designed to create sub domains created dynamically according to the input of users as they sign up for the service. Since the web site is expected to accommodate up to 30,000 users it would not [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a web site that will be taking on many Individual Business Owners. The web site is designed to create sub domains created dynamically according to the input of users as they sign up for the service. Since the web site is expected to accommodate up to 30,000 users it would not be practical to edit the httpd.conf configuration file in Apache for each one. The file would simply grow to be enormous. The solution? Create wild-card sub domains.</p>
<p>Wild-card sub domains can be a great way to handle multiple sub domains that need to be created dynamically by making a simple edit to Apache via the terminal and some creative PHP programming.</p>
<p>The first step is alter Apache. There are a few ways to do this depending on how your server is set up.<br />
Here are some links I have found on how to do this in various server environments;</p>
<ul>
<li><a href="http://http://rackerhacker.com/2007/08/10/using-wildcard-subdomains-in-plesk/">PLesk</a></li>
<li><a href="http://http://kb.siteground.com/article/How_to_enable_wildcard_subdomains.html">cPanel</a></li>
<li><a href="http://http://steinsoft.net/index.php?site=programming/articles/apachewildcarddomain">In Apache</a></li>
</ul>
<p><strong>NOTE:</strong> In the case of the project I am working on, we have a dedicated server by RackSpace. It was necessary to register the wild-card sub-domain ( *.you-domain.com ) with their name servers as well in order for this to work.</p>
<h3>Step One: Set Up a Wild Card DNS Record</h3>
<p>The first step is to create a wildcard DNS record. Your DNS server is already resolving visitors to domain.tld, but it doesn&#8217;t know where to resolve them to find subdomain1.domain.tld.</p>
<p>You&#8217;ll need to create what is called an &#8220;A record,&#8221; which is short for &#8220;address record.&#8221; As the name implies, &#8220;A records&#8221; tell what IP address a host is pointing to.</p>
<p>The way to do this will vary based on your DNS server and what control panel (or command line) you are using, most are somewhat similar. When you create a name record of type “A” pointing from *.domain.tld to your web server&#8217;s IP address.</p>
<p>If you are using a control panel, then likely you can set this using a web form. Sometimes have to get your web host to do this.</p>
<p>Your web server&#8217;s DNS service may need to be restarted. You can expext it to take a few hours or even up to a few days sometimes to propagate throughout the Internet.</p>
<h3>Step Two: Set Up a Wild Card DNS Record</h3>
<p>Test and make sure it working by typing in a random sub-domain url to your site ( ie. Http://random-name.your-domain.com  ). It should resolve to your site&#8217;s home.</p>
<p>Now that any sub-domain will point to your domain, you can use some PHP to determine what URL brought your user to your site. Once you have that knowledge you can manipulate the functionality of  your site accordingly. Pretty cool!</p>
<h3>Recognize Which Sub Domain Brought Your Visitor With PHP</h3>
<p>One way to “recognize” the subdomain from the URL that brought you visitor is to use the a supper global ( which means they are available in all scopes throughout a script. There is no need to do global $variable; to access them within functions or methods) server variable called $_SERVER['HTTP_HOST'].</p>
<p>This super global variable will return the host name.<br />
ie.   sub-domain.your-domain.com<br />
( if there is no sub- domain then it would just be the domain.com)</p>
<p>If you use PHP&#8217;s explode with “.” as the delimiter, you can isolate the sub-domain by separating out the first element of the resulting array of URL parts like this&#8230;</p>
<p>$url_sections = explode(&#8221;.&#8221;,$_SERVER['HTTP_HOST']);<br />
$subdomain =$url_sections[0];</p>
<p>Knowing what sub-domain you&#8217;re dealing with gives you the PHP power to make you scripts act accordingly. In my case, I used the extracted information for the “virtual” sub-domain to query the MySQL database.</p>
<p>Wild card sub domains can useful for content management platforms like Drupal. With wild card sub domains and a little cleverness you can handle multiple sub domains within a single installation of Drupal.</p>
<h3>A Special Note Regarding  SEO</h3>
<p>It is very important that you do not have more than one URL (including the sub domain) point to identical content. Google penalizes for &#8220;duplicate content&#8221; so be sure not to carelessly point various unknown sub domains at your sites home page. With wild card sub domains, if a user makes a mistake and types in a misspelling then use PHP to redirect their page in some way that corrects them and then points them to the right page.</p>
<p>If you are dealing with this already and have any comments or suggestions or corrections feel free to post a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/apache/wild-card-sub-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploading Large Images</title>
		<link>http://www.rubberneckdesigns.com/php/uploading-large-images/</link>
		<comments>http://www.rubberneckdesigns.com/php/uploading-large-images/#comments</comments>
		<pubDate>Mon, 11 May 2009 21:01:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://rubberneckdesigns.com/?p=88</guid>
		<description><![CDATA[Recently I was working on scripting the back end of a commercial site in PHP5. In this case the back end user interface permits users to upload rather large image files so that the files can be processed for ‘Zoomify’( a fast way of showing a highly detailed &#8220;zoomable&#8221; image). After making sure the process [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on scripting the back end of a commercial site in PHP5. In this case the back end user interface permits users to upload rather large image files so that the files can be processed for ‘Zoomify’( a fast way of showing a highly detailed &#8220;zoomable&#8221; image). After making sure the process was secure, I also needed to change a few settings in the <a title="What is the PHP.INI (or configuration) File?" href="http://rubberneckdesigns.com/what-is-the-phpini-file-85">php.ini</a> file in order for the system to allow files sizes of over 2 megs (the standard PHP5 default).</p>
<p>It is generally not wise to make these changes in the php.ini file itself unless you have a very good reason. The preferred way would be to make the required change at execution time for the particular script you happen to be running only. This gives you better control over site operations and security. To do this you use the &#8220;ini_set()&#8221;  function.<br />
To demonstrate how to do this, I will show you the code for the four changes I needed to make to my script to accommodate the large image uploads. First, I defined global variables that determine what the setting should be.</p>
<div id="attachment_101" class="wp-caption alignnone" style="width: 442px"><img class="size-full wp-image-101" title="define_globals-050909" src="http://www.rubberneckdesigns.com.php5-5.dfw1-2.websitetestlink.com/wp-content/uploads/2009/05/define_globals-050909.png" alt="Defineing Globals in PHP" width="432" height="74" /><p class="wp-caption-text">Defineing Globals in PHP</p></div>
<p>I do this so that later if I chose to edit the settings I can do so from my configuration file and not have to hunt through the script to make the changes. Also this allows me to duplicate the setting elsewhere if needed. The setting are as follows:</p>
<dl id="attachment_103" class="wp-caption alignnone" style="width: 435px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-103" title="Use ini_set() to change settings in the php.ini file." src="http://www.rubberneckdesigns.com.php5-5.dfw1-2.websitetestlink.com/wp-content/uploads/2009/05/picture-131.png" alt="Use ini_set() to change settings in the php.ini file." width="425" height="79" /></dt>
</dl>
<p>Also, If you are using a form to upload the file, do not forget to make the MAX_FILE_SIZE directive large enough to accommodate your file size. By the way, do not rely on MAX_FILE_SIZE as any sort of security measure.</p>
<p>Once I made these settings on my local testing server, all worked well. However, after the site was in the “live” pre production mode, the large file sizes would return an error. I knew it was not the file size issue because I had already compensated for that. What tipped me off to the problem was the fact that, every once in a while the file would upload with no error. That is when I realized it was not only a “memory limit” issue but also a timing issue. This did not show up at first because it takes much longer for a file to upload to a remote server than to the local server.</p>
<p>Settings we do not often deal with are easy to forget about and that was the case this time. Once I remembered to reset the “max_execution_time”  to the appropriate amount of seconds, the files uploaded just fine.</p>
<p>As mentioned above, the maximum execution time limit is set in the php.ini file. The line of code in the php.ini file is:</p>
<div id="attachment_104" class="wp-caption alignnone" style="width: 449px"><img class="size-full wp-image-104" title="Set the max_execution time in the php.ini file." src="http://www.rubberneckdesigns.com.php5-5.dfw1-2.websitetestlink.com/wp-content/uploads/2009/05/picture-14.png" alt="Set the max_execution time in the php.ini file." width="439" height="37" /><p class="wp-caption-text">Set the max_execution time in the php.ini file.</p></div>
<p>With this little line of code in your PHP script, you are now afforded 180 seconds of time to run your program. You can adjust the seconds as you wish by simply changing the number.</p>
<p>I hope this helps!</p>
<p><img src="file:///Users/Paul/Library/Caches/TemporaryItems/moz-screenshot.jpg" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/php/uploading-large-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is the php.ini file?</title>
		<link>http://www.rubberneckdesigns.com/php/what-is-the-phpini-file/</link>
		<comments>http://www.rubberneckdesigns.com/php/what-is-the-phpini-file/#comments</comments>
		<pubDate>Mon, 11 May 2009 19:44:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://rubberneckdesigns.com/?p=85</guid>
		<description><![CDATA[A really great feature of PHP it the ability to modify its behavior by altering its configuration file (php.ini).
By having the php.ini file, PHP has made it easier to change how it responds and beh



aves even after it has already been installed. What a pain it would be to have to re-compile every time you [...]]]></description>
			<content:encoded><![CDATA[<p>A really great feature of PHP it the ability to modify its behavior by altering its configuration file (php.ini).</p>
<p>By having the php.ini file, PHP has made it easier to change how it responds and beh</p>
<dl id="attachment_92" class="wp-caption alignnone" style="width: 515px;">
<dt class="wp-caption-dt"></dt>
</dl>
<p>aves even after it has already been installed. What a pain it would be to have to re-compile every time you realize the need for a configuration change.</p>
<p>The php.ini file really helps make PHP more powerful and more secure as well. This is because you can configure PHP with secure settings until the setting need to change for some reason. Then you can also programmatically alter its behavior to accommodate a particular script file’s needs, on the fly, and returning the settings to normal when you’re done.</p>
<dl id="attachment_92" class="wp-caption alignnone" style="width: 424px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-92" title="Changeing the php ini file memory limit" src="http://www.rubberneckdesigns.com.php5-5.dfw1-2.websitetestlink.com/wp-content/uploads/2009/05/picture-121.png" alt="Changeing the php ini file memory limit" width="414" height="29" /></dt>
</dl>
<p>When PHP is booting, one of the first things it does is look at the php.ini file. It reads into memory the directives defined with in it. In most cases, when you compile PHP, it puts a copy of the php.ini file in /usr/local/lib/php. This may different depending upon your server.</p>
<p>If you are on a Unix machine, you may be able to type locate php.ini or find / -name php.ini -print and have it tell you the location of the php.ini file. If you have installed it on a Windows machine, use the &#8220;Find -&gt; Files or Folders&#8221; option from the Start Menu.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/php/what-is-the-phpini-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Protect Against SQL Injection</title>
		<link>http://www.rubberneckdesigns.com/ajax-web-design/how-to-protect-against-sql-injection/</link>
		<comments>http://www.rubberneckdesigns.com/ajax-web-design/how-to-protect-against-sql-injection/#comments</comments>
		<pubDate>Thu, 07 May 2009 17:44:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Security]]></category>

		<guid isPermaLink="false">http://rubberneckdesigns.com/?p=74</guid>
		<description><![CDATA[One of the most common web security problems is SQL Injection. As the name implies, SQL injections works by introducing malicious SQL code where it doesn&#8217;t belong. Since it is SQL code you could probably guess that the attacker &#8220;injects&#8221; his poison via database queries. Web developers often pass some sort of variable to their [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most common web security problems is SQL Injection. As the name implies, SQL injections works by introducing malicious SQL code where it doesn&#8217;t belong. Since it is SQL code you could probably guess that the attacker &#8220;injects&#8221; his poison via database queries. Web developers often pass some sort of variable to their database queries. Very common are variables that are influenced by user input. User input, to variable, then to query,- get it? So, there is a need for a way of eliminating the user&#8217;s ability to manipulate the variable in any way that could effect the query.</p>
<p><strong>What Happens With SQL Injection</strong></p>
<p>By passing an unexpected string of code into a user input, such a form, an attacker send damaging code that causes an otherwise good query to go haywire. For example:<span id="more-74"></span></p>
<div id="attachment_73" class="wp-caption alignleft" style="width: 384px"><img class="size-full wp-image-73" title="code snippet sql injection unprotected" src="http://www.rubberneckdesigns.com.php5-5.dfw1-2.websitetestlink.com/wp-content/uploads/2009/05/picture-8.png" alt="unprotected query is vulnerable" width="374" height="18" /><p class="wp-caption-text">unprotected query is vulnerable</p></div>
<p>The above snippet of code works as long as users put in the expected information. An attacker, will instead, make clever use of a few extra characters. You likely know by now that SQL requires a semi-colon at the end of each query. PHP automatically adds it in if you omit it. Because of this, the attacker, by closing the string and using the closing parenthesis to finish the query followed by a semi colon, can add an additional query to drop the table.<img class="size-full wp-image-75" title="example of SQL Injection" src="http://www.rubberneckdesigns.com.php5-5.dfw1-2.websitetestlink.com/wp-content/uploads/2009/05/picture-9.png" alt="example of SQL Injection" width="349" height="14" /></p>
<div class="mceTemp">
<dl id="attachment_75" class="wp-caption alignnone" style="width: 359px;">
<dd class="wp-caption-dd"><span style="color: #888888;">example of SQL Injection</span></dd>
</dl>
</div>
<p>This is what we in the world of secure web development refer to as a &#8216;bad thing&#8217;!<br />
Scary isn&#8217;t it? Attackers have used this method to not only drop tables and destroy records, but also to retrieve highly sensitive information.</p>
<p><strong>How to Protect Against SQL Injection</strong></p>
<p>OK, after that scary bit of information, you&#8217;ll be glad to know that protecting yourself is really not all that hard. The hard part is always remembering when and where to do it.</p>
<p>Protecting against SQL Injection is a simple matter of calling a PHP function that renders data safe ( or cleansed ) for use in a query. There are a few methods for cleansing user input in PHP depending on the PHP extension you are using. We will be discussing the mysql extension.The name of the function is:<br />
<span style="color: #0000ff;">mysql_real_escape_string()</span>. Notice in this snippet how it is used:</p>
<div id="attachment_72" class="wp-caption alignnone" style="width: 480px"><img class="size-full wp-image-72" title="code snippet mysql_real_escape_string" src="http://www.rubberneckdesigns.com.php5-5.dfw1-2.websitetestlink.com/wp-content/uploads/2009/05/picture-7.png" alt="How to protect again SQL Injection" width="470" height="205" /><p class="wp-caption-text">How to protect again SQL Injection</p></div>
<p>See how easy it is?  Just take the user input (in this case a post ) and pass it through the <span style="color: #0000ff;">mysql_real_escape_string()</span> function, (as shown on line 7 ). Then use the &#8220;cleansed&#8221; variable in the query ( as shown on line 9 ).</p>
<p>It is so easy to protect against this, yet it is often overlooked or forgotten. SO remember to use <span style="color: #0000ff;">mysql_real_escape_string()</span> to cleanse your input to help guard against SQL Injection.</p>
<p>There is more to learn and be discussed so feel free to stop back or drop me any suggestions or tips to share.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/ajax-web-design/how-to-protect-against-sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Error Reporting and Security</title>
		<link>http://www.rubberneckdesigns.com/php/php-error-reporting-and-security/</link>
		<comments>http://www.rubberneckdesigns.com/php/php-error-reporting-and-security/#comments</comments>
		<pubDate>Thu, 07 May 2009 15:55:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Security]]></category>

		<guid isPermaLink="false">http://rubberneckdesigns.com/?p=60</guid>
		<description><![CDATA[Error reporting in PHP gives valuable insight during the development stages. This Insight can be a great aid to problem solving. There are others, however who are interested in why your web site has failed on occasion. The information thrown out by many PHP errors gives the kind of information about your web application that [...]]]></description>
			<content:encoded><![CDATA[<p>Error reporting in PHP gives valuable insight during the development stages. This Insight can be a great aid to problem solving. There are others, however who are interested in why your web site has failed on occasion. The information thrown out by many PHP errors gives the kind of information about your web application that can make you vulnerable to crackers (malicious web site breakers). In fact apart from reading the code itself, error reporting is some of the most valuable intelligence an attacker can gather when looking for vulnerabilities in your web application.</p>
<p>So, what should be done once you launch your new web site? Well, as proud as you may be of your new creative geniuses, a wise web developer has the humility to recognize that bugs are still likely to surface from time to time. While you do not want any attackers to see error <span id="more-60"></span>reporting, the information is still valuable to you for squishing bugs. You can (and should) write your error reporting to a file. Actually, PHP does this by default. If you are on a shared server, though, you likely will not have access to this file. You will need to write these errors to your own file.</p>
<p><strong>Don&#8217;t Worry, Witting Errors to a File Is Easy</strong><br />
All you need to do is make a few adjustments in you php.ini file. Here are a few php.ini directives that are relevant:</p>
<p>•    <span style="color: #808080;">display_errors</span> This directive controls whether PHP errors should be sent to the screen. For the production environment this should be turned off.<br />
•    <span style="color: #808080;">error_reporting</span> This directive controls which errors that should be reported. You should set this to E_ALL and you should fix all issues that appear by doing this.<br />
•    <span style="color: #808080;">log_errors</span> This directive controls whether errors should be logged to a file. I would recommend that you always turn this on.<br />
•    <span style="color: #808080;">error_log</span> This is the path of the file errors should be written to. This is only applies if log_errors is turned on obviously.</p>
<p>Your directory structure effects how<span style="color: #808080;"> error_log</span> is set, since it involves creating a path to the error log.</p>
<p>The important thing to remember is that you want to be cautious about what information your error reporting is throwing out to the client. Whenever, possible keep it private. While it should be safely tucked away, it does provide valuable information to you as a web developer. So, keep it handy.</p>
<p>There are many other things to consider in safely setting up a PHP environment with security in mind. We will discuss these in future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/php/php-error-reporting-and-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Execution Time Limit Setting</title>
		<link>http://www.rubberneckdesigns.com/php/php-execution-time-limit-setting/</link>
		<comments>http://www.rubberneckdesigns.com/php/php-execution-time-limit-setting/#comments</comments>
		<pubDate>Wed, 06 May 2009 16:37:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[User Iterface Design]]></category>

		<guid isPermaLink="false">http://rubberneckdesigns.com/?p=57</guid>
		<description><![CDATA[Recently I had a little problem stump me while designing the back end of a commercial site. The back end user interface uploads rather large image files so that the files can be processed for ‘Zoomify’( a fast way of showing a highly detailed zoomable image). After making sure the process was secure, I also [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had a little problem stump me while designing the back end of a commercial site. The back end user interface uploads rather large image files so that the files can be processed for ‘Zoomify’( a fast way of showing a highly detailed zoomable image). After making sure the process was secure, I also needed to change a few settings in the PHP ini file in order for the system to allow files sizes of over 2 megs. All was working great on the local testing server. <span id="more-57"></span>However, once the site was in the “live” pre production mode, the large file sizes would return an error. I knew it was not the file size issue because I had already compensated for that with the<span style="color: #888888;"> ini_set(&#8221;memory_limit&#8221;,&#8221;64M&#8221;);</span> line.</p>
<p><strong>Setting the PHP Execution Time Limit</strong></p>
<p>What tipped me off to the problem was the fact that, every once in a while the file would upload with no error. That is when I realized it was not only a “memory limit” issue but also a timing issue.<br />
Settings we do not often deal with are easy to forget about and that was the case this time. Once I remembered to reset the<span style="color: #888888;"> max_execution_time</span> to the appropriate amount of seconds, the files uploaded just fine.</p>
<p>As mentioned above, the maximum execution time limit is set in the php.ini file. The line of code in the php.ini file is:</p>
<p><span style="color: #888888;">max_execution_time = 30 ; Maximum execution time of each script, in seconds</span></p>
<p>It is generally not wise to make this change in the php.ini file itself unless you have a very good reason. The preferred way would be to make the required change in execution time for the particular script you happen to be running only. This gives you better control over site operations and security.</p>
<p>Simply place an ini file setting within the file that executes the script which is causing a delay ( in my case the file upload ). The line code looks like this:</p>
<p><span style="color: #888888;">set_time_limit ( 60 ) ;</span></p>
<p>With this little line of code in you PHP script, you are now afforded 60 seconds of time to run your program. You can adjust the seconds as you wish by simply changing the number. I hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rubberneckdesigns.com/php/php-execution-time-limit-setting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
