<?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>Noupe &#187; PHP</title>
	<atom:link href="http://www.noupe.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.noupe.com</link>
	<description>The Curious Side of Smashing Magazine</description>
	<lastBuildDate>Fri, 10 Feb 2012 20:55:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Getting Started with PHP Regular Expressions</title>
		<link>http://www.noupe.com/php/php-regular-expressions.html</link>
		<comments>http://www.noupe.com/php/php-regular-expressions.html#comments</comments>
		<pubDate>Mon, 24 Aug 2009 01:01:42 +0000</pubDate>
		<dc:creator>Editorial</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.noupe.com/?p=21096</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=3" border="0" alt="" /></a>
    </div></td></tr></table>
&nbsp;&nbsp; 1. What are Regular Expressions The main purpose of regular expressions, also called regex or regexp, is to efficiently search for patterns in a given text. These search patterns are written using a special format which a regular expression parser understands. Regular expressions are originating from Unix systems, where a program was designed, called [...]]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<h3 class="title">1. What are Regular Expressions</h3>
<p><strong>The main purpose of regular expressions, also called regex or regexp, is to efficiently search for patterns in a given text</strong>. These search patterns are written using a special format which a regular expression parser understands.</p>
<p><span id="more-21096"></span></p>
<p class="showcase"><img src="http://noupe.com/img/express-1.gif" alt=""/></p>
<p>Regular expressions are originating from Unix systems, where a program was designed, called grep, to help users work with strings and manipulate text. <strong>By following a few basic rules, one can create very complex search patterns.</strong></p>
<p>As an example, let&#8217;s say you&#8217;re given the task to check wether an e-mail or a telephone number has the correct form. Using a few simple commands these problems can easily be solved thanks to regular expressions. The syntax doesn&#8217;t always seems straightforward at first, but once you learn it, you&#8217;ll realize that you can do pretty complex searches easily, just by typing in a few characters and you&#8217;ll approach problems from a different perspective.</p>
<h3 class="title">2. Perl Compatible Regular Expressions</h3>
<p>PHP has implemented quite a few <em>regex</em> functions which uses different parsing engines. There are two major parser in PHP. One called <strong>POSIX</strong> and the other <strong>PCRE</strong> or Perl Compatible Regular Expression.</p>
<p>The PHP <a href="http://www.php.net/manual/en/ref.regex.php" title="php.net/manual/en/ref.regex.php">function prefix</a> for POSIX is <em>ereg_</em>. <strong>Since the release of PHP 5.3 this engine is deprecated</strong>, but let&#8217;s have a look at the more optimal and faster PCRE engine.</p>
<p>In PHP every PCRE function starts with <em>preg_</em> such as <a href="http://www.php.net/manual/en/function.preg-match.php" title="php.net/manual/en/function.preg-match.php">preg_match</a> or <a href="http://www.php.net/manual/en/function.preg-replace.php" title="php.net/manual/en/function.preg-replace.php">preg_replace</a>. You can read the full function list in <a href="http://www.php.net/manual/en/ref.pcre.php" title="php.net/manual/en/ref.pcre.php">PHP&#8217;s documentation</a>.</p>
<h3 class="title">3. Basic Syntax</h3>
<p>To use regular expressions first you need to learn the syntax. This syntax consists in a series of letters, numbers, dots, hyphens and special signs, which we can group together using different parentheses.</p>
<p>In PHP every regular expression pattern is defined as a string using the Perl format. In Perl, a regular expression pattern is written between forward slashes, such as <em>/hello/</em>. In PHP this will become a string, <em>&#8216;/hello/&#8217;</em>.</p>
<p>Now, <strong>let&#8217;s have a look at some operators, the basic building blocks of regular expressions</strong></p>
<table>
<tbody>
<tr>
<th>Operator</th>
<th>Description</th>
</tr>
<tr>
<td>^</td>
<td>The circumflex symbol marks the beginning of a pattern, although in some cases it can be omitted</td>
</tr>
<tr>
<td>$</td>
<td>Same as with the circumflex symbol, the dollar sign marks the end of a search pattern</td>
</tr>
<tr>
<td>.</td>
<td>The period matches any single character</td>
</tr>
<tr>
<td>?</td>
<td>It will match the preceding pattern zero or one times</td>
</tr>
<tr>
<td>+</td>
<td>It will match the preceding pattern one or more times</td>
</tr>
<tr>
<td>*</td>
<td>It will match the preceding pattern zero or more times</td>
</tr>
<tr>
<td>|</td>
<td>Boolean <em>OR</em></td>
</tr>
<tr>
<td>-</td>
<td>Matches a range of elements</td>
</tr>
<tr>
<td>()</td>
<td>Groups a different pattern elements together</td>
</tr>
<tr>
<td>[]</td>
<td>Matches any single character between the square brackets</td>
</tr>
<tr>
<td>{min, max}</td>
<td>It is used to match exact character counts</td>
</tr>
<tr>
<td>\d</td>
<td>Matches any single digit</td>
</tr>
<tr>
<td>\D</td>
<td>Matches any single non digit caharcter</td>
</tr>
<tr>
<td>\w</td>
<td>Matches any alpha numeric character including underscore (_)</td>
</tr>
<tr>
<td>\W</td>
<td>Matches any non alpha numeric character excluding the underscore character</td>
</tr>
<tr>
<td>\s</td>
<td>Matches whitespace character</td>
</tr>
</tbody>
</table>
<p>As an addition in PHP the forward slash character is escaped using the simple slash <em><strong>\</strong></em>. Example: <em><strong>&#8216;/he\/llo/&#8217;</strong></em></p>
<p><strong>To have a brief understanding how these operators are used, let&#8217;s have a look at a few examples:</strong></p>
<table>
<tbody>
<tr>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td>&#8216;/hello/&#8217;</td>
<td>It will match the word <em>hello</em></td>
</tr>
<tr>
<td>&#8216;/^hello/&#8217;</td>
<td>It will match <em>hello</em> at the start of a string. Possible matches are <em>hello</em> or <em>helloworld</em>, but not <em>worldhello</em></td>
</tr>
<tr>
<td>&#8216;/hello$/&#8217;</td>
<td>It will match <em>hello</em> at the end of a string.</td>
</tr>
<tr>
<td>&#8216;/he.o/&#8217;</td>
<td>It will match any character between <em>he</em> and <em>o</em>. Possible matches are <em>helo</em> or <em>heyo</em>, but not <em>hello</em></td>
</tr>
<tr>
<td>&#8216;/he?llo/&#8217;</td>
<td>It will match either <em>llo</em> or <em>hello</em></td>
</tr>
<tr>
<td>&#8216;/hello+/&#8217;</td>
<td>It will match <em>hello</em> on or more time. E.g. <em>hello</em> or <em>hellohello</em></td>
</tr>
<tr>
<td>&#8216;/he*llo/&#8217;</td>
<td>Matches <em>llo</em>, <em>hello</em> or <em>hehello</em>, but not <em>hellooo</em></td>
</tr>
<tr>
<td>&#8216;/hello|world/&#8217;</td>
<td>It will either match the word <em>hello</em> or <em>world</em></td>
</tr>
<tr>
<td>&#8216;/(A-Z)/&#8217;</td>
<td>Using it with the hyphen character, this pattern will match every uppercase character from A to Z. E.g. A, B, C&#8230;</td>
</tr>
<tr>
<td>&#8216;/[abc]/&#8217;</td>
<td>It will match any single character <em>a</em>, <em>b</em> or <em>c</em></td>
</tr>
<tr>
<td>&#8216;/abc{1}/&#8217;</td>
<td>Matches precisely one <em>c</em> character after the characters <em>ab</em>. E.g. matches <em>abc</em>, but not <em>abcc</em></td>
</tr>
<tr>
<td>&#8216;/abc{1,}/&#8217;</td>
<td>Matches one or more <em>c</em> character after the characters <em>ab</em>. E.g. matches <em>abc</em> or <em>abcc</em></td>
</tr>
<tr>
<td>&#8216;/abc{2,4}/&#8217;</td>
<td>Matches between two and four <em>c</em> character after the characters <em>ab</em>. E.g. matches <em>abcc</em>, <em>abccc</em> or <em>abcccc</em>, but not <em>abc</em></td>
</tr>
</tbody>
</table>
<p>Besides operators, there are <strong>regular expression modifiers</strong>, which can globally alter the behavior of search patterns.</p>
<p>The <em>regex</em> modifiers are placed after the pattern, like this <em><strong>&#8216;/hello/i&#8217;</strong></em> and they consists of single letters such as <em>i</em> which marks a pattern case insensitive or <em>x</em> which ignores white-space characters. For a full list of modifiers please visit <a href="http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php" title="php.net/manual/en/reference.pcre.pattern.modifiers.php">PHP&#8217;s online documentation</a>.</p>
<p>The real power of regular expressions relies in combining these operators and modifiers, therefore creating rather complex search patterns.</p>
<h3 class="title">4. Using Regex in PHP</h3>
<p class="showcase"><img src="http://noupe.com/img/express-2.gif" alt=""/></p>
<p>In PHP we have a total of nine PCRE functions which we can use. Here&#8217;s the list:</p>
<ul class="post">
<li><a href="http://www.php.net/manual/en/function.preg-filter.php">preg_filter</a> &#8211; performs a regular expression search and replace</li>
<li><a href="http://www.php.net/manual/en/function.preg-grep.php">preg_grep</a> &#8211; returns array entries that match a pattern</li>
<li><a href="http://www.php.net/manual/en/function.preg-last-error.php">preg_last_error</a> &#8211; returns the error code of the last PCRE regex execution</li>
<li><a href="http://www.php.net/manual/en/function.preg-match.php">preg_match</a> &#8211; perform a regular expression match</li>
<li><a href="http://www.php.net/manual/en/function.preg-match-all.php">preg_match_all</a> &#8211; perform a global regular expression match</li>
<li><a href="http://www.php.net/manual/en/function.preg-quote.php">preg_quote</a> &#8211; quote regular expression characters</li>
<li><a href="http://www.php.net/manual/en/function.preg-replace.php">preg_replace</a> &#8211; perform a regular expression search and replace</li>
<li><a href="http://www.php.net/manual/en/function.preg-replace-callback.php">preg_replace_callback</a> &#8211; perform a regular expression search and replace using a callback</li>
<li><a href="http://www.php.net/manual/en/function.preg-split.php">preg_split</a> &#8211; split string by a regular expression</li>
</ul>
<p><strong>The two most commonly used functions are <em>preg_match</em> and <em>preg_replace</em>.</strong></p>
<p>Let&#8217;s begin by creating a test string on which we will perform our regular expression searches. The classical <em>hello world</em> should do it.</p>
<pre class="php" name="code">$test_string = 'hello world';</pre>
<p>If we simply want to search for the word <em>hello</em> or <em>world</em> then the search pattern would look something like this:</p>
<pre name="code" class="php">
preg_match('/hello/', $test_string);
preg_match('/world/', $test_string);
</pre>
<p>If we wish to see if the string begins with the word <em>hello</em>, we would simply put the ^ character in the beginning of the search pattern like this:</p>
<pre class="php" name="code">preg_match('/^hello/', $test_string);
</pre>
<p>Please note that <strong>regular expressions are case sensitive</strong>, the above pattern won&#8217;t match the word <em>hElLo</em>. If we want our pattern to be <strong>case insensitive</strong> we should apply the following modifier:</p>
<pre class="php" name="code">preg_match('/^hello/i', $test_string);
</pre>
<p>Notice the character <em>i</em> at the end of the pattern <strong>after the forward slash</strong>.</p>
<p>Now let&#8217;s examine a more complex search pattern. What if we want to check that the first five characters in the string are alpha numeric characters.</p>
<pre class="php" name="code">preg_match('/^[A-Za-z0-9]{5}/', $test_string);
</pre>
<p>Let&#8217;s dissect this search pattern. First, by using the caret character (^) we specify that the string must begin with an alpha numeric character. This is specified by <em>[A-Za-z0-9]</em>.</p>
<p><em>A-Z</em> means all the characters from A to Z followed by <em>a-z</em> which is the same except for lowercase character, this is important, because regular expressions are case sensitive. I think you&#8217;ll figure out by yourself what <em>0-9</em> means.</p>
<p><em>{5}</em> simply tells the <em>regex</em> parser to count exactly five characters. If we put six instead of five, the parser wouldn&#8217;t match anything, because in our test string the word <em>hello</em> is five characters long, followed by a white-space character which in our case doesn&#8217;t count.</p>
<p>Also, this regular expression could be optimized to the following form:</p>
<pre class="php" name="code">preg_match('/^\w{5}/', $test_string);
</pre>
<p><em>\w</em> specifies any alpha numeric characters plus the underscore character (_).</p>
<h1>6. Useful Regex Functions</h1>
<p>Here are a few PHP functions using regular expressions which you could use on a daily basis.</p>
<p><strong>Validate e-mail</strong>. This function will validate a given e-mail address string to see if it has the correct form.</p>
<pre class="php" name="code">function validate_email($email_address)
{
    if( !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+
                     ([a-zA-Z0-9\._-]+)+$/", $email_address))
    {
        return false;
    }
    return true;
}
</pre>
<p><strong>Validate a URL</strong></p>
<pre class="php" name="code">function validate_url($url)
{
    return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?
                      (/.*)?$|i', $url);
}
</pre>
<p><strong>Remove repeated words</strong>. I often found repeated words in a text, such as <em>this this</em>. This handy function will remove such duplicate words.</p>
<pre class="php" name="code">function remove_duplicate_word($text)
{
    return preg_replace("/s(w+s)1/i", "$1", $text);
}
</pre>
<p><strong>Validate alpha numeric, dashes, underscores and spaces</strong></p>
<pre class="php" name="code">function validate_alpha($text)
{
    return preg_match("/^[A-Za-z0-9_- ]+$/", $text);
}
</pre>
<p><strong>Validate US ZIP codes</strong></p>
<pre class="php" name="code">function validate_zip($zip_code)
{
    return preg_match("/^([0-9]{5})(-[0-9]{4})?$/i",$zip_code);
}
</pre>
<h3 class="title">7. Regex Cheat Sheet</h3>
<p>Because cheat sheets are cool nowadays, below you can find a PCRE cheat sheet that you can run through quickly anytime you forget something.</p>
<h3>Meta Characters</h3>
<table border="0" cellpadding="2" cellspacing="2">
<col class="symbol">
<col>
<tbody>
<tr>
<th>&nbsp;</th>
<th>Description</th>
</tr>
<tr>
<td>^</td>
<td>Marks the start of a string</td>
</tr>
<tr>
<td>$</td>
<td>Marks the end of a string</td>
</tr>
<tr>
<td>.</td>
<td>Matches any single character</td>
</tr>
<tr>
<td>|</td>
<td>Boolean OR</td>
</tr>
<tr>
<td>()</td>
<td>Group elements</td>
</tr>
<tr>
<td>[abc]</td>
<td>Item in range (a,b or c)</td>
</tr>
<tr>
<td>[^abc]</td>
<td>NOT in range (every character except a,b or c)</td>
</tr>
<tr>
<td>\s</td>
<td>White-space character</td>
</tr>
<tr>
<td>a?</td>
<td>Zero or one b characters. Equals to a{0,1}</td>
</tr>
<tr>
<td>a*</td>
<td>Zero or more of a</td>
</tr>
<tr>
<td>a+</td>
<td>One or more of a</td>
</tr>
<tr>
<td>a{2}</td>
<td>Exactly two of a</td>
</tr>
<tr>
<td>a{,5}</td>
<td>Up to five of a</td>
</tr>
<tr>
<td>a{5,10}</td>
<td>Between five to ten of a</td>
</tr>
<tr>
<td>\w</td>
<td>Any alpha numeric character plus underscore. Equals to [A-Za-z0-9_]</td>
</tr>
<tr>
<td>\W</td>
<td>Any non alpha numeric characters</td>
</tr>
<tr>
<td>\s</td>
<td>Any white-space character</td>
</tr>
<tr>
<td>\S</td>
<td>Any non white-space character</td>
</tr>
<tr>
<td>\d</td>
<td>Any digits. Equals to [0-9]</td>
</tr>
<tr>
<td>\D</td>
<td>Any non digits. Equals to [^0-9]</td>
</tr>
</tbody>
</table>
<h3>Pattern Modifiers</h3>
<table border="0" cellpadding="2" cellspacing="2">
<col class="symbol">
<col>
<tbody>
<tr>
<th>&nbsp;</th>
<th>Description</th>
</tr>
<tr>
<td>i</td>
<td>Ignore case</td>
</tr>
<tr>
<td>m</td>
<td>Multiline mode</td>
</tr>
<tr>
<td>S</td>
<td>Extra analysis of pattern</td>
</tr>
<tr>
<td>u</td>
<td>Pattern is treated as UTF-8</td>
</tr>
</tbody>
</table>
<h3 class="title">8. Useful Readings</h3>
<ul class="post">
<li><a href="http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers">15 PHP Regular Expression for Web Developers</a></li>
<li><a href="http://www.ibm.com/developerworks/opensource/library/os-php-regex1/index.html">Mastering Regular Expressions in PHP</a></li>
<li><a href="http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html">Introduction to PHP Regex</a></li>
</ul>
<div class="author-box">
<div class="author-text">
<h4><strong>Author</strong>: Joel Reyes</h4>
<p>Joel Reyes Has been designing and coding web sites for several years, this has lead him to be the creative mind behind Looney Designer a design resource and portfolio site that revolves around web and graphic design.</p>
</p></div>
<div class="write-for-us"><strong class="red">Write for Us!</strong> We are looking for exciting and creative articles, if you want to contribute, just send us an <a href="mailto:info@noupe.com">email</a>.</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.noupe.com/php/php-regular-expressions.html/feed</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>10+ Mod_Rewrite Rules You Should Know</title>
		<link>http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html</link>
		<comments>http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html#comments</comments>
		<pubDate>Tue, 18 Aug 2009 07:55:41 +0000</pubDate>
		<dc:creator>Editorial</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.noupe.com/?p=20451</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=3" border="0" alt="" /></a>
    </div></td></tr></table>
&nbsp;&nbsp; Mod_rewrite is an Apache-based rewrite engine for dynamically rewriting URLs. It&#8217;s built into Apache servers natively, though not enabled by default. It&#8217;s capable of functions beyond simple rewrites, though, some of which are included below. Turn Mod_Rewrite On Mod_rewrite is used through your .htaccess file. Place the following code at the beginning of your [...]]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<p>Mod_rewrite is an Apache-based rewrite engine for dynamically rewriting URLs. It&#8217;s built into Apache servers natively, though not enabled by default. </p>
<p>It&#8217;s capable of functions beyond simple rewrites, though, some of which are included below.</p>
<p><span id="more-20451"></span></p>
<hr/>
<p class="img"><img src="http://noupe.com/img/modrewrite-image1.jpg" width="500" height="325" alt="Mod_Rewrite Rules You Should Know"/></p>
<h3 class="title">Turn Mod_Rewrite On</h3>
<p>Mod_rewrite is used through your .htaccess file. Place the following code at the beginning of your .htaccess file to turn mod_rewrite on:</p>
<pre name="code" class="php">
RewriteEngine on
</pre>
<p>(Don&#8217;t forget that .htaccess commands are case-sensitive.) This code needs to be entered at the beginning of any .htaccess file using mod_rewrite.</p>
<h3 class="title">The Basic Mod_Rewrite Layout</h3>
<p>The basic format for a mod_rewrite command is:</p>
<pre name="code" class="php">
RewriteRule Pattern Substitution [Flag(s)]
</pre>
<h3 class="title">URLs are Always Relative</h3>
<p>The URL you redirect to is always relative to the directory in which your .htaccess file is placed. So if it&#8217;s in the root directory, URLs are all in relation to the root directory; if it&#8217;s in a sudirectory, URLs are in relation to that particular subdirectory.</p>
<h3 class="title">A Basic Redirect</h3>
<p>If you just want to create a simple 301 redirect from one URL to another, then use the following code:</p>
<pre name="code" class="php">
RewriteRule ^fileone.html$ filetwo.html
</pre>
<p>This is a very basic rule that means any requests for fileone.html will be sent to filetwo.html.</p>
<h3 class="title">Require no &#8220;www&#8221;</h3>
<p>This bit of code will make it so visitors to your site don&#8217;t need to type in the &#8220;www&#8221; bit of your website address.</p>
<pre name="code" class="php">
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
</pre>
<h3 class="title">Block a Specific IP Address</h3>
<p>If you want to block someone coming from a specific IP address from accessing your website, you can use the following code:</p>
<pre name="code" class="php">
RewriteCond %{REMOTE_ADDR} ^(A\.B\.C\.D)$
RewriteRule ^/* http://www.domain.com/sorry.html [L]
</pre>
<p>Replace the A\.B\.C\.D with the IP address you want to block (don&#8217;t forget to leave the &#8220;\&#8221; before each dot, which escapes the character). </p>
<h3 class="title">Block Specific User Agents</h3>
<p>If you want to block a group of IP addresses using the same User Agent (bot), the following code with do it:</p>
<pre name="code" class="php">
RewriteCond %{HTTP_USER_AGENT} UserAgent
RewriteRule .* - [F,L]
</pre>
<p>Just replace the &#8220;UserAgent&#8221; bit with whatever user agent you want to block. You can also block more than one at a time by replacing the top line in that code with something like this:</p>
<pre name="code" class="php">
RewriteCond %{HTTP_USER_AGENT} UserAgentA [OR]
RewriteCond %{HTTP_USER_AGENT} UserAgentB
</pre>
<p>You can put as many user agents in as you want, just make sure you end each line with [OR] (with the exception of the last line, of course).</p>
<p class="img"><img src="http://noupe.com/img/modrewrite-image2.jpg" width="500" height="375" /></p>
<h3 class="title">Strip Query Strings</h3>
<p>Let&#8217;s say all the pages on your site other than your home page are formatted as follows, with query strings instead of page names:</p>
<p>http://www.domain.com/home.html?example=12345abcd</p>
<p>Those aren&#8217;t very pretty, and on top of that, search engines will show a bunch of duplicated &#8220;home&#8221; pages. If you want to get rid of the query string in your page URLs, use the following code:</p>
<pre name="code" class="php">
RewriteCond %{QUERY_STRING} example=
RewriteRule (.*) http://www.domain.com/$1? [R=301]
</pre>
<p>This not only gets rid of the query string, but also the preceding question mark.</p>
<h3 class="title">Set up a Default Image</h3>
<p>Using a default, backup image in case of broken images can make your site look more professional. Use the following code to redirect to a default image for any image whose file cannot be found.</p>
<pre name="code" class="php">
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^images/.*\.jpg$ /images/default.jpg [L]
</pre>
<p>Of course, you can change the &#8220;.jpg&#8221; bit to whatever file type you&#8217;re using. Make sure you have an image called &#8220;default.jpg&#8221; or change that to whatever your default image filename is.</p>
<h3 class="title">Prevent Hotlinking</h3>
<p>The last thing most website owners want is other sites stealing their content or worse—hotlinking to their images and stealing their bandwidth. Here&#8217;s a simple bit of code that prevents it:</p>
<pre name="code" class="php">
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/ .*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
</pre>
<p>Make sure you change the &#8220;domain.com&#8221; bit to your own domain name.</p>
<h3 class="title">Redirect to a Maintenance Page</h3>
<p>If you need to take your entire site offline for a bit and redirect to a maintenance page (or some other page), use the following code:</p>
<pre name="code" class="php">
RedirectMatch 302 ^/ /maintenancepage.html
</pre>
<p>Change the &#8220;maintenancepage.html&#8221; bit to wherever your maintenance page file is located.</p>
<h3 class="title">Redirect Multiple Domains to a Single Domain</h3>
<p>If you have multiple domains pointing to your site, it&#8217;s possible you could take a hit in the search engines for having duplicate content. Use the following code to redirect visitors from two domains to just one:</p>
<pre name="code" class="php">
RewriteCond %{HTTP_HOST} ^www.domain.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domain.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.net$ [NC]
RewriteRule ^(.*)$ http://domain.net/$1 [R=301,L]
</pre>
<h3 class="title">Remember the Filesystem Always Takes Precedence</h3>
<p>The filesystem on your server will always take precedence over the rewritten URL. For example, if you have a directory named &#8220;services&#8221; and within that directory is a file called &#8220;design.html&#8221;, you can&#8217;t have the URL redirect to &#8220;http://domain.com/services&#8221;. What happens is that Apache goes into the &#8220;services&#8221; directory and doesn&#8217;t see the rewrite instructions. </p>
<p>To fix this, simply rename your directory (adding an underscore to the beginning or end is a simple way to do that).</p>
<h3 class="title">Remember:</h3>
<ul>
<li>Because mod_rewrite works within the .htaccess file, commands are case sensitive.</li>
<li>Always back up your .htaccess file before making any changes to it. This way, if there&#8217;s a problem, you can easily restore your site.</li>
</ul>
<h3 class="title">More Resources:</h3>
<ul class="post">
<li><a href="http://www.modrewrite.com/" target="_blank">Modrewrite.com</a> &#8211; This is a great site that offers a forum, a beginner&#8217;s guide, and links to more information about mod_rewrite.</li>
<li><a href="http://spellbook.infinitiv.it/2006/09/25/mod_rewrite-tips-and-tricks.htm" target="_blank">Mod_Rewrite Tips and Tricks</a> &#8211; A great article on the basics of mod_rewrite and some beginner and advanced techniques.</li>
<li><a href="http://www.modrewrite.co.uk/" target="_blank">Mod Rewrite Tips and Tricks</a> &#8211; This site offers a few basic tips for mod_rewrite.</li>
<li><a href="http://www.justinshattuck.com/2007/01/19/apache-mod_rewrite-cheat-sheet/" target="_blank">Apache Mod_Rewrite Cheat Sheet</a> &#8211; This cheat sheet offers information on the most-used items for building a mod_rewrite pattern.</li>
<li><a href="http://www.sitepoint.com/article/apache-mod_rewrite-examples/" target="_blank">Learn Apache mod_rewrite: 13 Real-World Examples</a> &#8211; This is a much more advanced article from SitePoint.</li>
<li><a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html" target="_blank">Module mod_rewrite URL Rewriting Engine</a> &#8211; The official documentation from Apache.</li>
<li><a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" target="_blank">.htaccess Rewrite Tips for Using RewriteRule and RewriteCond for .htaccess mod_rewrite</a> &#8211; A great guide to a number of different mod_rewrite patterns.</li>
<li><a href="http://www.xinsight.ca/blog/tips-for-configuring-apaches-mod_rewrite/" target="_blank">Tip for Configuring Apache&#8217;s Mod_Rewrite</a> &#8211; Five great tips for mod_rewrite configuration.</li>
<li><a href="http://phpstarter.net/2008/07/several-htaccess-mod_rewrite-tricks-to-better-web-application/">Several Mod_Rewrite Tricks for a Better Web Application</a> &#8211; Covers a number of basic and more advanced mod_rewrite tricks.</li>
</ul>
<div class="author-box">
<div class="author-text">
<img height="80" width="80" class="author-photo" src="http://media.noupe.com//uploads/2009/05/cameronchapman-80x80.png" alt=""/>   </p>
<h4><strong>Author</strong>: <a href="http://cameronchapman.com">Cameron Chapman</a></h4>
<p>Cameron Chapman is a writer, blogger, copyeditor, and social media addict. She&#8217;s been designing for more than six years and writing her whole life. If you’d like to connect with her, you can follow her on <a href="http://twitter.com/cameron_chapman">Twitter</a> or at her <a href="http://cameronchapman.com/">Personal Website</a>.</p>
</p></div>
<div class="write-for-us"><strong class="red">Write for Us!</strong> We are looking for exciting and creative articles, if you want to contribute, just send us an <a href="mailto:info@noupe.com">email</a>.</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html/feed</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>Discussing PHP Frameworks: What, When, Why and  Which?</title>
		<link>http://www.noupe.com/php/discussing-php-frameworks.html</link>
		<comments>http://www.noupe.com/php/discussing-php-frameworks.html#comments</comments>
		<pubDate>Sat, 25 Jul 2009 21:01:26 +0000</pubDate>
		<dc:creator>Editorial</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.noupe.com/?p=17784</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=3" border="0" alt="" /></a>
    </div></td></tr></table>
&nbsp;&nbsp; What is a PHP Framework? PHP is the world’s most popular scripting language for many different reasons – flexibility, ease-of-use, among others – but often times coding in PHP, or any language for that matter, can get rather monotonous and repetitive. That’s where a PHP framework can help. PHP frameworks streamline the the development [...]]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<h3 class="title">What is a PHP Framework?</h3>
<p>PHP is the world’s most popular scripting language for many different reasons – flexibility, ease-of-use, among others – but often times coding in PHP, or any language for that matter, can get rather monotonous and repetitive. That’s where a PHP framework can help.</p>
<p><span id="more-17784"></span></p>
<p>PHP frameworks streamline the the development of web applications written in PHP by providing a basic structure for which to build the web applications. In other words, PHP frameworks help to promote rapid application development (RAD), which saves you time, helps build more stable applications, and reduces the amount of repetitive coding for developers. Frameworks can also help beginners to build more stable apps by ensuring proper database interaction and coding on the presentation layer. This allows you to spend more time creating the actual web application, instead of spending time writing repetitive code.</p>
<p>The general idea behind the workings of a <strong>PHP framework</strong> is referred to as <strong>Model View Controller</strong> (MVC). MVC is an architectural pattern in programming that isolates business logic from the UI, allowing one to be modified separately from the other (also known as separation of concerns). With MVC, Model refers to data, View refers to the presentation layer, and Controller to the application or business logic. Basically, MVC breaks up the development process of an application, so you can work on individual elements while others are unaffected. Essentially, this makes coding in PHP faster and less complicated.</p>
<h3 class="title">Why Should we use a PHP Framework?</h3>
<p>Developers should utilize PHP frameworks for various reasons, but the number one reason is for speeding up the development process. Reusing code across similar projects will save the developer a substantial amount of time and effort. A framework offers pre-built modules for performing tedious coding tasks, so the developer can spend their time on developing the actual application rather than re-building the foundation with each and every project.</p>
<p>Stability is another big reason developers are utilizing frameworks. While simplicity is one of PHP’s greatest assets, and the reason many people prefer to use this scripting language, it can also be one of its biggest downfalls. It’s fairly easy, especially for beginners, to write bad code and not even realize it. With PHP the application will often times still work, but unknowingly you may have opened up a large security hole in your coding that may be susceptible to attacks. It’s important to remember that PHP is a very forgiving language, so it’s even more important to make sure to tie up any loose ends in your coding – even if the application seems to be working properly.</p>
<p>Finally, the availability of PHP frameworks is extensive, and there are many different frameworks to choose from. You can even create your own, although many developers elect to choose from any of the most well-known frameworks due to their popularity, large support teams, and their forums/communities that allow you to interact with other developers who utilize the same framework. As a side note, you should always examine your project to first decide if you should even use a framework or not. Some questions you should ask yourself are: Will it save you, and anyone else who may use it, time and effort? Will the app perform better? Will it improve stability? If you can answer yes to any of these questions, a PHP framework may be the right answer for that particular project.</p>
<h3 class="title">When to use a PHP Framework?</h3>
<p>This is a common question amongst experienced and beginner developers alike, and there’s really no direct answer to the question. For many beginners, a framework will offer greater simplicity as well stability, so it may be a good idea to use PHP frameworks whenever possible. It will help reduce or eliminate bad coding and speed up the build process.</p>
<p>On the other hand, many experienced PHP programmers see frameworks as tools for “weak” programmers that don’t understand how to write good, clean code. Whether this is true or not is up for debate, but the fact of the matter is that PHP frameworks are a tool that can be used to save time and tighten up one’s coding.</p>
<p>When working on a project with tight deadlines, utilizing a PHP framework is a huge benefit that can greatly speed up the coding process. So if you’re in a time crunch, PHP frameworks can be very beneficial to you. Another instance when PHP frameworks should be a consideration is when you’re working on projects with substantial amounts of monotonous coding, because it will help make the job much less tedious.</p>
<h3 class="title">What to Look for in a PHP Framework?</h3>
<p>There’s plenty of options available to anyone who may be searching for PHP frameworks, and there’s even the option of creating your own, although that’s only recommended for PHP experts. When searching for the the PHP framework best suited for your needs, it’s important to keep in mind who will be using and/or modifying your applications from top to bottom. If there are many people who will be using the application, it may be best use a popular PHP framework that many developers are familiar with. On the other hand, if you wish to build web applications for your own personal use, you are better off choosing any PHP framework that you’re comfortable with – whether it’s popular amongst the developer community or not.</p>
<p>Various factors to search for in a PHP framework include: easy of use, rapid development/performance, popularity amongst other developers, strong features, and support/forums. It’s recommended to try out several PHP frameworks when you’re first starting out in order to find one that suits your needs the best. All frameworks are slightly different and have varying strengths and weaknesses, for instance Zend Framework has been around since V3 and is full of features plus has an extensive support system in place since it has been around for so long. On the contrary, CakePHP is another PHP framework which is younger than Zend Framework and has slightly less of a support system in place (although support for this framework is growing rapidly), but is much more user-friendly and easy to use.</p>
<p>As you can see, each type of PHP framework has its own advantages, so it’s best to use a bit of trial and error to figure out which one will work the best for your needs. Another excellent way of choosing a framework is to consult your colleagues in the development community to see which ones they prefer. Those who have actually used a specific framework will be able to inform you of the ease-of-use, features, support availability, scope of the community surrounding the framework, and possible shortfalls.</p>
<h3 class="title">Most Common Mistakes When Using a PHP Framework</h3>
<p>Mistakes are possible in any type of programming, but PHP frameworks help to limit these mistakes greatly by providing good quality code that is tried and true from the start of the development process. Repetitive coding seems to promote mistakes now and then, and frameworks all but eliminate that problem.</p>
<p>That being said, there are still things to be careful of when utilizing any PHP framework. For instance, unless you are an expert in PHP programming, you should always opt for using a popular framework with plenty of support and an active user base (see below for examples of popular PHP frameworks). There are many frameworks out there that have little or no support, and/or they were created by individuals with limited knowledge of PHP. These types of frameworks can cause your applications to not function properly, and worse case scenario, could cause catastrophic security issues with your website.</p>
<p>Another somewhat common mistake is not ensuring your database and web server is compatible with the particular framework. For example, Seagull PHP Framework recommends the following configuration:</p>
<ul class="post">
<li><strong>PHP:</strong> PHP 4.3.0 is the minimum, later versions work fine, as do versions PHP 5.1.1 and above. Avoid anything in the 5.0.x series</li>
<li><strong>MySQL:</strong> MySQL 4.0.x, 4.1.x and 5.0.x are all supported. You can also use 3.23.x.</li>
<li><strong>Apache:</strong> Seagull works fine with 1.3.x and 2.x series of Apache</li>
</ul>
<p>If you don’t meet these requirements, you won’t be observing the best performance possible from your chosen framework. Even if you are an expert in PHP, you should always go over the documentation of the framework to confirm compatibility before trying it out.</p>
<p>Similar to the previously mentioned common mistake, not following the recommended installation process of your PHP framework can also give you some headaches. Take Seagull as an example again – the Seagull wiki has a detailed rundown of the framework’s installation process that has several key steps that are sometimes easily overlooked by careless or unsuspecting developers. The key is to take your time setting up the framework and follow the installation instructions to the “T” – The time you’ll save actually developing applications later will more than make up for the few extra minutes spent installing the framework correctly the first time.</p>
<h3 class="title">What are the Best PHP Frameworks Available?</h3>
<p>Within the past few years as PHP has evolved as the scripting language of choice by most developers, there have been an explosion of PHP frameworks to hit the scene. There is a great debate about what the best PHP frameworks are, because the simple fact is that not every framework is built for everyone. Here’s a quick rundown of five of the best and most popular choices right now:</p>
<h4 class="title">The Zend Framework</h4>
<p class="img"><img src="http://noupe.com/img/php-frameworks/php-1.jpg" alt="PHP Frameworks Post Image" width="500" height="350" /></a></p>
<p><a href="http://framework.zend.com/">The Zend Framework</a> has a massive following amongst the development community and is focused on web 2.0 style applications. Because of their massive following, extensive support and active user base, Zend is referred to as “The PHP Company”. Zend is one of, if not, the most popular PHP frameworks available today. It has robust features that are built for corporate-level development, and it requires an extensive knowledge of PHP.</p>
<h4 class="title">CakePHP</h4>
<p class="img"><img src="http://noupe.com/img/php-frameworks/php-2.jpg" alt="PHP Frameworks Post Image" width="500" height="350" /></a></p>
<p><a href="http://cakephp.org/">CakePHP</a> is a great choice for beginners to advanced PHP developers. It’s based on the same principles that Ruby on Rails is designed around, and it’s heavily focused on rapid development – making it a great framework to be used for rapid application development. Its rapidly growing support system, simplicity, and scalability make CakePHP one of the most popular PHP frameworks available today.</p>
<h4 class="title">Symfony</h4>
<p class="img"><img src="http://noupe.com/img/php-frameworks/php-3.jpg" alt="PHP Frameworks Post Image" width="500" height="350" /></a></p>
<p><a href="http://www.symfony-project.org/">Symfony</a> is aimed more at advanced developers who’s main objective is to create enterprise-level applications – most notably Askeet and Yahoo! Bookmarks. This open source PHP framework is full of features and can do it all, but it’s main downfall is that it is a bit slower than other frameworks.</p>
<h4 class="title">Codelgniter</h4>
<p class="img"><img src="http://noupe.com/img/php-frameworks/php-4.jpg" alt="PHP Frameworks Post Image" width="500" height="350" /></a></p>
<p><a href="http://codeigniter.com/">Codelgniter</a> is well-known for its ease-of-use, performance and speed. Unlike Symfony, this PHP framework is ideal for shared hosting accounts or for when you want a framework with a small footprint. It offers simple solutions, and has an extensive library of video tutorials, forums, a user guide and wiki available for support. Beginners should consider using Codelgniter.</p>
<h4 class="title">Seagull</h4>
<p class="img"><img src="http://noupe.com/img/php-frameworks/php-5.jpg" alt="PHP Frameworks Post Image" width="500" height="350" /></a></p>
<p><a href="http://seagullproject.org/">Seagull</a> is a well-established PHP framework used for building web, command line and GUI apps. It is an extremely easy to use framework that is ideal for beginners to advanced coders. For beginners, Seagull features a library of sample applications that can be customized to fit your needs, and for experts, Seagull offers a host of options – including best practices, standards, and modular codebase – for building web applications quickly and easily. Seagull has an active developer community and plenty of support documentation in place as well.</p>
<h4 class="title">Summary</h4>
<p>PHP frameworks are a great way for developers of all skill levels to reduce the need for repetitive coding, speed up the development process, and to ensure proper coding when creating web applications. This not only speeds up the development of rich applications, but it also tightens up PHP security by reducing the risk of security holes in your coding.</p>
<p>While some expert PHP coders do not feel the need to use frameworks to develop web apps, they can still be an advantage in situations where rapid development is necessary, such as under tight deadlines. And for beginner to intermediate developers, frameworks can enhance the PHP learning process while promoting good coding practices and reducing bad coding, which is common in PHP due to its “forgiving” nature.</p>
<p>There are many PHP frameworks available today, and thus developers are sure to find a framework that fits there needs in terms of features, support, speed, scalability and more. Some of the top PHP frameworks used by developers today include: The Zend Framework, CakePHP, Symfony, Codelgniter, and Seagull.</p>
<div class="author-box">
<div class="author-text">
<h4><strong>Author</strong>: Joel Reyes</h4>
<p>Joel Reyes Has been designing and coding web sites for several years, this has lead him to be the creative mind behind Looney Designer a design resource and portfolio site that revolves around web and graphic design.</p>
</p></div>
<div class="write-for-us"><strong class="red">Write for Us!</strong> We are looking for exciting and creative articles, if you want to contribute, just send us an <a href="mailto:info@noupe.com">email</a>.</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.noupe.com/php/discussing-php-frameworks.html/feed</wfw:commentRss>
		<slash:comments>221</slash:comments>
		</item>
		<item>
		<title>PHP Security:  Fortifying Your Website- Power Tips, Tools &amp; How to&#8217;s</title>
		<link>http://www.noupe.com/php/php-security-tips.html</link>
		<comments>http://www.noupe.com/php/php-security-tips.html#comments</comments>
		<pubDate>Sun, 05 Jul 2009 21:05:57 +0000</pubDate>
		<dc:creator>Editorial</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.noupe.com/?p=15885</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=3" border="0" alt="" /></a>
    </div></td></tr></table>
&nbsp;&nbsp; Defining PHP Security and It’s uses PHP is the most popular web programming languages in use today due in large part to the fact that it’s a highly flexible syntax that can perform many functions while working flawlessly in conjunction with html – Plus it’s relatively easy to learn for beginners, yet it’s powerful [...]]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<h3 class="title">Defining PHP Security and It’s uses</h3>
<p>PHP is the most popular web programming languages in use today due in large part to the fact that it’s a highly flexible syntax that can perform many functions while working flawlessly in conjunction with html – Plus it’s relatively easy to learn for beginners, yet it’s powerful enough for advanced users as well. It also works exceptionally well with open source tools, such as the Apache web server and MySQL database. In other words, its versatility is unsurpassed when compared to other scripting languages, making it the language of choice for many programmers.</p>
<p><span id="more-15885"></span></p>
<p>Though many programmers and developers may be implementing PHP in their websites, the issue of PHP security is often overlooked when building a site. Insecure coding is rather common in PHP due to the fact that it’s such a forgiving language that will often “work” even when there are a few loose ends in the coding. These “loose ends” are what hackers are looking for, and in PHP, they’re not that hard to find. The key is for you to find them <em>first</em>, and to leverage PHP’s unique features to minimize your security vulnerability.</p>
<p>PHP Security involves minimizing programming errors as much as possible, and putting proper code in place to protect against possible vulnerabilities – Often times this means putting 2-3 “layers” of protection in place to guard sensitive data against hackers that could otherwise cause a catastrophic result if compromised. Developers call this principle of redundant safeguarding <em>Defense in Depth</em>, and this concept has been proven over the years to be an extremely effective defense against malicious attacks.</p>
<h3 class="title">Types of Attacks</h3>
<p>There are various types of attacks that PHP is particularly vulnerable to, and any website that sends or receives information is at risk of an attack – ranging from an annoyance to catastrophic – so it’s important to put the proper security in place to minimize the risk. The two main types of attacks are <strong>human attacks</strong> and <strong>automated attacks</strong> – Both of which can potentially devastate a website.</p>
<p>The most common type of human attacks are little more than annoyances and are common at file storage sites and forums, such as abusing file storage policy, defamation, lobbying at sites such Amazon or Yahoo Answers, and other similar abuse that doesn’t necessarily involve manipulation of your website’s source code. Humans can also find security holes that allow them to access source code and use it maliciously. This can potentially cause substantial damage to your website, so this is the type of human attack you should focus your efforts on.</p>
<p>Automated attacks are particularly dangerous because of their efficiency in using the power of automated scripts to wreak havoc on your website in a number of different ways. These attacks may slow down your site, access the error logs, manipulate the source code, or compromise sensitive information – The possibilities are seemingly endless. The most common, and notorious, type of automated attack are viruses and worm, which are slightly different in nature but are similar in the way that they can potentially harm a website.</p>
<p>The goal of PHP security is to minimize, and ultimately eliminate, the potential for both human and automated attacks by putting into place strategic lines of defense to eliminate access to your site by unverified users. The way you go about doing this is to target the most common types of PHP security breaches first, so that you make your website airtight against malicious attacks. So what are the most common types of PHP security breaches?</p>
<h3 class="title">Most Common PHP Security Vulnerabilities</h3>
<p>Experienced hackers know the most common types of security holes to look for in PHP, so it’s important to address these issues first. It doesn’t matter whether you’re a beginner or expert PHP programmer, every programmer makes mistakes now and then, and hackers will find it if you don’t first.</p>
<h4 class="title">1. Register_Globals</h4>
<p>Register_Globals makes writing PHP applications simple and convenient for the developer, but it also poses a potential security risk. This setting is located in PHP’s configuration file, which is php.ini, and it can be either turned on or off. When turned on, it allows unverified users to inject variables into an application to gain administrative access to your website. Most, if not all, PHP security experts recommend turning register_globals off.</p>
<p>For example take a look at the <a href="http://en.wikibooks.org/wiki/PHP_Programming/Register_Globals">code snippet below</a>. A user could append the end of a page&#8217;s url with ?admin=1 to basically force entry to administrative areas that would normally require a password.</p>
<p class="img"><img src="http://noupe.com/img/php-security/secure-1.jpg" alt="PHP Security Post Image" width="?" height="?" /></a></p>
<p>With <a href="http://en.wikibooks.org/wiki/PHP_Programming/Register_Globals">register_globals</a> turned off, this type of forced entry isn’t possible. The good news is that PHP 4.2.0 has register_globals turned off as its default setting, and PHP 6.0.0 has actually removed the feature. While some developers frown upon this move because register_globals off makes programming in PHP slightly more time-consuming, but in terms of PHP security it’s a crucial step in the right direction.</p>
<p>So instead of relying on register_globals, you should instead go through PHP Predefined Variables, such as $_REQUEST. To further tighten security, you should also specify by using: $_ENV, $_GET, $_POST, $_COOKIE, or $_SERVER instead using the more general $_REQUEST.</p>
<h4 class="title">2. Error Reporting</h4>
<p>Error reporting is a great tool for diagnosing bugs and allowing you to fix them quicker and easier, but it also poses a potential security threat. The problem occurs when the error is visible to others on-screen, because it reveals possible security holes in your source code that a hacker can easily take advantage of. If display_errors is not turned off, or have a value of “0”, the output will appear on the end user’s browser – Not good for security! You do, however, want to set log_errors to on, and then indicate the exact location of the log with error_log.</p>
<p>Take a look at the table below from <a href="http://www.phpfreaks.com/tutorial/php-security/page2">PHPFreaks.com</a>, which points out the recommended settings for both production and development instances of PHP web applications.</p>
<p class="img"><img src="http://noupe.com/img/php-security/secure-2.jpg" alt="PHP Security Post Image" width="500" height="" /></a></p>
<h4 class="title">3. Cross-Site Scripting (XSS)</h4>
<p>Cross-site scripting, or XSS, is a way for hackers to gather your website’s user data by using malicious markup or JavaScript code to trick a user, or their browser, to follow a bad link or present their login details to a fake login screen that instead of logging them in, steals their personal information. The best way to defend against XSS is to disable JavaScript and images while surfing the web, but we all know that’s nearly impossible with so many websites using JavaScript’s rich application environment these days.</p>
<p>To defend against XSS attacks, you need to be proactive – Don’t wait until your website has already been exploited. For instance, PHP applications that use form submission, or POST requests, are much less vulnerable than GET requests. So it’s very important that you spell out which variables and actions will be allowed as GET values, and also which ones must come via POST values. In a nutshell, defending against XSS involves controlling the user input at your site and making sure that it goes through a filtering process to ensure that it’s void of malicious code.</p>
<p>An example of filtering user input can be found in the snippet of code below that was taken from <em>Pro PHP Security</em> by Chris Snyder and Michael Southwell.</p>
<p class="img"><img src="http://noupe.com/img/php-security/secure-3.jpg" alt="PHP Security Post Image" width="500" height="" /></a></p>
<p>This relatively straightforward piece of code works by preventing html and JavaScript from being embedded in the input, which results in a completely safe version of the input. This is especially useful for comment sections of a blog, forums and other web applications that receive user input.</p>
<p>Also useful for protecting against XSS is a useful PHP function called <em>htmlentities()</em>. This simple function works by converting all characters in html to their corresponding entities, such as “<” would convert to “&lt;” (without the quotes).</p>
<h4 class="title">4. Remote File Inclusion (RFI)</h4>
<p>This type of attack is relatively unknown amongst developers, which makes it an especially damaging threat to PHP security. Remote file inclusion, or RFI, involves an attack from a remote location that exploits a vulnerable PHP application and injects malicious code for the purpose of spamming or even gaining access to the root folder of the server. An unverified user gaining access to any server can wreak major havoc on a website in many different ways, including abusing personal information stored in databases.</p>
<p>A great example of an RFI attack can be found at<strong><a href="http://www.phpfreaks.com/tutorial/php-security/page6">PHPFreaks.com.</a></strong> Here&#8217;s an exerpt from that page:</p>
<blockquote><p>Imagine that at http://example.com/malice.php a file exists and our script is located at http://site.com/index.php. The attacker will do this request: http://site.com/index.php?page=http://example.com/malice. This file will get executed when it is included and it will a write a new file to the disk.</p></blockquote>
<p>The best way to secure your site from RFI attacks is through php.ini directives – Specifically, the allow_url_fopen and the allow_url_include directives. The allow_url_fopen directive is set to on by default, and the allow_url_include is set to off. These two simple directives will adequately protect your site from RFI attacks.</p>
<h3 class="title">Other PHP Security Tools</h3>
<p>While the most effective way to secure PHP web application is through accurate coding and vigilante monitoring of your site, there are other helpful tools out there that can help to quickly and easily point out possible vulnerabilities in your PHP coding. Here are three useful tools that can be beneficial to PHP developers:</p>
<h4 class="title">- PhpSecInfo</h4>
<p class="img"><img src="http://noupe.com/img/php-security/secure-4.jpg" alt="PHP Security Post Image" width="500" height="" /></a></p>
<p>This useful tool reports security information in the PHP environment, and best of all, it offers suggestions for improving the errors. It’s available for download under the “New BSD” license, and the PhpSecInfo project is always looking for more PHP developers to help improve this tool.</p>
<p class="img"><img src="http://noupe.com/img/php-security/secure-5.jpg" alt="PHP Security Post Image" width="500" height="" /></a></p>
<p><a href="http://phpsec.org/projects/phpsecinfo/index.html" class="download">Download PhpSecInfo Here.</a></p>
<h4 class="title">- PHP Security Scanner</h4>
<p>This is a tool used to scan PHP code for vulnerabilities, and it can be used to scan any directory. <a href="http://www.security-database.com/toolswatch/PHP-Security-Scanner-1-2-added-to.html">PHP Security Scanner</a> features a useful UI for better visualization of potential problems, and it supports basic wild card search functionality for filtering directories or files that are to be searched.</p>
<p><a href="http://sourceforge.net/projects/securityscanner/" class="download">Download PHP Security Scanner Here</a></p>
<h4 class="title">- Spike PHP Security Audit Tool</h4>
<p>The Spike PHP Security Audit Tool is an open source solution for doing static analysis of PHP code. It will search for security exploits, so you can correct them during the development process.</p>
<p class="img"><img src="http://noupe.com/img/php-security/secure-6.jpg" alt="PHP Security Post Image" width="500" height="" /></a></p>
<p><a href="http://developer.spikesource.com/projects/phpsecaudit/" class="download">Download Spike PHP Security Audit Tool Here</a></p>
<div class="author-box">
<div class="author-text">
<h4><strong>Author</strong>: Joel Reyes</h4>
<p>Joel Reyes Has been designing and coding web sites for several years, this has lead him to be the creative mind behind Looney Designer a design resource and portfolio site that revolves around web and graphic design.</p>
</p></div>
<div class="write-for-us"><strong class="red">Write for Us!</strong> We are looking for exciting and creative articles, if you want to contribute, just send us an <a href="mailto:info@noupe.com">email</a>.</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.noupe.com/php/php-security-tips.html/feed</wfw:commentRss>
		<slash:comments>70</slash:comments>
		</item>
		<item>
		<title>How To Create Your Own Stats Program (JavaScript, AJAX, PHP)</title>
		<link>http://www.noupe.com/php/how-to-create-your-own-stats.html</link>
		<comments>http://www.noupe.com/php/how-to-create-your-own-stats.html#comments</comments>
		<pubDate>Tue, 16 Jun 2009 21:01:18 +0000</pubDate>
		<dc:creator>Editorial</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.noupe.com/?p=14293</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=3" border="0" alt="" /></a>
    </div></td></tr></table>
&nbsp;&nbsp; When creating a website, one main goal is to attract visitors. Traffic generation is a necessity for monetary purposes, showing off your work, or just expressing your thoughts. There are many ways to create traffic for your website. Search engines, social bookmarking, and word of mouth are just a few examples. But how do [...]]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<p>When creating a website, one main goal is to attract visitors. Traffic generation is a necessity for monetary purposes, showing off your work, or just expressing your thoughts. There are many ways to create traffic for your website. Search engines, social bookmarking, and word of mouth are just a few examples. But how do you know whether this traffic is genuine? How do you know if your visitors are coming back for a second time?</p>
<p><span id="more-14293"></span></p>
<hr/>
<p class="img"><img src="http://noupe.com/img/php-stats/stats-1.jpg" alt="Web Statistics"/></p>
<p>These questions have raised the concept of web statistics. Often times, webmasters use certain programs, such as Google Analytics or Awstats, to complete this job for them. These programs obtain a wide variety of information about visitors to a site. They find page views, visits, unique visitors, browsers, IP addresses, and much more. But how exactly is this accomplished? Follow along as we present a tutorial on how to create your own web statistics program using PHP, JavaScript, AJAX, and SQLite.</p>
<p style="background-color:#F0EEE6;<br />
border:1px solid #E7E5DD; padding:20px" class="img"><a target="_blank" href="http://karthik-testing.nfshost.com/web-stats/" style="border:none">View Demo of your Own Stats Program</a></p>
<p>To begin, let&#8217;s start with some simple HTML markup that will act as the page we are tracking:</p>
<pre name="code" class="php">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Web Statistics&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h2 id="complete"&gt;&lt;/h2&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>The <code>h2#complete</code> element will be filled dynamically with JavaScript once the page view has successfully been tracked by our web statistics. To initiate this tracking, we can use jQuery and an AJAX request:</p>
<pre name="code" class="php">&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type='text/javascript'&gt;
$(function() {
	// Set the data text
	var dataText = 'page=&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;&#038;referrer=&lt;?php echo $_SERVER['HTTP_REFERER']; ?&gt;';

	// Create the AJAX request
	$.ajax({
		type: "POST",                    // Using the POST method
		url: "/process.php",             // The file to call
		data: dataText,                  // Our data to pass
		success: function() {            // What to do on success
			$('#complete').html( 'Your page view has been added to the statistics!' );
		}
	});
});
&lt;/script&gt; </pre>
</p>
<p>Consider the above code step by step:</p>
<ul>
<li>When the DOM is ready, we first set our <code>dataText</code>. This text is in query string format and will be sent as data to <code>process.php</code>, which will track this page view.</li>
<li>We then create an AJAX request that uses the POST method to send form data.</li>
<li>Our form data (dataText) is then sent to <code>process.php</code> in the root of our server.</li>
<li>Once this request is completed, the <code>h2#complete</code> element is filled with a successful notice</li>
</ul>
<p>Our next job is to write <code>process.php</code>. Its main goal is to obtain information about the web statistics and store it in a database. Since our database has not yet been made, we must create a simple file, <code>install.php</code>, which will do this for us:</p>
<p class="img"><img src="http://noupe.com/img/php-stats/stats-2.jpg" alt="SQLite Database"/></p>
<pre name="code" class="php">&lt;?php
	# Open the database
	$handle = sqlite_open( $_SERVER['DOCUMENT_ROOT'].'stats.db', 0666, $sqliteError ) or die(  $sqliteError  );

	# Set the command to create a table
	$sqlCreateTable = "CREATE TABLE stats(page text UNIQUE, ip text, views UNSIGNED int DEFAULT 0, referrer text DEFAULT '')";

	# Execute it
	sqlite_exec( $handle, $sqlCreateTable );

	# Print that we are done
	echo 'Finished!';
?&gt;</pre>
<p>This code is mostly straightforward. It opens up a database (stats.db) in the root of the server and creates a database for it. The string inside <code>$sqlCreateTable</code> is a SQLite command that makes our statistics table. This table contains four colums: Page, IP Address, Views, and Referrer:</p>
<ul>
<li>Page is a String that contains the page being viewed as a relative link (i.e. /index.php).</li>
<li>IP Address is also a String that contains a list of IP Addresses that visited this page. It is in the format of <code>numVisits1(IP Address1) numVisits2(IP Address2) numVisits3(IP Address3) etc</code>. For example, if we obtained 10 visits from 74.35.286.15 and 5 visits from 86.31.23.78 (hypothetical ip addresses), this String would be <code>"10(74.25.286.15) 5(86.31.23.78)"</code>.</li>
<li>Views is an integer containing the number of times the page has been viewed.</li>
<li>Referrer is a String in the same format as IP Address. It contains all referrers to this page and how many referrals have been made.</li>
</ul>
<p>And now onto <code>process.php</code>:</p>
<pre name="code" class="php"># Connect to the database
$handle = sqlite_open( $_SERVER['DOCUMENT_ROOT'].'/stats.db', 0666, $sqliteError ) or die( $sqliteError );

# Use the same-origin policy to prevent cross-site scripting (XSS) attacks
# Remember to replace http://yourdomain.com/ with your actual domain
if( strpos( $_SERVER['HTTP_REFERER'], 'http://yourdomain.com/' ) !== 0 ) {
     die( "Do not call this script manually or from an external source." );
}

# Obtain the necessary information, strip HTML tags, and escape the string for backup proetection
$page = sqlite_escape_string( strip_tags( $_POST['page'] ) );
$referrer = sqlite_escape_string( strip_tags( $_POST['referrer'] ) );
$ip = sqlite_escape_string( strip_tags( $_SERVER['REMOTE_ADDR'] ) );

# Query the database so we can update old information
$sqlGet = 'SELECT * FROM stats WHERE page = \''.$page.'\'';
$result = sqlite_query( $handle, $sqlGet );</pre>
</p>
<p>This first snippet connects to our stats database and gets the information we need for the current visit. It also queries the database and obtains any information previously stored. We use this information to create an updated table.</p>
<p>The next job is to find old information:</p>
<p class="img"><img src="http://noupe.com/img/php-stats/stats-3.jpg" alt="Old Statistics"/></p>
<pre name="code" class="php"># Set up a few variables to hold old information
$views = 0;
$ips = '';
$referrers = '';

# Check if old information exists
if( $result &#038;&#038; ( $info = sqlite_fetch_array( $result ) ) ) {
	# Get this information
	$views = $info['views'];
	$ips = $info['ip'].' ';
	if( $info['referrer'] )
		$referrers = $info['referrer'].' ';

	# Set a flag to state that old information was found
	$flag = true;
}</pre>
</p>
<p>The above code finds all previous information in our table. This is vital, as we need to update the number of views (increase it by one), IP addresses, and referrers.</p>
<pre name="code" class="php"># Create arrays for all referrers and ip addresses
$ref_num = array();
$ip_num = array();

# Find each referrer
$values = split( ' ', $referrers );

# Set a regular expression string to parse the referrer
$regex = '%(\d+)\((.*?)\)%';

# Loop through each referrer
foreach( $values as $value ) {
	# Find the number of referrals and the URL of the referrer
	preg_match( $regex, $value, $matches );

	# If the two exist
	if( $matches[1] &#038;&#038; $matches[2] )
		# Set the corresponding value in the array ( referrer link -> number of referrals )
		$ref_num[$matches[2]] = intval( $matches[1] );
}

# If there is a referrer on this visit
if( $referrer )
	# Add it to the array
	$ref_num[$referrer]++;

# Get the IPs
$values = split( ' ', $ips );

# Repeat the same process as above
foreach( $values as $value ) {
	# Find the information
	preg_match( $regex, $value, $matches );

	# Make sure it exists
	if( $matches[1] &#038;&#038; $matches[2] )
		# Add it to the array
		$ip_num[$matches[2]] = intval( $matches[1] );
}

# Update the array with the current IP.
$ip_num[$ip]++;</pre>
</p>
<p>The above two loops are very similar. They take in the information from the database and parse it with regular expressions. Once this information is parsed, it is stored in an array. Each array is then updated with the information from the current visit. This information can then be used to create the final String:</p>
<pre name="code" class="php"># Reset the $ips string
$ips = '';

# Loop through all the information
foreach( $ip_num as $key => $val ) {
	# Append it to the string (separated by a space)
	$ips .= $val.'('.$key.') ';
}

# Trim the String
$ips = trim( $ips );

# Reset the $referrers string
$referrers = '';

# Loop through all the information
foreach( $ref_num as $key => $val ) {
	# Append it
	$referrers .= $val.'('.$key.') ';
}

# Trim the string
$referrers = trim( $referrers );</pre>
</p>
<p>The final strings are now created. IPs and Referrers are in the form: &#8220;numVisits1(IP/Referrer1) numVisits2(IP/Referrer2) etc.&#8221; For example, the following could be the referrer String:</p>
<pre name="code" class="php">5(http://www.noupe.com) 10(http://css-tricks.com)</pre>
</p>
<p>It means that 5 referrals came from http://www.noupe.com and 10 came from http://css-tricks.com. This format saves space and is easy to parse as web statistics.</p>
<p>Now for the final few lines:</p>
<pre name="code" class="php"># Update the number of views
$views++;

# If we did obtain information from the database
# (the database already contains some information about this page)
if( $flag )
	# Update it
	$sqlCmd = 'UPDATE stats SET ip=\''.$ips.'\', views=\''.$views.'\', referrer=\''.$referrers.'\' WHERE page=\''.$page.'\'';

# Otherwise
else
	# Insert a new value into it
	$sqlCmd = 'INSERT INTO stats(page, ip, views, referrer) VALUES (\''.$page.'\', \''.$ips.'\',\''.$views.'\',\''.$referrers.'\')';

# Execute the commands
sqlite_exec( $handle, $sqlCmd );</pre>
</p>
<p>That&#8217;s all there is to it for <code>process.php</code>. As a review, it finds the IP Address and Referrer of the visitor, uses the values to create two Strings, increases the number of views of the page by one, and places all of these values into the database.</p>
<p>There is now only one task left. We have to display the web statistics. Let&#8217;s call the following file <code>display.php</code>:</p>
<p class="img"><img src="http://noupe.com/img/php-stats/stats-4.jpg" alt="Display The Statistics"/></p>
<pre name="code" class="php">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Web Statistics Display&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php
	# Open up the database
	$handle = sqlite_open( $_SERVER['DOCUMENT_ROOT'].'/stats.db', 0666, $sqliteError ) or die( $sqliteError );

	# Get all the statistics
	$sqlGet = 'SELECT * FROM stats';
	$result = sqlite_query( $handle, $sqlGet );

	# Create an unordered list
	echo "&lt;ul&gt;\n";

	# If there are results
	if( $result ) {
		$page_views = 0;
		$unique_visitors = 0;

		# Fetch them
		while( ($info = sqlite_fetch_array( $result ) ) ) {
			# Get the page, views, IPs, and referrers
			$page = $info['page'];
			$views = $info['views'];
			$ips = $info['ip'];
			$referrers = $info['referrer'];

			# Print out a list element with the <code>$page/$views</code> information
			if( $views == 1 )
				echo "\t&lt;li&gt;\n\t\t&lt;p&gt;$page was viewed $views time:&lt;/p&gt;\n";
			else
				echo "\t&lt;li&gt;\n\t\t&lt;p&gt;$page was viewed $views times:&lt;/p&gt;\n";

			# Update the number of page views
			$page_views += $views;

			# Parse the data of IPs and Referrers using process.php's code
			preg_match_all( '%(\d+)\((.*?)\)%', $ips, $matches );

			# Find the size of the data
			$size = count( $matches[1] );

			# Create a sub list
			echo "\t\t&lt;ul&gt;\n";

			# Loop through all the IPs
			for( $i = 0; $i &lt; $size; $i++ ) {
				# Find the number of visits
				$num = $matches[1][$i];

				# Find the IP address
				$ip = $matches[2][$i];

				# Print the info in a list element
				if( $num == 1 )
					echo "\t\t\t&lt;li&gt;$num time by $ip&lt;/li&gt;\n";
				else
					echo "\t\t\t&lt;li&gt;$num times by $ip&lt;/li&gt;\n";

				# Update the number of unique visitors
				$unique_visitors++;
			}

			# Repeat the whole process for referrers
			preg_match_all( '%(\d+)\((.*?)\)%', $referrers, $matches );
			$size = count( $matches[1] );

			# Loop through each one
			for( $i = 0; $i &lt; $size; $i++ ) {
				$num = $matches[1][$i];
				$referrer = $matches[2][$i];

				# Print out the info
				if( $num == 1 )
					echo "\t\t\t&lt;li&gt;$num referral by $referrer&lt;/li&gt;\n";
				else
					echo "\t\t\t&lt;li&gt;$num referrals by $referrer&lt;/li&gt;\n";
			}

			# End the sub-list
			echo "\t\t&lt;/ul&gt;\n";

			# End the list element
			echo "\t&lt;/li&gt;\n";
		}

		echo "\t&lt;li&gt;Total unique visitors: $unique_visitors&lt;/li&gt;\n";
		echo "\t&lt;li&gt;Total page views: $page_views&lt;/li&gt;\n";
	}

	# End the unordered list
	echo "&lt;/ul&gt;\n";

	# Close the database
	sqlite_close($handle);
?&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
</p>
<p>It may seem daunting, but it is very similar to process.php. It parses the page, views, ip addresses, and referrers from the database. It then continues to output these in an unordered list format.</p>
<p>The final output is as follows:</p>
<p class="img"><img src="http://noupe.com/img/php-stats/stats-5.jpg" alt="Final Web Statistics"></p>
<p style="background-color:#F0EEE6;<br />
border:1px solid #E7E5DD; padding:20px" class="img"><a target="_blank" href="http://karthik-testing.nfshost.com/web-stats/" style="border:none">View Demo of your Own Stats Program</a></p>
<p>Thank you for reading and good luck!</p>
<div class="author-box">
<div class="author-text">
<h4><strong>Author</strong>: <a href="http://www.lateralcode.com">Karthik Viswanathan</a></h4>
<p>Karthik Viswanathan is a high-school student who loves to program and create websites. You can view Karthik&#8217;s work on his two blogs, <a href="http://blog.pqlite.com">Resource Mania</a> and <a href="http://www.lateralcode.com">Lateral Code</a>. He has also developed a PHP library for traversing HTML documents, which can be found <a href="http://www.pqlite.com">here</a>.</p>
</p></div>
<div class="write-for-us"><strong class="red">Write for Us!</strong> We are looking for exciting and creative articles, if you want to contribute, just send us an <a href="mailto:info@noupe.com">email</a>.</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.noupe.com/php/how-to-create-your-own-stats.html/feed</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>20 Useful PHP + jQuery Components &amp; Tuts for Everyday Project</title>
		<link>http://www.noupe.com/php/20-useful-php-jquery-tutorials.html</link>
		<comments>http://www.noupe.com/php/20-useful-php-jquery-tutorials.html#comments</comments>
		<pubDate>Sun, 05 Apr 2009 23:06:03 +0000</pubDate>
		<dc:creator>Editorial</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[TUTORIAL]]></category>

		<guid isPermaLink="false">http://www.noupe.com/?p=10322</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&collection=noupe-rss&position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&collection=noupe-rss&position=3" border="0" alt="" /></a>
    </div></td></tr></table>
&nbsp;&nbsp; Web applications have made huge leaps and bounds in improving user experience thanks to a lot of recently developed Ajax technology. When you combine some neat functionality courtesy of PHP with the cleverness of jQuery you can produce some pretty neat effects. In an effort to help you take it up a notch, we’d [...]]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<p>Web applications have made huge leaps and bounds in improving user experience thanks to a lot of recently developed Ajax technology. When you combine some neat functionality courtesy of PHP with the cleverness of jQuery you can produce some pretty neat effects. In an effort to help you take it up a notch, we’d like to share some methods for helping your site anticipate a user’s next move.</p>
<p>The post below is made up of the best 20 PHP + jQuery Components and Tutorials that you will likely need in many of your projects, they are all of the highest quality and more or less easy to configure. Give them a try.</p>
<p><span id="more-10322"></span></p>
<h3 class="title">1. <a href="http://www.lateralcode.com/directory-trees-with-php-and-jquery/">Directory Trees With PHP And jQuery</a></h3>
<p>A simple way to keep track of many files is to use a directory tree. A directory tree lists out files and directories so that it’s easy to find what you’re looking for. In this tutorial, you will learn how to create a directory tree using PHP and jQuery.</p>
<p class="img"><a href="http://www.lateralcode.com/directory-trees-with-php-and-jquery/"><img src="http://noupe.com/img/php-jquery-components1.jpg" alt=""/></a></p>
<p><a href="http://demo.lateralcode.com/directory-tree/" class="">Check out the Demo Here</a></p>
<h3 class="title">2. <a href="http://net.tutsplus.com/videos/screencasts/create-a-photo-admin-site-using-php-and-jquery/">Create a Photo Admin Site Using PHP and jQuery</a></h3>
<p>A sceencast tutorial for creating a photo site using PHP, jQuery, and AJAX. You will learn how to retrieve images from a database, create a simple login form with authentication, and then allow for the database to be asynchronously updated.</p>
<p class="img"><a href="http://net.tutsplus.com/videos/screencasts/create-a-photo-admin-site-using-php-and-jquery/"><img src="http://noupe.com/img/php-jquery-components2.jpg" alt=""/></a></p>
<h3 class="title">3. <a href="http://net.tutsplus.com/tutorials/php/asynchronous-comments-with-jquery-and-json/">Asynchronous Comments with PHP, jQuery, and JSON</a></h3>
<p>In this article, learn how to create a simple but effective means of capturing and displaying visitor comments using a blend of jQuery, PHP and JSON. In the public forum that is the blogosphere, the ability to capture and display visitor comments on your blogs can give you instant feedback and opinions from the people that matter most – those that read your blog.</p>
<p class="img"><a href="http://net.tutsplus.com/tutorials/php/asynchronous-comments-with-jquery-and-json/"><img src="http://noupe.com/img/php-jquery-components3.jpg" alt=""/></a></p>
<p><a href="http://www.danwellman.co.uk/comments.html" class="">Check out the Demo Here</a></p>
<h3 class="title">4. <a href="http://www.chazzuka.com/blog/?p=82">PHP ajax login form using Jquery</a></h3>
<p>Create a new PHP ajax login functionality using Jquery. You can easliy switch the data source between database and PHP array, login authentication can be using username or email, or even both of ‘em by changing the config, automattic redirection could be done within the javascript config.</p>
<p class="img"><a href="http://www.chazzuka.com/blog/?p=82"><img src="http://noupe.com/img/php-jquery-components4.jpg" alt=""/></a></p>
<p><a href="http://www.chazzuka.com/experiments/php-ajax-login/" class="">Check out the Demo Here</a></p>
<h3 class="title">5. <a href="http://query7.com/php-jquery-todo-list-part-1/">PHP + jQuery Todo List Part 1</a>, <a href="http://query7.com/php-jquery-todo-list-part-2/">part2</a></h3>
<p>This is part 1 of a 2 part series on making a Todo List with PHP and enhancing it with jQuery’s AJAX and manipulation capabilities.</p>
<p class="img"><a href="http://query7.com/php-jquery-todo-list-part-1/"><img src="http://noupe.com/img/php-jquery-components5.jpg" alt=""/></a></p>
<p><a href="http://lastkarrde.com/q7todo/" class="">Check out the Demo Here</a></p>
<h3 class="title">6. <a href="http://virae.org/newsletter_module/">Newsletter module</a></h3>
<p>A PHP, jQuery and AJAX module, which should be great for any newsletter management needs. You just need to copy one file onto your site, and you&#8217;re ready to send and archive all newsletters, manage e-mail addresses and categories, and configure a template for your e-mails. Also have an ability of optional password protection. All options can be easily configured at the top of included .php file.</p>
<p class="img"><a href="http://virae.org/newsletter_module/"><img src="http://noupe.com/img/php-jquery-components6.jpg" alt=""/></a></p>
<p><a href="http://virae.org/newsletter_module/" class="">Check out the Demo Here</a></p>
<h3 class="title">7. <a href="http://www.reynoldsftw.com/2009/03/tutorial-from-php-to-xml-to-jquery-and-ajax/">From PHP to XML to jQuery and Ajax</a></h3>
<p>This tutorial will focus on getting data from a database using PHP, converting that to an XML document, and reading that XML in through jQuery via Ajax calls. Seems complex, but is in fact, very easy.</p>
<p class="img"><a href="http://www.reynoldsftw.com/2009/03/tutorial-from-php-to-xml-to-jquery-and-ajax/"><img src="http://noupe.com/img/php-jquery-components7.jpg" alt=""/></a></p>
<p><a href="http://demos.reynoldsftw.com/php-xml-jquery-ajax/theHTML.html" class="">Check out the Demo Here</a></p>
<h3 class="title">8. <a href="http://yensdesign.com/2009/01/how-validate-forms-both-sides-using-php-jquery/">How to Validate Forms in both sides using PHP and jQuery</a></h3>
<p>We are going to learn how to validate your forms using PHP and jQuery in both sides: client side (using javascript with jQuery) and server side (using PHP). It will be interesting to see how to use regular expressions to validate different kind of e-mails, passwords and more.</p>
<p class="img"><a href="http://yensdesign.com/2009/01/how-validate-forms-both-sides-using-php-jquery/"><img src="http://noupe.com/img/php-jquery-components8.jpg" alt=""/></a></p>
<p><a href="http://yensdesign.com/tutorials/validateform/" class="">Check out the Demo Here</a></p>
<h3 class="title">9. <a href="http://yensdesign.com/2009/01/create-a-shoutbox-using-php-and-ajax-jquery/">Create a shoutbox using PHP and AJAX</a></h3>
<p>We will learn how to create a dynamic ajax based shoutbox with jQuery from scratch. It will be very interesting to know how to use the ajax function of jQuery and how it can be used to insert and recover data from a MySQL database via PHP in a way asynchronous.</p>
<p class="img"><a href="http://yensdesign.com/2009/01/create-a-shoutbox-using-php-and-ajax-jquery/"><img src="http://noupe.com/img/php-jquery-components9.jpg" alt=""/></a></p>
<p><a href="http://www.yensdesign.com/tutorials/shoutbox" class="">Check out the Demo Here</a></p>
<h3 class="title">10. <a href="http://t.wits.sg/2008/06/25/howto-php-and-jquery-upload-progress-bar/">HOWTO: PHP and jQuery upload progress bar</a></h3>
<p>With the controllable jQuery Progress Bar, writing a form upload progress bar seems like a piece of cake now. Hypothetically, all we need is to create the bar, poll for the progress of the file upload, drive the new progress bar value (in percentage) and set it using PHP.</p>
<p class="img"><a href="http://t.wits.sg/2008/06/25/howto-php-and-jquery-upload-progress-bar/"><img src="http://noupe.com/img/php-jquery-components10.jpg" alt=""/></a></p>
<p><a href="http://t.wits.sg/misc/jQueryProgressBar/demo.php" class="">Check out the Demo Here</a></p>
<h3 class="title">11. <a href="http://fromvega.com/wordpress/2007/05/05/auto-complete-field-with-jquery-json-php/">Auto-Complete Field with jQuery, JSON &#038; PHP</a></h3>
<p>Using jQuery with PHP to create auto complete field, beside the auto-complete code we need the jQuery library along with its Dimensions plug-in.</p>
<p class="img"><a href="http://fromvega.com/wordpress/2007/05/05/auto-complete-field-with-jquery-json-php/"><img src="http://noupe.com/img/php-jquery-components11.jpg" alt=""/></a></p>
<h3 class="title">12. <a href="http://www.marcofolio.net/webdesign/a_fancy_apple.com-style_search_suggestion.html">A fancy Apple.com-style search suggestion</a></h3>
<p>Learn how to recreate the effect from Apple website by creating a fancy apple.com-style search suggestion. This example makes use of several techniques: MySQL (for the database), HTML/CSS for styling, PHP for retrieving the data and jQuery for the AJAX request.</p>
<p class="img"><a href="http://www.marcofolio.net/webdesign/a_fancy_apple.com-style_search_suggestion.html"><img src="http://noupe.com/img/php-jquery-components12.jpg" alt=""/></a></p>
<p><a href="http://qpoit.com/marcofolio_demo/apple_search/" class="">Check out the Demo Here</a></p>
<h3 class="title">13. <a href="http://www.webmotionuk.co.uk/php-jquery-image-upload-and-crop-v11/">PHP &#038; jQuery image upload and crop v1.2 </a></h3>
<p>Create a PHP and jQuery image upload and crop tool using PHP, jQuery, PHP GD Library and <a href="http://odyniec.net/projects/imgareaselect/">Image Area Select</a>.</p>
<p class="img"><a href="http://www.webmotionuk.co.uk/php-jquery-image-upload-and-crop-v11/"><img src="http://noupe.com/img/php-jquery-components13.jpg" alt=""/></a></p>
<p><a href="http://www.webmotionuk.co.uk/jquery/image_upload_crop.php" class="">Check out the Demo Here</a></p>
<h3 class="title">14. <a href="http://ennuidesign.com/blog/FlickrScrollr+Explained:+PHP">FlickrScrollr </a></h3>
<p>FlickrScrollr is a combination of PHP and jQuery that parses a Flickr RSS feed and creates an animated thumbnail display.</p>
<p class="img"><a href="http://ennuidesign.com/blog/FlickrScrollr+Explained:+PHP"><img src="http://noupe.com/img/php-jquery-components14.jpg" alt=""/></a></p>
<p><a href="http://ennuidesign.com/demo/flickrscrollr" class="">Check out the Demo Here</a></p>
<h3 class="title">15. <a href="http://ad1987.blogspot.com/2009/02/reddit-style-voting-with-php-mysql-and.html">Reddit-style Voting With PHP, MySQL And jQuery</a></h3>
<p>If you are a regular at Reddit, you must have noticed the way people vote there. You can either vote up or vote down. This tutorial will show you how to create such a voting system with jQuery, PHP and MySQL.</p>
<p class="img"><a href="http://ad1987.blogspot.com/2009/02/reddit-style-voting-with-php-mysql-and.html"><img src="http://noupe.com/img/php-jquery-components15.jpg" alt=""/></a></p>
<p><a href="http://abhisek.uuuq.com/lab/reddit_votes/" class="">Check out the Demo Here</a></p>
<h3 class="title">16. <a href="http://9lessons.blogspot.com/2009/02/smtp-feedback-mail-class-with-jquery.html">SMTP Feedback Mail class with jQuery Slide Effect</a></h3>
<p>This post is about feedback mail with nice slide effect using php SMTP class and jQuery. It&#8217;s very useful to add  contact/feedback page to your php websites.</p>
<p class="img"><a href="http://9lessons.blogspot.com/2009/02/smtp-feedback-mail-class-with-jquery.html"><img src="http://noupe.com/img/php-jquery-components16.jpg" alt=""/></a></p>
<p><a href="http://9lessons.net63.net/feedback.php" class="">Check out the Demo Here</a></p>
<h3 class="title">17. <a href="http://9lessons.blogspot.com/2009/03/ajax-add-record-using-jquery.html">Ajax Add a Record with Button Status Change using jQuery</a></h3>
<p>If you like Facebook and Twitter API method of clicking follow, add a friend button. Where you click the button, the button status changed to &#8216;You following&#8217; and &#8216;Remove&#8217; at the same time request inserted into database. This tutorial will show you how to do it.</p>
<p class="img"><a href="http://9lessons.blogspot.com/2009/03/ajax-add-record-using-jquery.html"><img src="http://noupe.com/img/php-jquery-components17.jpg" alt=""/></a></p>
<p><a href="http://www.9lessons.net63.net/jqueryhtml.html" class="">Check out the Demo Here</a></p>
<h3 class="title">18. <a href="http://www.thatagency.com/design-studio-blog/2009/01/refreshing-an-element-at-a-set-time-interval-using-jquery-and-a-sprinkle-of-ajax/">Refreshing an element at a set time interval using jQuery and a sprinkle of Ajax</a></h3>
<p>Now lets say that you a web page that has a big Block of “something” and inside this “something” you would like to have some information change at a set time interval. Well with Jquery, some PHP and a sprinkle of Ajax, you can get this done quick fast and in a hurry.</p>
<p><a href="http://www.thatagency.com/design-studio-blog/examples/simple-page-element-refresh/" class="">Check out the Demo Here</a></p>
<h3 class="title">19. <a href="http://marcgrabanski.com/article/cakephp-ajax-quick-save-jquery">CakePHP Ajax &#8220;Quick Save&#8221; with jQuery</a></h3>
<p>When you are in an administration panel, sometimes you want a &#8220;quick save&#8221; feature that allows you to save without leaving the page.  Here is how to accomplish this with CakePHP and jQuery.</p>
<p class="img"><a href="http://marcgrabanski.com/article/cakephp-ajax-quick-save-jquery"><img src="http://noupe.com/img/php-jquery-components19.jpg" alt=""/></a></p>
<h3 class="title">20. <a href="http://www.xanthir.com/pir/">PHP / jQuery Image Replacement</a></h3>
<p>This is a tiny plugin that, in combination with a separate server-side script, dynamically replaces the text of an element with an image, generated using fonts you specify. This allows you to use beautiful text in headings without having to manually produce images in Photoshop, GIMP, or similar.</p>
<p class="img"><a href="http://www.xanthir.com/pir/"><img src="http://noupe.com/img/php-jquery-components20.jpg" alt=""/></a></p>
<p><a href="http://www.xanthir.com/pir/" class="">Check out examples here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.noupe.com/php/20-useful-php-jquery-tutorials.html/feed</wfw:commentRss>
		<slash:comments>101</slash:comments>
		</item>
	</channel>
</rss>

