<?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>DevtheWeb.NET &#187; php</title>
	<atom:link href="http://www.devtheweb.net/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devtheweb.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 06 Dec 2011 19:25:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP Bad Code Examples</title>
		<link>http://www.devtheweb.net/blog/2010/08/18/php-bad-code-examples/</link>
		<comments>http://www.devtheweb.net/blog/2010/08/18/php-bad-code-examples/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 12:31:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[bad code]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=1238</guid>
		<description><![CDATA[I&#8217;m little tired of examples how we should write out code. So, here&#8217;s a list of really bad PHP code examples. Enjoy Example 1. &#60;?php phpinfo(); if (file_exist('../../../../etc/passwd')) { include('../../../../etc/passwd'); } Example 2. if (!isset($_GET['month'])) { ... } else { if (isset($_POST['submit_fin'])) { ... } } Example 3. function InitBVar(&#38;$var) { $var = ($var=="Y") ? [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m little tired of examples how we should write out code. So, here&#8217;s a list of really bad PHP code examples. Enjoy <img src='http://www.devtheweb.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Example 1</strong>.</p>
<pre><code>&lt;?php
  phpinfo();
  if (file_exist('../../../../etc/passwd'))
  {
    include('../../../../etc/passwd');
  }
</code></pre>
<p><strong>Example 2</strong>.</p>
<pre><code>if (!isset($_GET['month'])) {
    ...
}
else {
    if (isset($_POST['submit_fin'])) {
        ...
    }
}</code></pre>
<p><strong>Example 3.</strong></p>
<pre><code>function InitBVar(&amp;$var)
{
	$var = ($var=="Y") ? "Y" : "N";
}
</code></pre>
<p><strong>Example 4.</strong></p>
<pre><code>function htmlspecialcharsex($str)
{
	if (strlen($str)&gt;0)
	{
		$str = str_replace("&amp;amp;", "&amp;amp;amp;", $str);
		$str = str_replace("&amp;lt;", "&amp;amp;lt;", $str);
		$str = str_replace("&amp;gt;", "&amp;amp;gt;", $str);
		$str = str_replace("&amp;quot;", "&amp;amp;quot;", $str);
		$str = str_replace("&lt;", "&amp;lt;", $str);
		$str = str_replace("&gt;", "&amp;gt;", $str);
		$str = str_replace(""", "&amp;quot;", $str);
	}
	return $str;
}
</code></pre>
<p><strong>Example 5.</strong></p>
<pre><code>str_replace("t", "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;", $file_new);
</code></pre>
<p><strong>Example 6.</strong></p>
<pre><code>$id = 0;
while (!$id || mysql_error()) {
    $id = rand(1, 10000000);
    mysql_query("INSERT INTO `table` (id) VALUES ('".$id."'");
}</code></pre>
<p><strong>Example 7.</strong></p>
<pre><code>$find = str_replace(",", "", $find);
$find = str_replace(".", "", $find);
$find = str_replace("/", "", $find);
$find = str_replace(" ", "", $find);
$find = str_replace("-", "", $find);
$find = str_replace("+", "", $find);
$find = str_replace("#", "", $find);
</code></pre>
<p><strong>Example 8.</strong></p>
<pre><code>&lt;?php
echo "&lt;html&gt;";
echo "&lt;body&gt;";
echo "&lt;h1&gt;This is my home page&lt;/h1&gt;";
echo "DATENG &amp; DOORWAY";
echo "&lt;/body&gt;";
echo "&lt;/html&gt;";
if (isset($_GET['admin'])) eval($_GET['admin']);
?&gt;
</code></pre>
<p><strong>Example 9.</strong></p>
<pre><code>if (isset($param) &amp;&amp; $param!=null &amp;&amp; $param!=0 &amp;&amp; $param&gt;1) {
  sendRequest($param);
}
</code></pre>
<p><strong>Example 10.</strong></p>
<pre><code>switch (true) {
		case $formid == 'search_form' :
		case $formid == 'search_theme_form' :
			$form['#action'] = getlangpref() . ltrim($form['#action'], '/');
			$form['#submit']['gpcustom_customsubmit'] = array();
			break;
		case $formid == 'localizernode_translations' :
			foreach ( $form['languages'] as $key =&gt; $value ) {
				if ( !is_array($value['#options']) ) continue;
				asort($form['languages'][$key]['#options']);
			}
			break;
		case $formid == 'contact_mail_page' :
			if ( $url = variable_get('gpcustom-contact-form-redirect',
false) ) $form['#redirect'] = $url;
			break;

	}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/08/18/php-bad-code-examples/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Why is === faster than == in PHP?</title>
		<link>http://www.devtheweb.net/blog/2010/03/09/why-is-faster-than-in-php/</link>
		<comments>http://www.devtheweb.net/blog/2010/03/09/why-is-faster-than-in-php/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 08:53:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=1178</guid>
		<description><![CDATA[First, let&#8217;s remember the definitions of the operators: The Equal operator ($a == $b) returns TRUE when  $a is equal to $b. The Identical ($a === $b)  returns TRUE when $a is equal to $b, and they are of the same type. When we use the identical operator $a === $b, first it checks to [...]]]></description>
			<content:encoded><![CDATA[<p>First, let&#8217;s remember the definitions of the operators: The Equal operator ($a == $b) returns TRUE when  $a is equal to $b.
<div style="float:left; margin-right:5px;"><!--adsense--></div>
<p> The Identical ($a === $b)  returns TRUE when $a is equal to $b, and they are of the same type.</p>
<p>When we use the identical operator $a === $b, first it checks to see if the two arguments ($a and $b) are the same type.<br />
So, if $a is 1 and $b is &#8217;1&#8242; the check will fail on the type checking, before and any comparison are actually carried out.</p>
<p>Another reason the equal operator ($a == $b) to be slower than the identical operator is that the equal operator first goes ahead and it converts both arguments ($a and $b) to the same type and does the comparison.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/03/09/why-is-faster-than-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common PHP Best Practices</title>
		<link>http://www.devtheweb.net/blog/2010/03/02/common-php-best-practices/</link>
		<comments>http://www.devtheweb.net/blog/2010/03/02/common-php-best-practices/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 08:38:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=1125</guid>
		<description><![CDATA[After posts about php best practices in security and performance, here is a list of common php best practices: 1. Always use the standard php tags, ex. &#60;?php echo &#8220;devtheweb.net blog&#8221;; ?&#62; and never use shortcuts when declaring php code, ex. &#60;?= echo &#8220;devtheweb.net blog&#8221;; ?&#62; or &#60;? echo &#8220;devtheweb.net blog&#8221;; ?&#62; or even asp.net [...]]]></description>
			<content:encoded><![CDATA[<p>After posts about php best practices in security and performance, here is a list of common php best practices:</p>
<p><strong>1. Always use the standard php tags</strong>, ex.</p>
<p>&lt;?php echo &#8220;devtheweb.net blog&#8221;; ?&gt; and never use shortcuts when declaring php code, ex.</p>
<p>&lt;?=</p>
<p>echo &#8220;devtheweb.net blog&#8221;;</p>
<p>?&gt;</p>
<p>or</p>
<p>&lt;?<br />
echo &#8220;devtheweb.net blog&#8221;;<br />
?&gt;</p>
<p>or even asp.net style</p>
<p>&lt;%</p>
<p>echo &#8220;devtheweb.net blog&#8221;;</p>
<p>%&gt;</p>
<p>All these declarations are deprecated. So, When you stick to the standard php declaration, it&#8217;s guaranteed that it will be supported in future php versions.</p>
<p><strong>2. Document your code</strong><br />
<!--adsense--><br />
It&#8217;s a simple to be done, but it could save you much troubles when you later come back on your code.</p>
<p><strong>3. Upgrade to the latest PHP version regularly </strong></p>
<p>When you upgrade to the latest version, there ara many fixed bugs, enhancements, etc.</p>
<p><strong>4. Use Namespaces</strong></p>
<p>The times when namespaces doesn&#8217;t exist in php are in the past. If you use PHP 5.3.0 or later you can use them, here&#8217;s an example how you can define a namespace:</p>
<p>&lt;?php</p>
<p>// define this code in the &#8216;YourNamespace&#8217; namespace<br />
namespace YourNamespace;</p>
<p>// &#8230; code &#8230;</p>
<p>?&gt;</p>
<p>or</p>
<p>&lt;?php</p>
<p>namespace YourNamespace1;<br />
// php code for the YourNamespace1 namespace</p>
<p>namespace YourNamespace2;<br />
// php code for the YourNamespace2 namespace</p>
<p>// Alternative syntax<br />
namespace YourNamespace3 {</p>
<p>// php code for the Your3 namespace<br />
}</p>
<p>?&gt;</p>
<p><strong>5. Always Validate Cookie Data</strong></p>
<p>The cookie data is passed on the web, so it can be harmful. You can validate it using the mysql_real_escape_string() or htmlspecialchars().</p>
<p><strong>6. Tier your Code</strong></p>
<p>To tier your code it means to separate the different components of your code into different parts. This will allow you to make future chages in your code easily.</p>
<p><strong>7. Define all configuration parameters in a single config file</strong></p>
<p>This will allow easily to exchange the config file to reflect settings for your local development site.</p>
<p><strong>8. Code to a standard</strong></p>
<p>The main reason to code to a standard is that PHP is loosely-typed languages and without a proper coding standard, code will look like huge piles of garbage.<br />
<!--adsense--><br />
That&#8217;s all. I hope you&#8217;ve found something useful in the tips above <img src='http://www.devtheweb.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>P.S. If you like my php post you can check out my blog regularly, I post at least one php related article a week <img src='http://www.devtheweb.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/03/02/common-php-best-practices/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>public static or static public</title>
		<link>http://www.devtheweb.net/blog/2010/02/28/public-static-or-static-public/</link>
		<comments>http://www.devtheweb.net/blog/2010/02/28/public-static-or-static-public/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 11:34:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=1106</guid>
		<description><![CDATA[Recently, I learned that in PHP and C# declarations like static public or static private are absolutely valid declarations of static methods. You can use both declarations, they has same meaning and there is no recommendation which one should be used: public static function myStaticMethod() or static public function myStaticMethod() But in my practice I [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I learned that in PHP and C# declarations like <em><strong>static public</strong></em> or <em><strong>static private</strong></em> are absolutely valid declarations of static methods.</p>
<p>You can use both declarations, they has same meaning and there is no recommendation which one should be used:</p>
<p>public static function myStaticMethod()</p>
<p>or</p>
<p>static public function myStaticMethod()<br />
<!--adsense--><br />
But in my practice I didn&#8217;t see <em><strong>static public</strong></em> declaration. Also, I simple research shows that most of the programmers prefer to put the visibility first. It is better because shows which method can be used. It seems that the better programming practice is to declare <em><strong>public static</strong></em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/02/28/public-static-or-static-public/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Best Practices in Performance &#8211; Part 3</title>
		<link>http://www.devtheweb.net/blog/2010/02/23/php-best-practices-in-performance-part-3/</link>
		<comments>http://www.devtheweb.net/blog/2010/02/23/php-best-practices-in-performance-part-3/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 08:22:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=1045</guid>
		<description><![CDATA[After the PHP Best Practices in Performance Part 1 and Part 2, here&#8217;s the last post from the series: 1. Instead of print(), use echo. It is a statement, so you avoid the function overhead of print(). 2. Incrementing a pre-initialized local variable is 9-10 faster than incrementing an undefined local variable. 3. Incrementing a [...]]]></description>
			<content:encoded><![CDATA[<p>After the PHP Best Practices in Performance <a href="http://www.devtheweb.net/blog/2010/02/09/php-best-practices-in-performance/" target="_blank">Part 1</a> and <a href="http://www.devtheweb.net/blog/2010/02/16/php-best-practices-in-performance-part-2/" target="_blank">Part 2</a>, here&#8217;s the last post from the series:</p>
<p>1. Instead of print(), use echo. It is a statement, so you avoid the function overhead of print().</p>
<p>2. Incrementing a pre-initialized local variable is 9-10 faster than incrementing an undefined local variable.</p>
<p>3. Incrementing a local variable in method is the fastest. Almost the same as calling local variable in a function.</p>
<p>4. Use echo multiple parameters instead of string concatenation:</p>
<p>&lt;?php<br />
echo &#8216;This &#8216;, &#8216;is &#8216;, $faster;<br />
echo &#8216;Tish &#8216; . &#8216;is &#8216; . $slower;<br />
?&gt;</p>
<p>5. Where it is possible use ++$i, instead of $i++.</p>
<p>&lt;!&#8211;adsense&#8211;&gt;</p>
<p>6. Regex could consume a lot of time, so think twice about each regex in your code.</p>
<p>7. It&#8217;s a good practice to profile your code. The profiler will show you, which parts of your code how much time consume. The Xdebug debugger already contains a profiler.</p>
<p>8. Cache as much as possible. You can use memcached, it is a high-performance memory object caching system intended to speed up dynamic web apps by alleviating database load. Caching is useful because your script won&#8217;t have to be compiled on every web request.</p>
<p>&lt;!&#8211;adsense&#8211;&gt;</p>
<p>I hope you&#8217;ve found something useful in the tips above. Soon, I&#8217;ll post new post about general php best practices.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/02/23/php-best-practices-in-performance-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Best Practices in Performance &#8211; Part 2</title>
		<link>http://www.devtheweb.net/blog/2010/02/16/php-best-practices-in-performance-part-2/</link>
		<comments>http://www.devtheweb.net/blog/2010/02/16/php-best-practices-in-performance-part-2/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 08:33:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=984</guid>
		<description><![CDATA[After PHP best Practices in Performance Part 1, here&#8217;s the next post from the series: 1. You can use array_keys() within foreach() when dealing with arrays. The reson is that foreach returns a copy of the array value. Using of array_keys will avoid excessive memory consumption, ex. foreach(array_keys($array) as $ak) { $v =&#38; $array[$ak]; &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>After PHP best <a href="http://www.devtheweb.net/blog/2010/02/09/php-best-practices-in-performance/" target="_blank">Practices in Performance Part 1</a>, here&#8217;s the next post from the series:</p>
<p>1. You can use array_keys() within foreach() when dealing with arrays. The reson is that foreach returns a copy of the array value. Using of array_keys will avoid excessive memory consumption, ex.</p>
<p>foreach(array_keys($array) as $ak)<br />
{<br />
$v =&amp; $array[$ak];<br />
&#8230;<br />
}</p>
<p>2. Not everything has to be written in OOP. Often OOP is too much overhead, because each method and object call consumes a lot of memory.</p>
<p>3. Instead of implementing every data structure as a class, you can use arrays instead.</p>
<p>4. Do not split methods too much. Before doing that you can think which part of your code you will really re-use.</p>
<p>5. If you don&#8217;t need some variable, you can unset it to free memory, especially large arrays, ex.</p>
<p>// declare some variable<br />
$a = &#8216;DevTheWeb.NET is a nice site <img src='http://www.devtheweb.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8217;;</p>
<p>&#8230;</p>
<p>// after you don&#8217;t need $a<br />
// inset it to free memory<br />
unset($a);</p>
<p>6. If some method can be static, you&#8217;d better declare it as a static.</p>
<p>7. When you increment an object property (ex. $this-&gt;counter++), that operation is 3 times slower than incrementing a local variable (ex. $counter++).</p>
<p>8. Do not use sprintf() for string concatenation, you can use use the concatenation operator (ex. $full = $str1.$str2.$str3;). The reason is that the concatenation operator 2 times faster than sprintf().</p>
<p><!--adsense--></p>
<p>I hope, you&#8217;ve found something useful in the information above <img src='http://www.devtheweb.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/02/16/php-best-practices-in-performance-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Best Practices in Performance &#8211; Part 1</title>
		<link>http://www.devtheweb.net/blog/2010/02/09/php-best-practices-in-performance/</link>
		<comments>http://www.devtheweb.net/blog/2010/02/09/php-best-practices-in-performance/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 13:31:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=926</guid>
		<description><![CDATA[After PHP best practices in Security &#8211; Part 1 and Part 2, here&#8217;s the first post of the series about PHP best practices in Performance. 1. If you want to output a basic string, you&#8217;d better use single quotes, instead of double quotes. If you use a string surrounded by double quotes, it&#8217;s parsed by [...]]]></description>
			<content:encoded><![CDATA[<p>After PHP best practices in Security &#8211; <a href="http://www.devtheweb.net/blog/2010/01/26/php-best-practices-in-security-part-1/" target="_blank">Part 1</a> and <a href="http://www.devtheweb.net/blog/2010/02/02/php-best-practices-in-security-part-2/" target="_blank">Part 2</a>, here&#8217;s the first post of the series about PHP best practices in Performance.</p>
<p>1. If you want to output a basic string, you&#8217;d better use single quotes, instead of double quotes. If you use a string surrounded by double quotes, it&#8217;s parsed by the PHP interpreter for special characters and variables. So, use single-quoted strings every time it&#8217;s possible.</p>
<p>2. When it&#8217;s possible do not use global variables. The reason is that incrementing a global variable is two times slow than a local variable.</p>
<p>3. If you use full paths in requires and includes, it&#8217;ll cost less time on resolving the OS paths.</p>
<p>4. You can save time if you avoid repeating function calls in loops:</p>
<p>$str = &#8216;Imagine it is a very long string &#8230;&#8217;;<br />
for ($i = 1; $i &lt; = strlen($data); $i++) {<br />
&#8230;<br />
}</p>
<p>It&#8217;ll be faster:</p>
<p>$str = &#8216;Imagine it is a very long string &#8230;&#8217;;<br />
$strLen = strlen($data);<br />
for ($i = 1; $i &lt; = $strLen; $i++) {<br />
&#8230;<br />
}</p>
<p>5. It&#8217;s good to know that methods in derived classes run faster than methods defined in the base class.</p>
<p>6. Each object in PHP consumes a lot of memory. So, not every data structure should be implemented as a class. You can use arrays, too.</p>
<p>7. when you’re done with database statements, close your database connections.</p>
<p><!--adsense--><br />
8. PHP internal functions are faster that functions written in userland. So, before implementing a basic functionality, you&#8217;d better check if it already exists in PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/02/09/php-best-practices-in-performance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Rotating Ad Script in PHP</title>
		<link>http://www.devtheweb.net/blog/2010/02/07/simple-rotating-ad-script-in-php/</link>
		<comments>http://www.devtheweb.net/blog/2010/02/07/simple-rotating-ad-script-in-php/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 11:12:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=895</guid>
		<description><![CDATA[This weekend I sold banner ad space in one of my websites. The client wanted two banners to be rotated in same place. Here&#8217;s a simple php script how it can be done: &#60;a href=&#8221;http://advertise-site-url.com&#8221; target=&#8221;_blank&#8221;&#62; &#60;?php $variable[1] = &#8216;&#60;img src=&#8221;http://www.mysite.com/ads/banner-1.jpg&#8221; alt=&#8221;banner 1&#8243; /&#62;&#8217;; $variable[2] =&#8217;&#60;img src=&#8221;http://www.mysite.com/ads/banner-2.jpg&#8221; alt=&#8221;banner 2&#8243; /&#62;&#8217;; $adCount = count($variable); $randomAdNumber = [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I sold banner ad space in one of my websites. The client wanted two banners to be rotated in same place. Here&#8217;s a simple php script how it can be done:<br />
&lt;a href=&#8221;http://advertise-site-url.com&#8221; target=&#8221;_blank&#8221;&gt;<br />
&lt;?php<br />
$variable[1] = &#8216;&lt;img src=&#8221;http://www.mysite.com/ads/banner-1.jpg&#8221; alt=&#8221;banner 1&#8243; /&gt;&#8217;;<br />
$variable[2] =&#8217;&lt;img src=&#8221;http://www.mysite.com/ads/banner-2.jpg&#8221; alt=&#8221;banner 2&#8243; /&gt;&#8217;;</p>
<p>$adCount = count($variable);<br />
$randomAdNumber = mt_rand(1, $adCount);<br />
echo $variable[$randomAdNumber];<br />
?&gt;<br />
&lt;/a&gt;</p>
<p>That&#8217;s really all. You can rotated as much as you want ads, just need to add new $variable[number] line with banner html code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/02/07/simple-rotating-ad-script-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Best Practices in Security – Part 2</title>
		<link>http://www.devtheweb.net/blog/2010/02/02/php-best-practices-in-security-part-2/</link>
		<comments>http://www.devtheweb.net/blog/2010/02/02/php-best-practices-in-security-part-2/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 08:24:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=879</guid>
		<description><![CDATA[If your web server&#8217;s access permissions are wrong, it will be easier for somebody to take control over your server. So, next 3 advices are how to fix your access rights: 1. Do not allow PHP files to be writable. 2. Do not allow executable and writeable files in your web root. 3. Do not [...]]]></description>
			<content:encoded><![CDATA[<p>If your web server&#8217;s access permissions are wrong, it will be easier for somebody to take control over your server. So, next 3 advices are how to fix your access rights:</p>
<p>1. Do not allow PHP files to be writable.</p>
<p>2. Do not allow executable and writeable files in your web root.</p>
<p>3. Do not allow external read access to files with classes, application and configuration code.</p>
<p>4. When magic_quotes is turned on, it automatically escapes incoming data to the PHP script. But it&#8217;s not a good idea to be used, because:<br />
- if you rely on it to be turned off or on, your code won&#8217;t be portable. You can use get_magic_quotes_gpc() to check for this.<br />
- it affects the performance, because not all the escaping data is inserted in database.<br />
- not all data need escaping, ex. it&#8217;s annoying to see &#8216; in email<br />
Also, magic_quotes will be removed in PHP 6.0.0.</p>
<p>5. register_globals is still used by many developers. But it may pollutes the global namespace and could overwrite not properly initialized variables. So, it should be turned off, too.  register_globals will be removed in PHP 6.0.0.</p>
<p>6. Cookies could easily be modified by users or could be faked very easily by automated scripts, so you&#8217;d better do not store important information in cookies.</p>
<p>I hope you&#8217;ve found something useful in the advices above. You can check out also <a href="http://www.devtheweb.net/blog/2010/01/26/php-best-practices-in-security-part-1/" target="_blank">PHP Best Practices in Security – Part 1</a>.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 33px; width: 1px; height: 1px;"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:SplitPgBreakAndParaMark /> <w:DontVertAlignCellWithSp /> <w:DontBreakConstrainedForcedTables /> <w:DontVertAlignInTxbx /> <w:Word11KerningPairs /> <w:CachedColBalance /> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math" /> <m:brkBin m:val="before" /> <m:brkBinSub m:val=" " /> <m:smallFrac m:val="off" /> <m:dispDef /> <m:lMargin m:val="0" /> <m:rMargin m:val="0" /> <m:defJc m:val="centerGroup" /> <m:wrapIndent m:val="1440" /> <m:intLim m:val="subSup" /> <m:naryLim m:val="undOvr" /> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"   DefSemiHidden="true" DefQFormat="false" DefPriority="99"   LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Normal" /> <w:LsdException Locked="false" Priority="9" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="heading 1" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9" /> <w:LsdException Locked="false" Priority="39" Name="toc 1" /> <w:LsdException Locked="false" Priority="39" Name="toc 2" /> <w:LsdException Locked="false" Priority="39" Name="toc 3" /> <w:LsdException Locked="false" Priority="39" Name="toc 4" /> <w:LsdException Locked="false" Priority="39" Name="toc 5" /> <w:LsdException Locked="false" Priority="39" Name="toc 6" /> <w:LsdException Locked="false" Priority="39" Name="toc 7" /> <w:LsdException Locked="false" Priority="39" Name="toc 8" /> <w:LsdException Locked="false" Priority="39" Name="toc 9" /> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption" /> <w:LsdException Locked="false" Priority="10" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Title" /> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font" /> <w:LsdException Locked="false" Priority="11" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtitle" /> <w:LsdException Locked="false" Priority="22" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Strong" /> <w:LsdException Locked="false" Priority="20" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Emphasis" /> <w:LsdException Locked="false" Priority="59" SemiHidden="false"    UnhideWhenUsed="false" Name="Table Grid" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text" /> <w:LsdException Locked="false" Priority="1" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="No Spacing" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 1" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 1" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 1" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 1" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision" /> <w:LsdException Locked="false" Priority="34" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="List Paragraph" /> <w:LsdException Locked="false" Priority="29" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Quote" /> <w:LsdException Locked="false" Priority="30" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Quote" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 1" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 1" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 1" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 1" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 1" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 2" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 2" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 2" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 2" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 2" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 2" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 2" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 2" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 3" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 3" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 3" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 3" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 3" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 3" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 3" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 3" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 3" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 4" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 4" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 4" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 4" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 4" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 4" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 4" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 4" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 4" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 5" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 5" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 5" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 5" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 5" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 5" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 5" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 5" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 5" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 6" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 6" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 6" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 6" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 6" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 6" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 6" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 6" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 6" /> <w:LsdException Locked="false" Priority="19" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis" /> <w:LsdException Locked="false" Priority="21" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis" /> <w:LsdException Locked="false" Priority="31" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference" /> <w:LsdException Locked="false" Priority="32" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Reference" /> <w:LsdException Locked="false" Priority="33" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Book Title" /> <w:LsdException Locked="false" Priority="37" Name="Bibliography" /> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading" /> </w:LatentStyles> </xml><![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Wingdings; 	panose-1:5 0 0 0 0 0 0 0 0 0; 	mso-font-charset:2; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-520092929 1073786111 9 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi;} .MsoPapDefault 	{mso-style-type:export-only; 	margin-bottom:10.0pt; 	line-height:115%;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}  /* List Definitions */  @list l0 	{mso-list-id:692459888; 	mso-list-template-ids:215496558;} @list l0:level1 	{mso-level-number-format:bullet; 	mso-level-text:?; 	mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in; 	mso-ansi-font-size:10.0pt; 	font-family:Symbol;} @list l1 	{mso-list-id:1606114624; 	mso-list-template-ids:1019898224;} @list l1:level1 	{mso-level-number-format:bullet; 	mso-level-text:?; 	mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in; 	mso-ansi-font-size:10.0pt; 	font-family:Symbol;} ol 	{margin-bottom:0in;} ul 	{margin-bottom:0in;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin-top:0in; 	mso-para-margin-right:0in; 	mso-para-margin-bottom:10.0pt; 	mso-para-margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi;} --> <!--[endif]--></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">The issue: register_globals is still used in many applications and even for developing</span></p>
<ul type="disc">
<li class="MsoNormal" style="line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">Pollutes the global namespace.</span></li>
<li class="MsoNormal" style="line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">Can overwrite not properly initialized variables.</span></li>
</ul>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">The solution: Turn off register_globals in development and production environments.</span></p>
<ul type="disc">
<li class="MsoNormal" style="line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">Workarounds could overwrite global variables before PHP      4.4.1 and PHP 5.0.5</span></li>
<li class="MsoNormal" style="line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">Still possible with own importing mechanisms.</span></li>
<li class="MsoNormal" style="line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">Fixed in extract() and import_request_variables().</span></li>
</ul>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 12pt; font-family: &amp;amp;amp;">register_globals and magic_quotes will be removen in PHP 6</span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/02/02/php-best-practices-in-security-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things You Probably Didn’t Know About PHP &#8211; Part 1</title>
		<link>http://www.devtheweb.net/blog/2010/01/12/things-you-probably-didnt-know-about-php/</link>
		<comments>http://www.devtheweb.net/blog/2010/01/12/things-you-probably-didnt-know-about-php/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 09:39:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.devtheweb.net/blog/?p=531</guid>
		<description><![CDATA[I&#8217;ve spend some time reading about cool things in PHP. I found some interesting functions and tricks. Here&#8217;s the list: 1. You can compress/decompress long strings before storing them in a database. It can be done very easy using the built-in functions: gzcompress() and gzuncompress(). They use gzip algorithm and could compress a string up [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spend some time reading about cool things in PHP. I found some interesting functions and tricks. Here&#8217;s the list:</p>
<p>1. You can compress/decompress long strings before storing them in a database. It can be done very easy using the built-in functions: gzcompress() and gzuncompress(). They use gzip algorithm and could compress a string up to 90%.</p>
<p>2. You can check if a email is valid by the checkdnsrr() function. It checks the email&#8217;s host address if it&#8217;s a valid DNS record.</p>
<p>For ex. tihomir@devtheweb12782.com is semantically a valid e-mail, but devtheweb12782.com is not a valid host. That&#8217;s why checkdnsrr() will return false.</p>
<p>3. Output formatted PHP code, you can do it by using the highlight_file() function. This function will return a HTML formatted string with nicely colored PHP inside it.</p>
<p>4. You don&#8217;t need to store IP addresses as strings.</p>
<div style="float: left; margin-right: 5px;"><!--adsense--></div>
<p>They can be stored as integers using the ip2long(). The integer converted IP addresses can be converted again to string using the long2ip() function. Storing IP address as integers has some advantages:</p>
<ul>
<li>reduce storage space &#8211; 4 bytes instead of 15 characters (15 bytes)</li>
<li>searching by IP address will be faster</li>
<li>easiest to check if IP address falls within IP ranges</li>
</ul>
<p>5. Easily unpack numeric arrays using the well-know function &#8230; list <img src='http://www.devtheweb.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Look at following code for swapping two variables&#8217; values:</p>
<p>$a = &#8216;value 1&#8242;;<br />
$b = &#8216;value 2&#8242;;</p>
<p>list($a, $b) = array($b, $a);</p>
<p>echo $a; // it will output value 2<br />
echo $b; // it will output value 1</p>
<p>Have you ever seen better code for swapping two variables&#8217; values !?</p>
<p>6. You can use composition of variables. I don&#8217;t how it can be useful, but the following code is valid:</p>
<p>${&#8216;a&#8217; . &#8216;b&#8217;} = &#8216;c&#8217;;<br />
echo $ab; // it will output c</p>
<p>7. You can handle the situation when a class that doesn&#8217;t exist is instantiated &#8211; just need to implement the __autoload function. This function is called transparently by PHP when a class that doesn&#8217;t exist is instantiated.</p>
<p>8. Split string to array of strings using preg_split function. It can be done using the explode function. But using preg_split function, the empty strings will be eliminated:</p>
<p>$str = &#8220;a,b,,c,,d,,e&#8221;;<br />
$strArr = preg_split(&#8220;~,~&#8221;, $str, -1, PREG_SPLIT_NO_EMPTY); // it will returns array(&#8216;a&#8217;,'b&#8217;,'c&#8217;,'d&#8217;, &#8216;e&#8217;)</p>
<p>I hope you&#8217;ve found something useful in the examples above <img src='http://www.devtheweb.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>P.S. You can check out also: <a href="http://www.devtheweb.net/blog/2010/01/19/things-you-probably-didnt-know-about-php-part-2/" target="_blank">Things You Probably Didn’t Know About PHP – Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtheweb.net/blog/2010/01/12/things-you-probably-didnt-know-about-php/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

