<?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>Open Source Web &#187; PHP</title>
	<atom:link href="http://www.open-source-web.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.open-source-web.com</link>
	<description>Your open source for Development and Design</description>
	<lastBuildDate>Sun, 22 Aug 2010 19:08:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP and dynamic URLs</title>
		<link>http://www.open-source-web.com/php/php-and-dynamic-urls/</link>
		<comments>http://www.open-source-web.com/php/php-and-dynamic-urls/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 22:09:01 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=172</guid>
		<description><![CDATA[Whenever I make a new website now I always think about what the urls will need to be like. Most off the shelf CMS platforms will have a plug in or option to enables similar functionality.  But if your writing the site yourself you will want to be able to convert URL from post Id&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I make a new website now I always think about what the urls will need to be like. Most off the shelf CMS platforms will have a plug in or option to enables similar functionality.  But if your writing the site yourself you will want to be able to convert URL from post Id&#8217;s to post names to Urls and back again.</p>
<p>I have used many methods to do this in the past but recently I found two really useful built in PHP functions. <strong>urlencode()</strong> and <strong>urldecode()</strong>.</p>
<p>Alternatives to using <strong>urlencode() </strong>would be writing your own function to convert all the url unfriendly symbols, slashes, spaces etc. into HTML entities or just replacing them with hyphens.</p>
<p>Again PHP has an built in function for everyhting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/php-and-dynamic-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Charts Example</title>
		<link>http://www.open-source-web.com/php/google-charts-example/</link>
		<comments>http://www.open-source-web.com/php/google-charts-example/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 18:14:03 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[API's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=117</guid>
		<description><![CDATA[API&#8217;s are becoming more popular on the web as many of the big online companies such as Google, Yahoo and Facebook offer there own open source code for web developers to use freely and easily. To begin with I am going to go through how to use the Charts Basics API from Google. This is [...]]]></description>
			<content:encoded><![CDATA[<p>API&#8217;s are becoming more popular on the web as many of the big online companies such as Google, Yahoo and Facebook offer there own open source code for web developers to use freely and easily.</p>
<p><img src="http://chart.apis.google.com/chart?chs=250x100&amp;chd=t:10,80,35,10&amp;cht=lc&amp;chl=wk1|wk2|wk3|wk4" alt="Google Charts Basics" /></p>
<p>To begin with I am going to go through how to use the Charts Basics API from Google. This is an extremely easy one to start off with as you don&#8217;t require an API key or to install anything, you don&#8217;t even need a dynamic server side script to get some nice results.</p>
<p>For this example I am going to jazz it up with a bit of PHP using an associative array but you can easily replace this with a database or XML feed.</p>
<p>To call a chart we use the query string linking to the API which will end up looking something like this.</p>
<pre id="line1">&lt;<span class="start-tag">img</span><span class="attribute-name"> src</span>=<span class="attribute-value">"http://chart.apis.google.com/chart?chs=250x100&amp;amp;chd=t:10,80,35,10&amp;amp;cht=lc&amp;amp;chl=wk1|wk2|wk3|wk4"
</span><span class="attribute-name">alt</span>=<span class="attribute-value">"Sample chart" </span><span class="error"><span class="attribute-name">/</span></span>&gt;</pre>
<p>To generate this dynamicaly I used the following code</p>
<pre class="php" name="code">$arr = array();

$arr['Jan']['wk1'] = 10;
$arr['Jan']['wk2'] = 80;
$arr['Jan']['wk3'] = 35;
$arr['Jan']['wk4'] = 10;

$chart= 'http://chart.apis.google.com/chart?';
$chartsize = 'chs=250x100';
$type = "cht=lc";
$vals = 'chd=t:';
$keys = 'chl=';
$alt = "January";

foreach( $arr['Jan'] as $key =&gt; $value){
	$vals .= $value.',';
	$keys .= $key.'|';
	}</pre>
<p>And Lastly to pull all the code together.</p>
<pre class="php" name="code">
&lt;img src="&lt;? echo $chart;?&gt;
&lt;? echo $chartsize;?&gt;
&amp;amp;&lt;? echo substr("$vals", 0, -1);?&gt;
&amp;amp;&lt;? echo $type;?&gt;
&amp;amp;&lt;? echo substr("$keys", 0, -1);?&gt;"
alt="Sample chart" /&gt;
</pre>
<p>To develop this example further use the official documentation available here <a title="Google Chart Basic" rel="nofollow" href="http://code.google.com/apis/chart/" target="_blank">Google Chart Basic</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/google-charts-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random Banner with PHP</title>
		<link>http://www.open-source-web.com/php/random-banner-with-php/</link>
		<comments>http://www.open-source-web.com/php/random-banner-with-php/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 22:26:15 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[banners]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=103</guid>
		<description><![CDATA[This is a quick tutorial which shows how easy it is to make a random banner script with PHP. We will use a PHP array of images which is populated by a given directory and select a random index from the array to be the banner. For this example I have chosen to list the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick tutorial which shows how easy it is to make a random banner script with PHP. We will use a PHP array of images which is populated by a given directory and select a random index from the array to be the banner.</p>
<p>For this example I have chosen to list the files from a directory as this will keep the script fairly dynamic without the need of a database. The script could be easily modified to use a database but we can come back to that later on if we need to.</p>
<p>To start off all you will need is a folder with several banners and a page to display them on.</p>
<p>$dir will be the directory you have created to grab the images from, it is important to make sure this folder only contains banners.<br />
$banners will be the array of images found in the given folder.</p>
<pre class="php" name="code">

 $banners = array();
  $dir = 'res/banners/';
  if ($handle = opendir($dir)) {
  while (false !== ($file = readdir($handle))) {
  if($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot;){
  $banners[] = $file;
  }
  }
  closedir($handle);
  }

  $rand = array_rand($banners,1);
  echo &quot;&lt;img src='&quot;.$dir.$banners[$rand].&quot;' alt='banner'/&gt;&quot;;   
</pre>
<p>The code above uses a few handy built in PHP functions:<br />
opendir()<br />
readdir()<br />
array_rand()<br />
print_r()</p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/random-banner-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shorthand boolean IF with PHP</title>
		<link>http://www.open-source-web.com/php/shorthand-boolean-if-with-php/</link>
		<comments>http://www.open-source-web.com/php/shorthand-boolean-if-with-php/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 19:39:22 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[quick]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=74</guid>
		<description><![CDATA[This is a good alternative to using a basic IF condition. It basically fits the whole thing on a minimal line of code. It is an  easy way to compare two values and select the right one. There are a few ways to use this but the basic jist of it is to compare two [...]]]></description>
			<content:encoded><![CDATA[<p>This is a good alternative to using a basic IF condition. It basically fits the whole thing on a minimal line of code.</p>
<p>It is an  easy way to compare two values and select the right one. There are a few ways to use this but the basic jist of it is to compare two values and if its is true use the first value after the question mark, or if the condition returns false use the second value.</p>
<pre name="code" class="php">
echo $targetvar =  ($somevar == "thisVar" ? "itIsTrue" : "itIsFalse");
</pre>
<p><span style="font-size: 9pt; font-family: 'Arial','sans-serif';"><br />
In the example above we can set $targetvar with the condition. it will compare the first two variables with whatever you use, more then less then etc and it will choose the correct value from the two after the question mark.<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/shorthand-boolean-if-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEO Friendly Redirects with PHP</title>
		<link>http://www.open-source-web.com/php/seo-friendly-redirects-with-php/</link>
		<comments>http://www.open-source-web.com/php/seo-friendly-redirects-with-php/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 19:32:15 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=60</guid>
		<description><![CDATA[With a basic redesign you probably wont have this problem but if you have rebuilt a website even with the same content if the URL&#8217;s have changed this will have a huge effect on your search engine presence as you will be starting from scratch. Your links from internal pages may not work, links from [...]]]></description>
			<content:encoded><![CDATA[<p>With a basic redesign you probably wont have this problem but if you have rebuilt a website even with the same content if the URL&#8217;s have changed this will have a huge effect on your search engine presence as you will be starting from scratch. Your links from internal pages may not work, links from external sites wont work and you will lose your pagerank (if it ever mattered anyway.)</p>
<p>A good way to keep your sites listing after a redevelopment is to use a redirect. If you are using an Apache server you can use the .htaccess file to redirect.</p>
<p><code>Redirect 301 /oldpage.html /newpage.html</code></p>
<p>But some times this isnt the best way if you have to redirect hundreds of pages. The alternative is to use a header redirect in PHP. Most web based languages such as ASP or RUBY will do the same thing but with different code.</p>
<p><code><span class="html"><br />
<span class="default">&lt;?php</span></span></code></p>
<p><code><span class="html"><span class="comment">// make this code the first line<br />
</span><span class="default">header</span><span class="keyword">(</span><span class="string">"Location: /newpage.php"</span><span class="keyword">,</span><span class="default">TRUE</span><span class="keyword">,</span><span class="default">301</span><span class="keyword">);</span><span class="keyword"> </span></span></code><code><span class="html"><span class="default"> </span><span class="comment">// 301 Moved Permanently</span></span></code> to newpage.php<br />
<code><span class="html"><span class="keyword"> </span><span class="default">?&gt;</span></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/seo-friendly-redirects-with-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tracking visitors with PHP and Predefined variables</title>
		<link>http://www.open-source-web.com/php/tracking-visitors-with-php-and-predefined-variables/</link>
		<comments>http://www.open-source-web.com/php/tracking-visitors-with-php-and-predefined-variables/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 22:37:21 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[predefined]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=29</guid>
		<description><![CDATA[Although Google analytics can tell us a lot about who is visiting our websites it is still flawed in many ways. Google analytics is a powerful tool but if the user has disabled Javascript or you want to know live stats it can be pretty useless. Developing our own can be much more versatile as [...]]]></description>
			<content:encoded><![CDATA[<p>Although Google analytics can tell us a lot about who is visiting our websites it is still flawed in many ways. Google analytics is a powerful tool but if the user has disabled Javascript or you want to know live stats it can be pretty useless.</p>
<p>Developing our own can be much more versatile as we can gather information straight from the server using PHP&#8217;s Predefined variables.</p>
<p>You can add your own version of with a database and a few lines of PHP code.</p>
<pre class="php" name="code">
$time = mktime();
if (isset($_SERVER['REQUEST_METHOD'])) {   // HTTP-method
   $method = $_SERVER['REQUEST_METHOD'];
} else {
   $method = "";
}
if (isset($_SERVER['REMOTE_ADDR'])) {      // IP-adress
   $ip_adress = $_SERVER['REMOTE_ADDR'];
} else {
   $ip_adress = "";
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {  // Browser
   $browser = $_SERVER['HTTP_USER_AGENT'];
} else {
   $browser = "";
}
if (isset($_SERVER['PHP_SELF'])) {         // Current page
   $page = $_SERVER['PHP_SELF'];
} else {
   $page = "";
}
if (isset($_SERVER['HTTP_REFERER'])) {    // Previous page
   $referer = $_SERVER['HTTP_REFERER'];
} else {
   $referer = "";
}

$sql="INSERT INTO user_log (time, method, page, referer, adress, browser) // Insert into database as new row
					VALUES('$time','$method','$page','$referer','$ip_adress','$browser')";
mysql_query($sql);</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/tracking-visitors-with-php-and-predefined-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP foreach loop through post request</title>
		<link>http://www.open-source-web.com/php/php-foreach-loop-through-post-request/</link>
		<comments>http://www.open-source-web.com/php/php-foreach-loop-through-post-request/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 21:48:49 +0000</pubDate>
		<dc:creator>Adi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[request]]></category>

		<guid isPermaLink="false">http://www.open-source-web.com/?p=22</guid>
		<description><![CDATA[I use a variation of this code on most websites I have coded as it is versitile and full of uses when working with dynamic content. An example might be reusing the same mail() function for differant forms, you could loop through what is posted to it and print it out in the body of [...]]]></description>
			<content:encoded><![CDATA[<p>I use a variation of this code on most websites I have coded as it is versitile and full of uses when working with dynamic content.  An example might be reusing the same mail() function for differant forms, you could loop through what is posted to it and print it out in the body of the mail.</p>
<p>The foreach loop will process each of the requests set to the page. The $_REQUEST can be changed to just $_POST to check only posted form data or any other type of request.</p>
<p>The following loop contains a few examples of what you could do with the request once you have it.</p>
<pre name="code" class="php">
foreach ($_REQUEST as $key =&gt; $value)
{
$value = mysql_real_escape_string( $value );
$value = addslashes($value);
$value = strip_tags($value);
if($value != ""){$requestnumber ++;}
echo $key. ' - '.$value.'&lt;/br&gt;';
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.open-source-web.com/php/php-foreach-loop-through-post-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
