<?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>Webmaster-Source &#187; PHP/AJAX</title>
	<atom:link href="https://www.webmaster-source.com/tag/phpajax/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.webmaster-source.com</link>
	<description>Useful Resources For Webmasters</description>
	<lastBuildDate>Thu, 24 Aug 2017 02:01:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Book Rotation: Randomly Display Your Favorite Books</title>
		<link>https://www.webmaster-source.com/2007/09/20/book-rotation-randomly-display-your-favorite-books/</link>
		<comments>https://www.webmaster-source.com/2007/09/20/book-rotation-randomly-display-your-favorite-books/#comments</comments>
		<pubDate>Thu, 20 Sep 2007 12:33:30 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP/AJAX]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/2007/09/20/book-rotation-randomly-display-your-favorite-books/</guid>
		<description><![CDATA[This tutorial will teach you how to build a &#8220;Book Rotation.&#8221; On pageload, it picks a random book from a list of your favorites, and displays it&#8217;s title and cover, linking to it&#8217;s Amazon page with an affiliate link. You can see it in action here (look in the sidebar). Still interested? Okay, let&#8217;s get [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img src="http://i18.tinypic.com/4kozgjr.jpg" alt="" hspace="5" vspace="5" width="200" height="159" align="right" />This tutorial will teach you how to build a &#8220;Book Rotation.&#8221; On pageload, it picks a random book from a list of your favorites, and displays it&#8217;s title and cover, linking to it&#8217;s Amazon page with an affiliate link. You can <a href="http://blogs.ntugo.com/books/">see it in action here</a> (look in the sidebar). Still interested? Okay, let&#8217;s get started then.</p>
<p>First of all, log-in to <a href="http://associates.amazon.com">Amazon Associates</a>. If you don&#8217;t have an account yet, you might want to get one. Associates is an affiliate program where you earn commissions for referring customers to Amazon. If one of your users clicks on one of your referral link, and buys something from Amazon withing 24 hours, you earn a commission (up to 8%) of anything they buy. Once you&#8217;re logged in, head over to the &#8220;Build Links&#8221; page. You want the &#8220;Product Links&#8221; option (you&#8217;re screen should look something like the screenshot below).<span id="more-207"></span></p>
<p><img src="http://i15.tinypic.com/4t8rojn.jpg" alt="" /></p>
<p>Now, we&#8217;re going to need this later, so keep the window/tab open.</p>
<p>Do you know <a href="http://php.net">PHP</a>? If so, then you will have no trouble understanding the next part. Even if you don&#8217;t know what the heck &#8220;PHP&#8221; is, you&#8217;ll still be able to do the rest of the tutorial (just pay attention).</p>
<p>Open a copy of Notepad, or another plaintext editor and copy/paste the following code into it (note: I had to truncate the Amazon URLs because they don&#8217;t fit into my blog template):</p>
<p><code>&lt;?php<br />
$numberofads=6; // Change the numeral '6' to match the number of books in the rotation.<br />
</code></p>
<p><code>//Get Random Number<br />
$ad=rand(1, $numberofads);</code></p>
<p>//The images</p>
<p><code><br />
if ($ad==1) {<br />
$url="http://www.amazon.com/gp/product/0440418321?ie=UTF8&amp;tag=webmasterso0d-20[...]";<br />
$banner="http://g-ec2.images-amazon.com/images/I/214AbjNUu3L._AA_SL160_.jpg";<br />
$alt="The Golden Compass";<br />
}<br />
if ($ad==2) {<br />
$url="http://www.amazon.com/gp/product/0689303173?ie=UTF8&amp;tag=webmasterso0d</code><code>[...]</code><code>";<br />
$banner="http://ec1.images-amazon.com/images/I/31HQVBu7-zL._AA_SL160_.jpg";<br />
$alt="The Dark is Rising";<br />
}<br />
if ($ad==3) {<br />
$url="http://www.amazon.com/gp/product/037581468X?ie=UTF8&amp;tag=webmasterso0d-20</code><code>[...]</code><code>";<br />
$banner="http://ec1.images-amazon.com/images/I/2138ZDE2CAL._AA_SL160_.jpg";<br />
$alt="Terrier";<br />
}<br />
if ($ad==4) {<br />
$url="http://www.amazon.com/gp/product/0375814663?ie=UTF8&amp;tag=webmasterso0d-20</code><code>[...]</code><code>";<br />
$banner="http://ec1.images-amazon.com/images/I/21B6M4750RL._AA_SL160_.jpg";<br />
$alt="Trickster's Choice";<br />
}<br />
if ($ad==5) {<br />
$url="http://www.amazon.com/gp/product/0345340248?ie=UTF8&amp;tag=webmasterso0d-20</code><code>[...]</code><code>";<br />
$banner="http://ec1.images-amazon.com/images/I/21HFSDJXd%2BL._AA_SL160_.jpg";<br />
$alt="The Dragonriders of Pern";<br />
}<br />
if ($ad==6) {<br />
$url="http://www.amazon.com/gp/product/0439887453?ie=UTF8&amp;tag=webmasterso0d-20</code><code>[...]</code><code>";<br />
$banner="http://ec1.images-amazon.com/images/I/210R9Q6SE9L._AA_SL160_.jpg";<br />
$alt="Harry Potter books 1-7";<br />
}</code></p>
<p>//Output<br />
echo &#8216;&lt;a href=&#8221;&#8216;.$url.'&#8221;&gt;&#8217;.$alt.'&lt;/a&gt;&lt;br /&gt;';<br />
echo &#8216;&lt;a href=&#8221;&#8216;.$url.'&#8221;&gt;';<br />
echo &#8216;&lt;img src=&#8221;&#8216;.$banner.'&#8221; alt=&#8221;&#8216;.$alt.'&#8221; /&gt;';<br />
echo &#8216;&lt;/a&gt;';<br />
?&gt;</p>
<p>Did you paste that into Notepad? Good. Let me explain the code a little. The line <code>$numberofads=6;</code> means &#8220;there are six books in the rotation.&#8221; After editing the books in the rotation, you need to update this to match the number of books you have.  Other than that (and the book codes themselves) there&#8217;s not anything that needs changing.</p>
<p>Now, for each book in the rotation, there&#8217;s a block of code that looks like this:</p>
<p><code>if ($ad==1) {<br />
$url="http://www.amazon.com/gp/product/0440418321?ie=UTF8&amp;tag=webmasterso0d-20</code><code>[...]</code><code>";<br />
$banner="http://g-ec2.images-amazon.com/images/I/214AbjNUu3L._AA_SL160_.jpg";<br />
$alt="The Golden Compass";<br />
}</code></p>
<p>It&#8217;s nowhere near as complicated as it looks. The <code>$ad==1</code> part means that this is entry number one in the list of books. Each entry must have it&#8217;s own unique number (it doesn&#8217;t affect the display order, since that&#8217;s random). The <code> $url="http://www.amazon.com/gp/[...]";</code> part is the Amazon Affiliate link, while the part that looks like <code> $banner="http://g-ec2.images-amazon.com/[...]";</code> is the URL to the image of the book&#8217;s cover. The <code> $alt="The Golden Compass";</code> part is the title of the book.</p>
<p>Here&#8217;s how you add a new book to the rotation:</p>
<p><strong>Step 1:</strong> Add a new code block like the one shown above (the <code>if ($ad==1) { [...] }</code> thing).</p>
<p><strong>Step 2:</strong> On the Amazon Associates &#8220;Product Links&#8221; page, search for the book you want to add (set the dropdown to &#8220;Books&#8221;). Find the relevant result, and click the &#8220;Get HTML&#8221; button next to it.</p>
<p><strong>Step 3:</strong> In the &#8220;Select Link Type&#8221; area, pick &#8220;Image Only.&#8221; Now, do you see the &#8220;Preview&#8221; to the right? Just right-click the image and choose &#8220;Copy image location&#8221; (in Firefox. The option name may be different in IE). You&#8217;ve got the image url now, so paste it into the<code> $banner="[...]"</code> area. Down, on the same page, there&#8217;s a scrolling box marked &#8220;Get HTML Code For This Product Link.&#8221; In the box, you&#8217;ll see a part that looks something like this:</p>
<p><code>&lt;a href="http://www.amazon.com/gp/product/0545010225?ie=UTF8&amp;[...]"&gt;</code></p>
<p>Look familiar? The URL is the link you need to paste into the <code> $url="[...]"</code> area.</p>
<p><strong>Step 4:</strong> Change alt=&#8221;The Golden Compass&#8221;  to the title of the book.</p>
<p><strong>Step 5:</strong> This step only applies if you&#8217;re adding a new book instead of replacing an existing one. Change the numeral in <code>if ($ad==1) {</code> to be a unique number. Then update the <code> $numberofads=6;</code> line.</p>
<p>Once you&#8217;ve finished editing the code, save it as something like &#8220;bookrotation.php&#8221; and FTP it to your web host. Once you&#8217;ve done this, paste the following line of code into your blog template in the spot where you want the rotation to appear:</p>
<p><code>&lt;?php include="[URL to Rotation File]"; ?&gt;</code></p>
<p>This will work only if your blog template is a .php-type file. WordPress users are okay here, though some of you may not be able to do this.</p>
<p>If all is well, your rotation should be working.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2007/09/20/book-rotation-randomly-display-your-favorite-books/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Merging RSS Feeds With SimplePie</title>
		<link>https://www.webmaster-source.com/2007/08/06/merging-rss-feeds-with-simplepie/</link>
		<comments>https://www.webmaster-source.com/2007/08/06/merging-rss-feeds-with-simplepie/#comments</comments>
		<pubDate>Mon, 06 Aug 2007 14:04:24 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP/AJAX]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/2007/08/06/merging-rss-feeds-with-simplepie/</guid>
		<description><![CDATA[Have you played around with SimplePie? If not, start experimenting. SimplePie is an amazingly useful file you include in your PHP scripts so you can parse RSS feeds. It&#8217;s fast, it&#8217;s powerful, it&#8217;s easy to use, and there&#8217;s a lot you can do with it. In addition to the ordinary stuff, like displaying feed content [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img src="http://i17.tinypic.com/675l5xv.jpg" alt="" hspace="5" vspace="5" width="128" height="128" align="right" />Have you played around with <a href="http://www.webmaster-source.com/2007/08/05/simplepie-parse-rss-with-php/">SimplePie</a>? If not, start experimenting. SimplePie is an amazingly useful file you include in your <a href="http://en.wikipedia.org/wiki/PHP">PHP</a> scripts so you can parse RSS feeds. It&#8217;s fast, it&#8217;s powerful, it&#8217;s easy to use, and there&#8217;s a lot you can do with it.</p>
<p>In addition to the ordinary stuff, like displaying feed content on your website, you can also utilize SimplePie for more interesting things&#8230;.like combining RSS feeds. Why would you want to do that? Well, some of us have multiple blogs. Using SimplePie you can create a feed that aggregates all of your blogs&#8217; feeds. Blog networks may find this technique useful as well.<span id="more-150"></span></p>
<p>How do you merge feeds? It&#8217;s actually quite simple. Your script should do the following:</p>
<ul>
<li>Echo the beginning of the XML (the character encoding must be UTF-8)</li>
<li>Load simplepie.inc</li>
<li>Store all the original feeds in an array</li>
<li>Initialize SimplePie</li>
<li>Loop around echoing the aggregated RSS items</li>
<li>Echo the end of the XML</li>
</ul>
<p>Not too complex, eh? Let&#8217;s get coding!</p>
<p>First you need to output the beginning of the XML structure</p>
<p><strong> &lt;?php echo &#8216;&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;'; ?&gt;<br />
&lt;rss version=&#8221;2.00&#8243;&gt;<br />
&lt;channel&gt;<br />
&lt;title&gt;Aggregated Feed Demo&lt;/title&gt;<br />
&lt;link&gt;http://www.webmaster-source.com&lt;/link&gt;<br />
&lt;description&gt;<br />
A demo of SimplePie&#8217;s feed-merging capabilities.<br />
&lt;/description&gt;<br />
&lt;language&gt;en-us&lt;/language&gt;</strong></p>
<p>Just basic XML. Note that you need to use UTF-8 encoding, otherwise you could have some oddities in the feed. SimplePie prefers UTF-8, and can be a little buggy with other encodings.</p>
<p>Next, the script takes care of some SimplePie stuff and loads the RSS feeds.</p>
<p><strong> &lt;?php<br />
include_once(&#8216;./lib/php/simplepie.inc&#8217;); // Include SimplePie</strong></p>
<p><strong>$feed = new SimplePie(); // Create a new instance of SimplePie</strong></p>
<p><strong>// Load the feeds<br />
$feed-&gt;set_feed_url(array(<br />
&#8216;http://feeds.feedburner.com/Webmaster-source&#8217;,<br />
&#8216;http://feeds.feedburner.com/ProbloggerHelpingBloggersEarnMoney&#8217;<br />
));</strong></p>
<p><strong>$feed-&gt;set_cache_duration (600); // Set the cache time</strong></p>
<p><strong>$feed-&gt;enable_xml_dump(isset($_GET[&#8216;xmldump&#8217;]) ? true : false);</strong></p>
<p><strong>$success = $feed-&gt;init(); // Initialize SimplePie</strong></p>
<p><strong>$feed-&gt;handle_content_type(); // Take care of the character encoding<br />
?&gt;</strong></p>
<p>The only things you really need to change above are the feed URLs and the path to simplepie.inc. Now for the fun part. Let&#8217;s output ten RSS items, shall we?</p>
<p><strong> &lt;?php if ($success) {<br />
$itemlimit=0;<br />
foreach($feed-&gt;get_items() as $item) {<br />
if ($itemlimit==10) { break; }<br />
?&gt;</strong></p>
<p><strong>&lt;item&gt;<br />
&lt;title&gt;&lt;?php echo $item-&gt;get_title(); ?&gt;&lt;/title&gt;<br />
&lt;link&gt;&lt;?php echo $item-&gt;get_permalink(); ?&gt;&lt;/link&gt;<br />
&lt;description&gt;<br />
&lt;?php echo $item-&gt;get_description(); ?&gt;<br />
&lt;/description&gt;<br />
&lt;/item&gt;</strong></p>
<p><strong>&lt;?<br />
$itemlimit = $itemlimit + 1;<br />
}<br />
}<br />
?&gt;</strong></p>
<p><strong>&lt;/channel&gt;<br />
&lt;/rss&gt;</strong></p>
<p>That was easy, wasn&#8217;t it? Just save it as rss_all.php, or something similar, and upload it to your web server. Try it out. Note that it&#8217;s a good idea to use <a href="http://feedburner.com">Feedburner</a> so your server doesn&#8217;t have to process everything when a user&#8217;s RSS reader requests the feed. The <a href="http://simplepie.org">SimplePie website</a> has a <a href="http://simplepie.org/wiki/reference/start/">complete API reference</a> you may find useful. With a couple minutes of coding, you can easily add a &lt;pubDate&gt; tag to the generated feed. I highly recommend doing so, as it will make it easier for others to mix your aggregated feed with some of theirs.</p>
<p>Want to see this script in action? Take a look at <a href="http://feeds.ntugo.com/NtugoBlogs-All">this feed</a>. It has the ten most recent items from the <a href="http://blogs.ntugo.com/">NTugo Blogs</a> feeds</p>
<p><a href="http://www.webmaster-source.com/wp-content/uploads/2007/08/rssmergerphp.txt">Download TXT file</a> (copy-pasting code from blog post may not work).</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2007/08/06/merging-rss-feeds-with-simplepie/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/


Served from: www.webmaster-source.com @ 2026-06-09 00:07:21 by W3 Total Cache
-->