<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss 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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"  xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>SoftwareProjects - Internet Marketing and Web Development</title>
	<link>http://www.softwareprojects.com/images/logo.png</link>
	<description>Internet Marketing and Web Development</description>

	<generator>http://www.softwareprojects.com</generator>
	<language>en</language>

		<copyright>SoftwareProjects Inc</copyright>
		<managingEditor>support@softwareprojects.com (Adrian Singer)</managingEditor>
		<webMaster>support@softwareprojects.com</webMaster>
		<category>SoftwareProjects</category>
		<ttl>3000</ttl>

		<image>
			<url>http://www.softwareprojects.com/images/logo.png</url>
			<title>SoftwareProjects - Internet Marketing and Web Development</title>
			<link>http://www.softwareprojects.com/images/logo.png</link>
			<width>142</width>
			<height>55</height>

		</image>

<item>
<title><![CDATA[SoftwareProjects to attend Affiliate Summit West]]></title>
<link>http://www.softwareprojects.com/resources/the-platform-all-in-one/t-softwareprojects-to-attend-affiliate-sum-1928.html</link>
<pubDate>Thu, 14 Jan 2010 13:03:48 GMT</pubDate>
<dc:creator><![CDATA[Kate Richards]]></dc:creator>
<category><![CDATA[The Platform: All-In-One]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/the-platform-all-in-one/t-softwareprojects-to-attend-affiliate-sum-1928.html</guid>
<description><![CDATA[<a href="http://www.affiliatesummit.com" target="_blank">Affiliate Summit</a> Las Vegas is the largest gathering of affiliates, merchants and pay-by-performance networks.<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/c0wnNiaffsummitwest.jpg" border="0" alt="" /><br />
<br />
SoftwareProjects is sending a small team of rainmakers to meet and network with our respected clients and partners.<br />
<br />
We will be blogging live from the event, covering session highlights here on SoftwareProjects.com<br />
<br />
If you'd like to get together and learn why more than 3,000 businesses in 14 countries rely on SoftwareProjects when it comes to Shopping Carts, Product Launches, PPC, Email Marketing and Software Development,  please drop a comment here or <a href="http://www.softwareprojects.com/support_email.php" target="_blank">email us</a> to setup a meeting.<br />
<br />
See you in Vegas!]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/the-platform-all-in-one/t-softwareprojects-to-attend-affiliate-sum-1928.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/the-platform-all-in-one/t-softwareprojects-to-attend-affiliate-sum-1928.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[How to fix Mercurial Corrupt Repository]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-how-to-fix-mercurial-corrupt-repository-1926.html</link>
<pubDate>Fri, 08 Jan 2010 02:17:33 GMT</pubDate>
<dc:creator><![CDATA[Liviu Olos]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-how-to-fix-mercurial-corrupt-repository-1926.html</guid>
<description><![CDATA[If you're using <a href="http://www.softwareprojects.com/resources/programming/t-mercurial-version-control-1853.html" target="_blank">Mercurial HG</a> and keep running into the "premature EOF reading chunk" error, there's hope.  As part of this post, I will walk you through the process of repairing a damaged repository where HG .i files are corrupt and no one can successfully "Pull Changes".<br />
<br />
<b>Step 1:</b> Connect to your HG server, cd to the repository folder and run<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">hg verify</code><hr />
</div>
<br />
If you get something like <br />
<br />
<div style="margin:20px; margin-top:5px; ">
	<div class="smallfont" style="margin-bottom:2px">Quote:</div>
	<table cellpadding="6" cellspacing="0" border="0" width="100%">
	<tr>
		<td class="alt2">
			<hr />
			
				    error_file_name.extension@553: unpacking 646ac1c08e97: ./../Objects/stringobject.c:4124: bad argument to internal function<br />
    10662 files, 567 changesets, 11475 total revisions<br />
    1 integrity errors encountered!
			
			<hr />
		</td>
	</tr>
	</table>
</div>
<br />
Voila, you're dealing with HG index corruption.<br />
<br />
<b>Step 2:</b> Backup the file  <i>path_to_project/.hg/store/data/error_file_name.extension.i  backup/error_file_name.extension.i</i><br />
<br />
<b>Step 3:</b>  In the <i>path_to_project/</i> folder create a new empty file<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">echo "" >> new_file.extension</code><hr />
</div>
<br />
<b>Step 4:</b> <br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">hg add new_file.extension</code><hr />
</div>
<br />
<b>Step 5: </b><br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">hg commit</code><hr />
</div>
<br />
You might need to do <i>hg commit -u hg_user_name</i><br />
<br />
<b>Step 6:</b> Go to <i>path_to_project/.hg/store/data/</i> and<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">cp new_file.extension.i error_file_name.extension.i</code><hr />
</div>
<br />
This will replace the current file<br />
<br />
<b>Step 7:</b> Pull the files from your local HG client and you should be all set!<br />
 <br />
-<br />
<br />
<b>Tip: </b>To avoid unnecessary merges, always "Pull Changes" - "Commit" and "Push" as close to each other as possible.]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-how-to-fix-mercurial-corrupt-repository-1926.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-how-to-fix-mercurial-corrupt-repository-1926.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[iContact 2.0 API Integration PHP Example]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-icontact-20-api-integration-php-example-1925.html</link>
<pubDate>Fri, 25 Dec 2009 05:12:15 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-icontact-20-api-integration-php-example-1925.html</guid>
<description><![CDATA[One of the cool features of <a href="http://www.softwareprojects.com/selling-online/spi-autoresponder-manager" target="_blank">SPI's Autoresponder service</a>, is its ability to seamlessly integrate with third party autoresponders.<br />
<br />
Once you designate an autoresponder as a third-party one, SPI will continue applying your predefined rules for adding/removing members from that autoresponder, while notifying the third-party service (GetResponse, iContact, AWeber) automatically.<br />
<br />
Over the last few days, we have battling with iContact's new API.  iContact announced their 2.0 API back on February 2009, but it's still labeled as <a href="http://app.icontact.com/icp/pub/api/doc/api.html" target="_blank">"beta"</a> and there's little to no documentation available online.<br />
<br />
The SPI-iContact integration was using version 1.0 and our intention was to continue using that version until 2.0 is officially released.<br />
<br />
Unfortunately, with no prior warning, version 1.0 stopped working and is no longer honoring requests to add contacts / subscriptions records.<br />
<br />
iContact's API <a href="http://www.icontact.com/icp/core/externallogin" target="_blank">external login page</a> is down.  The help section is down:<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/88d1e020.png" border="0" alt="" /><br />
<br />
And the developer forums are <a href="http://www.icontact.com/forums/topic-647.html" target="_blank">ghost town USA</a>.<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/a63458b4.png" border="0" alt="" /><br />
<br />
Ok, rant over.  <br />
<br />
We really like the folks at iContact.  They offer an easy to use and inexpensive entry-level autoresponder service.  I just wish they would update the API documentation.<br />
<br />
The purpose of this post is to help others who are going through integrating with the iContact 2.0 API by providing  simple PHP examples for adding a contract, subscripting a contact to a list and unsubscribing.<br />
<br />
We haven't been able to find anything like this online, so I'm pretty sure this will help others going through the integration process.<br />
<br />
The code below is self-contained.  No need to use any other libraries.  <br />
<br />
<div style="margin:10px;  padding:4px; border:1px inset; background-color: #FDF8EB">

	<span style="margin:0px; width:550px; padding:4px;  overflow:auto; "><font face="courier new"> <br /></font><font color="#006600">function </font><font color="#0000CC">IContactLogin</font><font color="#006600">(</font><font color="#0000CC">$account_id</font><font color="#006600">, </font><font color="#0000CC">$key</font><font color="#006600">, </font><font color="#0000CC">$user</font><font color="#006600">, </font><font color="#0000CC">$pass</font><font color="#006600">, &amp;</font><font color="#0000CC">$client_folder_id</font><font color="#006600">)<br />{<br />&nbsp; </font><font color="#FF9900">// Build iContact authentication <br />&nbsp; </font><font color="#0000CC">$headers </font><font color="#006600">= array(<br />&nbsp; </font><font color="#CC0000">'Accept: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Content-Type: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Version: 2.0'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-AppId: ' </font><font color="#006600">. </font><font color="#0000CC">$key</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Username: ' </font><font color="#006600">. </font><font color="#0000CC">$user</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Password: ' </font><font color="#006600">. </font><font color="#0000CC">$pass<br />&nbsp; </font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Connect to iContact to retrieve the client folder id<br />&nbsp; </font><font color="#0000CC">$ch</font><font color="#006600">=</font><font color="#0000CC">curl_init</font><font color="#006600">(</font><font color="#CC0000">"https://app.icontact.com/icp/a/$account_id/c/"</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_HTTPHEADER</font><font color="#006600">, </font><font color="#0000CC">$headers</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_RETURNTRANSFER</font><font color="#006600">, </font><font color="#0000CC">true</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_SSL_VERIFYHOST</font><font color="#006600">, </font><font color="#0000CC">false</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">$buf </font><font color="#006600">= </font><font color="#0000CC">curl_exec</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_close</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Extract client folder id from response<br />&nbsp; </font><font color="#0000CC">$client_folder_id </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">;<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"&lt;clientFolderId&gt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$client_folder_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">, </font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"&lt;clientFolderId&gt;"</font><font color="#006600">)+</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$client_folder_id</font><font color="#006600">,</font><font color="#CC0000">"&lt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$client_folder_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$client_folder_id</font><font color="#006600">, </font><font color="#0000CC">0</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// If we have a non empty client_folder_id,<br />&nbsp; // then everything worked well<br />&nbsp; </font><font color="#0000CC">$result </font><font color="#006600">= (</font><font color="#0000CC">$client_folder_id</font><font color="#006600">+</font><font color="#0000CC">0 </font><font color="#006600">&gt; </font><font color="#0000CC">0</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Return result<br />&nbsp; </font><font color="#006600">return </font><font color="#0000CC">$result</font><font color="#006600">;<br />}<br /><br /><br />function </font><font color="#0000CC">IContactSubscribe</font><font color="#006600">(</font><font color="#0000CC">$account_id</font><font color="#006600">, </font><font color="#0000CC">$key</font><font color="#006600">, </font><font color="#0000CC">$user</font><font color="#006600">, </font><font color="#0000CC">$pass</font><font color="#006600">, </font><font color="#0000CC">$email</font><font color="#006600">, </font><font color="#0000CC">$list_id</font><font color="#006600">, &amp;</font><font color="#0000CC">$result_str</font><font color="#006600">)<br />{<br />&nbsp; </font><font color="#FF9900">// Get client folder id<br />&nbsp; </font><font color="#006600">if (!</font><font color="#0000CC">IContactLogin</font><font color="#006600">(</font><font color="#0000CC">$account_id</font><font color="#006600">, </font><font color="#0000CC">$key</font><font color="#006600">, </font><font color="#0000CC">$user</font><font color="#006600">, </font><font color="#0000CC">$pass</font><font color="#006600">, &amp;</font><font color="#0000CC">$client_folder_id</font><font color="#006600">))<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= </font><font color="#CC0000">"Failed retrieving client_folder_id for '$user'"</font><font color="#006600">;<br />&nbsp; &nbsp; return </font><font color="#0000CC">0</font><font color="#006600">;<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// Build iContact authentication<br />&nbsp; </font><font color="#0000CC">$headers </font><font color="#006600">= array(<br />&nbsp; </font><font color="#CC0000">'Accept: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Content-Type: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Version: 2.0'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-AppId: ' </font><font color="#006600">. </font><font color="#0000CC">$key</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Username: ' </font><font color="#006600">. </font><font color="#0000CC">$user</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Password: ' </font><font color="#006600">. </font><font color="#0000CC">$pass<br />&nbsp; </font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Find contact_id for the given 'email'<br />&nbsp; </font><font color="#0000CC">$ch</font><font color="#006600">=</font><font color="#0000CC">curl_init</font><font color="#006600">(</font><font color="#CC0000">"https://app.icontact.com/icp/a/$account_id/c/$client_folder_id/contacts/?email="</font><font color="#006600">.</font><font color="#0000CC">URLEncode</font><font color="#006600">(</font><font color="#0000CC">$email</font><font color="#006600">));<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_HTTPHEADER</font><font color="#006600">, </font><font color="#0000CC">$headers</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_RETURNTRANSFER</font><font color="#006600">, </font><font color="#0000CC">true</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_SSL_VERIFYHOST</font><font color="#006600">, </font><font color="#0000CC">false</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">$buf </font><font color="#006600">= </font><font color="#0000CC">curl_exec</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_close</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Extract contactId from response<br />&nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">;<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"&lt;contactId&gt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"&lt;contactId&gt;"</font><font color="#006600">));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$contact_id</font><font color="#006600">,</font><font color="#CC0000">"&lt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$contact_id</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// If we don't have a contactId, can't add subscription<br />&nbsp; </font><font color="#006600">if (empty(</font><font color="#0000CC">$contact_id</font><font color="#006600">))<br />&nbsp; {&nbsp; <br />&nbsp; &nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= </font><font color="#CC0000">"Failed finding a contact with the email address of '$email'"</font><font color="#006600">;<br />&nbsp; &nbsp; return </font><font color="#0000CC">0</font><font color="#006600">;<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// Build subscription record<br />&nbsp; </font><font color="#0000CC">$data </font><font color="#006600">= </font><font color="#CC0000">'&lt;?xml version="1.0" encoding="UTF-8"?&gt;'</font><font color="#006600">.</font><font color="#CC0000">"\r\n&lt;subscriptions&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;subscription&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;contactId&gt;$contact_id&lt;/contactId&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;listId&gt;$list_id&lt;/listId&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;status&gt;normal&lt;/status&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;/subscription&gt;\r\n&lt;/subscriptions&gt;"</font><font color="#006600">;<br /><br />&nbsp; </font><font color="#FF9900">// Add subscription<br />&nbsp; </font><font color="#0000CC">$ch</font><font color="#006600">=</font><font color="#0000CC">curl_init</font><font color="#006600">(</font><font color="#CC0000">"https://app.icontact.com/icp/a/$account_id/c/$client_folder_id/subscriptions/"</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_HTTPHEADER</font><font color="#006600">, </font><font color="#0000CC">$headers</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_POSTFIELDS</font><font color="#006600">, </font><font color="#0000CC">$data</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_RETURNTRANSFER</font><font color="#006600">, </font><font color="#0000CC">true</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_SSL_VERIFYHOST</font><font color="#006600">, </font><font color="#0000CC">false</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">$buf </font><font color="#006600">= </font><font color="#0000CC">curl_exec</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_close</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Extract subscriptionID from response<br />&nbsp; </font><font color="#0000CC">$subscription_id </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">;<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"&lt;subscriptionId&gt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$subscription_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"&lt;subscriptionId&gt;"</font><font color="#006600">));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$subscription_id</font><font color="#006600">,</font><font color="#CC0000">"&lt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$subscription_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$subscription_id</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// If we have a subscription id OR this subscription already existed, we're good<br />&nbsp; </font><font color="#0000CC">$result </font><font color="#006600">= !empty(</font><font color="#0000CC">$subscription_id</font><font color="#006600">) || </font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"could not be updated"</font><font color="#006600">)!==</font><font color="#0000CC">false</font><font color="#006600">;<br /><br />&nbsp; </font><font color="#FF9900">// Set result string<br />&nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= (</font><font color="#0000CC">$result </font><font color="#006600">? </font><font color="#CC0000">"Updated subscription $subscription_id" </font><font color="#006600">: </font><font color="#0000CC">$buf</font><font color="#006600">); <br /><br />&nbsp; </font><font color="#FF9900">// Return result<br />&nbsp; </font><font color="#006600">return </font><font color="#0000CC">$result</font><font color="#006600">;<br />}<br /><br />function </font><font color="#0000CC">IContactAddContact</font><font color="#006600">(</font><font color="#0000CC">$account_id</font><font color="#006600">, </font><font color="#0000CC">$key</font><font color="#006600">, </font><font color="#0000CC">$user</font><font color="#006600">, </font><font color="#0000CC">$pass</font><font color="#006600">, </font><font color="#0000CC">$email</font><font color="#006600">, </font><font color="#0000CC">$firstname</font><font color="#006600">, </font><font color="#0000CC">$lastname</font><font color="#006600">,<br />&amp;</font><font color="#0000CC">$result_str</font><font color="#006600">)<br />{<br />&nbsp; </font><font color="#FF9900">// Get client folder id<br />&nbsp; </font><font color="#006600">if (!</font><font color="#0000CC">IContactLogin</font><font color="#006600">(</font><font color="#0000CC">$account_id</font><font color="#006600">, </font><font color="#0000CC">$key</font><font color="#006600">, </font><font color="#0000CC">$user</font><font color="#006600">, </font><font color="#0000CC">$pass</font><font color="#006600">, &amp;</font><font color="#0000CC">$client_folder_id</font><font color="#006600">))<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= </font><font color="#CC0000">"Failed retrieving client_folder_id for '$user'"</font><font color="#006600">;<br />&nbsp; &nbsp; return </font><font color="#0000CC">0</font><font color="#006600">;<br />&nbsp; }<br />&nbsp;  <br />&nbsp; </font><font color="#FF9900">// Build iContact authentication<br />&nbsp; </font><font color="#0000CC">$headers </font><font color="#006600">= array(<br />&nbsp; </font><font color="#CC0000">'Accept: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Content-Type: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Version: 2.0'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-AppId: ' </font><font color="#006600">. </font><font color="#0000CC">$key</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Username: ' </font><font color="#006600">. </font><font color="#0000CC">$user</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Password: ' </font><font color="#006600">. </font><font color="#0000CC">$pass<br />&nbsp; </font><font color="#006600">);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; </font><font color="#FF9900">// Build contact record<br />&nbsp; </font><font color="#0000CC">$data </font><font color="#006600">= </font><font color="#CC0000">'&lt;?xml version="1.0" encoding="UTF-8"?&gt;'</font><font color="#006600">.</font><font color="#CC0000">"\r\n&lt;contacts&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;contact&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;email&gt;$email&lt;/email&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;firstName&gt;$firstname&lt;/firstName&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;lastName&gt;$lastname&lt;/lastName&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;status&gt;normal&lt;/status&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;/contact&gt;\r\n&lt;/contacts&gt;"</font><font color="#006600">;<br /><br />&nbsp;    </font><font color="#FF9900">// Add contact  <br />&nbsp; </font><font color="#0000CC">$ch</font><font color="#006600">=</font><font color="#0000CC">curl_init</font><font color="#006600">(</font><font color="#CC0000">"https://app.icontact.com/icp/a/$account_id/c/$client_folder_id/contacts/"</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_HTTPHEADER</font><font color="#006600">, </font><font color="#0000CC">$headers</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_POSTFIELDS</font><font color="#006600">, </font><font color="#0000CC">$data</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_RETURNTRANSFER</font><font color="#006600">, </font><font color="#0000CC">true</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_SSL_VERIFYHOST</font><font color="#006600">, </font><font color="#0000CC">false</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">$buf </font><font color="#006600">= </font><font color="#0000CC">curl_exec</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_close</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Extract contactId from response<br />&nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">;<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"&lt;contactId&gt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"&lt;contactId&gt;"</font><font color="#006600">));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$contact_id</font><font color="#006600">,</font><font color="#CC0000">"&lt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$contact_id</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// If we have a contact id, we're good<br />&nbsp; </font><font color="#0000CC">$result </font><font color="#006600">= !empty(</font><font color="#0000CC">$contact_id</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Set result string<br />&nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= (</font><font color="#0000CC">$result </font><font color="#006600">? </font><font color="#CC0000">"Added new contact $contact_id" </font><font color="#006600">: </font><font color="#0000CC">$buf</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Return result<br />&nbsp; </font><font color="#006600">return </font><font color="#0000CC">$result</font><font color="#006600">;<br />}<br /><br />function </font><font color="#0000CC">IContactUnsubscribe</font><font color="#006600">(</font><font color="#0000CC">$account_id</font><font color="#006600">, </font><font color="#0000CC">$key</font><font color="#006600">, </font><font color="#0000CC">$user</font><font color="#006600">, </font><font color="#0000CC">$pass</font><font color="#006600">, </font><font color="#0000CC">$email</font><font color="#006600">, </font><font color="#0000CC">$list_id</font><font color="#006600">, &amp;</font><font color="#0000CC">$result_str</font><font color="#006600">)<br />{<br />&nbsp; </font><font color="#FF9900">// Get client folder id<br />&nbsp; </font><font color="#006600">if (!</font><font color="#0000CC">IContactLogin</font><font color="#006600">(</font><font color="#0000CC">$account_id</font><font color="#006600">, </font><font color="#0000CC">$key</font><font color="#006600">, </font><font color="#0000CC">$user</font><font color="#006600">, </font><font color="#0000CC">$pass</font><font color="#006600">, &amp;</font><font color="#0000CC">$client_folder_id</font><font color="#006600">))<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= </font><font color="#CC0000">"Failed retrieving client_folder_id for '$user'"</font><font color="#006600">;<br />&nbsp; &nbsp; return </font><font color="#0000CC">0</font><font color="#006600">;<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// Build iContact authentication<br />&nbsp; </font><font color="#0000CC">$headers </font><font color="#006600">= array(<br />&nbsp; </font><font color="#CC0000">'Accept: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Content-Type: text/xml'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Version: 2.0'</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-AppId: ' </font><font color="#006600">. </font><font color="#0000CC">$key</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Username: ' </font><font color="#006600">. </font><font color="#0000CC">$user</font><font color="#006600">,<br />&nbsp; </font><font color="#CC0000">'Api-Password: ' </font><font color="#006600">. </font><font color="#0000CC">$pass<br />&nbsp; </font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Find contact_id for the given 'email'<br />&nbsp; </font><font color="#0000CC">$ch</font><font color="#006600">=</font><font color="#0000CC">curl_init</font><font color="#006600">(</font><font color="#CC0000">"https://app.icontact.com/icp/a/$account_id/c/$client_folder_id/contacts/?email="</font><font color="#006600">.</font><font color="#0000CC">URLEncode</font><font color="#006600">(</font><font color="#0000CC">$email</font><font color="#006600">));<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_HTTPHEADER</font><font color="#006600">, </font><font color="#0000CC">$headers</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_RETURNTRANSFER</font><font color="#006600">, </font><font color="#0000CC">true</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_SSL_VERIFYHOST</font><font color="#006600">, </font><font color="#0000CC">false</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">$buf </font><font color="#006600">= </font><font color="#0000CC">curl_exec</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_close</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Extract contactId from response<br />&nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">;<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"&lt;contactId&gt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"&lt;contactId&gt;"</font><font color="#006600">));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$contact_id</font><font color="#006600">,</font><font color="#CC0000">"&lt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$contact_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$contact_id</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// If we don't have a contactId, can't add subscription<br />&nbsp; </font><font color="#006600">if (empty(</font><font color="#0000CC">$contact_id</font><font color="#006600">))<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= </font><font color="#CC0000">"Failed finding a contact with the email address of '$email'"</font><font color="#006600">;<br />&nbsp; &nbsp; return </font><font color="#0000CC">0</font><font color="#006600">;<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// Build subscription record<br />&nbsp; </font><font color="#0000CC">$data </font><font color="#006600">= </font><font color="#CC0000">'&lt;?xml version="1.0" encoding="UTF-8"?&gt;'</font><font color="#006600">.</font><font color="#CC0000">"\r\n&lt;subscriptions&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;subscription&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;contactId&gt;$contact_id&lt;/contactId&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;listId&gt;$list_id&lt;/listId&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;status&gt;unsubscribed&lt;/status&gt;\r\n"</font><font color="#006600">;<br />&nbsp; </font><font color="#0000CC">$data</font><font color="#006600">.= </font><font color="#CC0000">"&lt;/subscription&gt;\r\n&lt;/subscriptions&gt;"</font><font color="#006600">;<br /><br />&nbsp; </font><font color="#FF9900">// Add subscription<br />&nbsp; </font><font color="#0000CC">$ch</font><font color="#006600">=</font><font color="#0000CC">curl_init</font><font color="#006600">(</font><font color="#CC0000">"https://app.icontact.com/icp/a/$account_id/c/$client_folder_id/subscriptions/"</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_HTTPHEADER</font><font color="#006600">, </font><font color="#0000CC">$headers</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_POSTFIELDS</font><font color="#006600">, </font><font color="#0000CC">$data</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_RETURNTRANSFER</font><font color="#006600">, </font><font color="#0000CC">true</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_setopt</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">, </font><font color="#0000CC">CURLOPT_SSL_VERIFYHOST</font><font color="#006600">, </font><font color="#0000CC">false</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">$buf </font><font color="#006600">= </font><font color="#0000CC">curl_exec</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br />&nbsp; </font><font color="#0000CC">curl_close</font><font color="#006600">(</font><font color="#0000CC">$ch</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Extract subscriptionID from response<br />&nbsp; </font><font color="#0000CC">$subscription_id </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">;<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"&lt;subscriptionId&gt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$subscription_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"&lt;subscriptionId&gt;"</font><font color="#006600">));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$subscription_id</font><font color="#006600">,</font><font color="#CC0000">"&lt;"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$subscription_id </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$subscription_id</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />&nbsp; }<br /><br />&nbsp; </font><font color="#FF9900">// If we have a subscription id OR this subscription already unsubscribed, we're good<br />&nbsp; </font><font color="#0000CC">$result </font><font color="#006600">= !empty(</font><font color="#0000CC">$subscription_id</font><font color="#006600">) || </font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">,</font><font color="#CC0000">"could not be updated"</font><font color="#006600">)!==</font><font color="#0000CC">false</font><font color="#006600">;<br /><br />&nbsp; </font><font color="#FF9900">// Set result string<br />&nbsp; </font><font color="#0000CC">$result_str </font><font color="#006600">= (</font><font color="#0000CC">$result </font><font color="#006600">? </font><font color="#CC0000">"Updated subscription $subscription_id" </font><font color="#006600">: </font><font color="#0000CC">$buf</font><font color="#006600">);<br /><br />&nbsp; </font><font color="#FF9900">// Return result<br />&nbsp; </font><font color="#006600">return </font><font color="#0000CC">$result</font><font color="#006600">;<br />} </font><font color="#0000CC"></font></span></div>]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-icontact-20-api-integration-php-example-1925.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-icontact-20-api-integration-php-example-1925.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[How to run SSH on a different port]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-how-to-run-ssh-on-a-different-port-1922.html</link>
<pubDate>Mon, 21 Dec 2009 12:15:27 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-how-to-run-ssh-on-a-different-port-1922.html</guid>
<description><![CDATA[By default SSH runs on port 22.  One of the easiest ways to make it more difficult for hackers to run dictionary attacks on your server, attempting to brute-force ssh-login, is to run ssh on a different port.<br />
<br />
Open up <b>/etc/ssh/sshd_config</b> and add this line at the top:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">Port 1234</code><hr />
</div>
<br />
Replace 1234 with the port number you'd like to run ssh on.  If there is already a Port line in your sshd_config file, comment it with a #<br />
<br />
Now, Restart sshd by issuing:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">/etc/rc.d/init.d/sshd restart</code><hr />
</div>
<br />
Test ssh works properly by connecting locally (replace 1234 with the new port number): <br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">ssh -l USERNAME localhost -p 1234</code><hr />
</div>]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-how-to-run-ssh-on-a-different-port-1922.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-how-to-run-ssh-on-a-different-port-1922.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[MapReduce 101: Parallel Programming]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-mapreduce-101-parallel-programming-1919.html</link>
<pubDate>Mon, 21 Dec 2009 08:25:00 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-mapreduce-101-parallel-programming-1919.html</guid>
<description><![CDATA[Two of the best video tutorials explaining the basics of MapReduce.<br />
<br />
If you're used to MySQL, you can think of "Map" as several queries running "SELECT" where data is extracted from multiple tables.  And you can think of "Reduce" as the "GROUP BY" operator where data is joined together to form a short result.<br />
<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/mVXpvsdeuKU&amp;hl=en_US&amp;fs=1&amp;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mVXpvsdeuKU&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/zVSSsJ_ua4Q&amp;hl=en_US&amp;fs=1&amp;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/zVSSsJ_ua4Q&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
<br />
For more information about MapReduce, see <a href="http://code.google.com/edu/parallel/mapreduce-tutorial.html" target="_blank">Google's Introduction to Parallel Programming and MapReduce</a>]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-mapreduce-101-parallel-programming-1919.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-mapreduce-101-parallel-programming-1919.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[Never use VARCHAR in MySQL]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-never-use-varchar-in-mysql-1916.html</link>
<pubDate>Tue, 15 Dec 2009 19:37:28 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-never-use-varchar-in-mysql-1916.html</guid>
<description><![CDATA[When using strings in MySQL, you have a choice between several field types:<br />
<br />
* <b>VARCHAR</b>: String of 0..65,535 characters with an extra byte to designate the length.<br />
* <b>CHAR</b>: String of a fixed length of 0 to 255 characters.<br />
* <b>TEXT</b> / <b>BIGTEXT</b>: String of 1..4GB characters with an extra byte to designate the length. Unlike VARCHAR, text fields cannot be compared, can't "order by", can't use "like" on them etc.<br />
* <b>BLOB</b>: For binary or unicode strings.  Supports 8bits per character and unlike the previous types, the string is not converted to a character-set prior to insertion.<br />
<br />
Quick tip: <b>Never ever use varchar</b>.  <br />
<br />
While VARCHAR offers slightly improved storage space (it will only take up n+1 characters on disk), there are a few major pitfalls with this variable type:<br />
<br />
#1. If you have any field in the table that is a CHAR (fixed size) field, all VARCHARs will be stored as n+1, so you don't get any reduced storage benefits.<br />
<br />
#2. If you're using MySQL replication, you may end up with a few nasty "master/slave table column type mismatch" errors - this is a big one<br />
<br />
#3. CHAR fields offer better performance than VARCHAR<br />
<br />
-<br />
<br />
We first learned about the issues with VARCHAR when replication began breaking with these cryptic messages:<br />
<br />
"Table definition on master and slave does not match: Column 37 size mismatch - master has size 255, testtable on slave has size 256. Master's column size should be <= the slave's column size."<br />
<br />
Both tables were identical and mysqldump'ing one on top of the other didn't help.  It seems to be rooted to MySQL's internal implementation of VARCHAR.<br />
<br />
To convert all table VARCHAR fields to CHAR, use this code:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">@mysql_query("SET GLOBAL WAIT_TIMEOUT = 600000");<BR>@mysql_Query("SET WAIT_TIMEOUT = 600000");<BR><BR>$Result1 = @mysql_query("SHOW TABLES FROM $DBNAME");<BR>$cnt1 = @mysql_num_rows($Result1);<BR>while ($cnt1)<BR>{<BR>&nbsp; &nbsp; &nbsp; &nbsp; $cnt1--;<BR>&nbsp; &nbsp; &nbsp; &nbsp; if (!($Row1 = @mysql_fetch_array($Result1)))<BR>&nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; $tablename = $Row1[0];<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; $Result3 = @mysql_query("DESCRIBE $tablename");<BR>&nbsp; &nbsp; &nbsp; &nbsp; $cnt3 = @mysql_num_rows($Result3);<BR>&nbsp; &nbsp; &nbsp; &nbsp; while ($cnt3)<BR>&nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $cnt3--;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!($Row3 = @mysql_fetch_array($Result3))) continue;<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (strpos($Row3['Type'],'varchar')!==false)<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $pos = strpos($Row3['Type'],'(');<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $length = substr($Row3['Type'],$pos+1);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $pos = strpos($length,')');<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $length = substr($length, 0, $pos);<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // If length is over 255, nothing we can do about it<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($length>255) continue;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($length<1) continue;<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Length is below 255, we can convert<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $sql = "alter table $tablename change ".$Row3['Field']." ".$Row3['Field']." char($length) default '' not null";<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @mysql_query($sql);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>}</code><hr />
</div>]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-never-use-varchar-in-mysql-1916.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-never-use-varchar-in-mysql-1916.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[How to Flush DNS]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-how-to-flush-dns-1913.html</link>
<pubDate>Sun, 06 Dec 2009 05:23:53 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-how-to-flush-dns-1913.html</guid>
<description><![CDATA[At times you want to force your machine to "forget" (flush) all DNS entries, so that it reloads any recent changes.<br />
<br />
This is useful when you've recently updated the ip-address of a domain and want your machine to see the new changes, without relying on any previously stored cache.<br />
<br />
Here's how to flush your DNS cache:<br />
<br />
<b>Windows</b><br />
<br />
Open a CMD dos box and run:<br />
<br />
ipconfig /flushdns<br />
<br />
If you get an error about "this requires elevation", do this: Click on the Windows Start button, type "cmd", then right click on the program and select "Run as Administrator"<br />
<br />
<b>Mac</b><br />
<br />
In Mac OSX Leopard, you can use the command <br />
dscacheutil to flush the DNS resolver cache:<br />
<br />
dscacheutil -flushcache<br />
<br />
In Mac OSX versions 10.5.1 and before, the command lookupd -flushcache performed the same task:<br />
<br />
lookupd -flushcache<br />
<br />
<b>Linux</b><br />
<br />
In Linux, the nscd daemon manages the DNS cache.<br />
To flush the DNS cache, restart the nscd daemon.<br />
To restart the nscd daemon, use the command:<br />
<br />
/etc/init.d/nscd restart]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-how-to-flush-dns-1913.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-how-to-flush-dns-1913.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[Mercurial Hook: Forbid 2 heads]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-mercurial-hook-forbid-2-heads-1910.html</link>
<pubDate>Sun, 06 Dec 2009 04:07:44 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-mercurial-hook-forbid-2-heads-1910.html</guid>
<description><![CDATA[The <a href="http://www.softwareprojects.com/resources/programming/t-mercurial-version-control-1853.html" target="_blank">Mercurial version control system</a> offers a powerful mechanism to let you perform automated actions in response to events that occur in a repository. In some cases, you can even control Mercurial's response to those events. No comments<br />
<br />
The name Mercurial uses for one of these actions is a hook (aka trigger).<br />
<br />
One of the most popular hooks is the ability to reject multiple heads.  <br />
<br />
<b>What are multiple heads?</b><br />
<br />
Multiple heads are a case where the code repository contains changes from two (or more) developers, that haven't been merged.  These changes may potentially overlap and break the application flow.<br />
<br />
Having multiple heads occurs in two cases:<br />
<br />
* As part of a merge (generally temporary)<br />
* Bugfix versions (generally permanent)<br />
<br />
At any time, you can view the head(s) of a repository with the command: hg heads<br />
<br />
<b>Pitfalls to watch-for with Multiple Heads</b><br />
<br />
Consider the following scenario:<br />
<br />
* It's Monday morning.  Bob and Linda each pull a copy of the repository to their local Mercurial HG.<br />
<br />
* <u>Bob</u> makes a few changes to index.php and pushes them to the server Monday afternoon.<br />
<br />
* <u>Linda</u> makes a few additional changes to index.php and pushes them to the server on Tuesday morning.<br />
<br />
Since Linda doesn't have the most recent copy of index.php (with Bob's changes), her copy of index.php will create a second "head" to the project.<br />
<br />
There are now two development branches - the one with Bob's changes and the one with Linda's changes, <b>neither one having all changes in place</b>.<br />
<br />
While TortoiseHG will often block Linda's push with a warning that it will create multiple heads, it is possible to push with -f (force).  Some Mercurial plugins automatically push with -f, creating the second head on the live server repository.<br />
<br />
Yes you can run 'hg merge' on the live server to merge Bob and Linda's changes (the two heads) locally, but you <b>never ever want to run hg merge on a live server</b>.  <br />
<br />
Running 'hg merge', adds "<<<<< local >>>>> other" comments into the source files, as part of its file-diff process.  This temporarily breaks the syntax of your source files for the duration of the merge.<br />
<br />
If this is a live server, your scripts will all STOP WORKING until the merge is complete and the "<<<<< local >>>>> other" notations are removed from the source files.<br />
<br />
<b>Rejecting Multiple heads - Do the merge offline</b><br />
<br />
Instead of allowing multiple heads on the live server, a much better approach is to reject multiple heads, forcing the engineers to merge changes locally, before pushing any change that will create a second head.<br />
<br />
In the example above, when Linda attempts to push the changes on Tuesday, her push will be rejected with an error message of "Trying to push more than one head, try run hg merge before it."<br />
<br />
Linda then has to pull the recent changes, retrieving Bob's additions, merge the changes locally and then push a version that incorporates both her changes and Bob's into the server.<br />
<br />
The benefits of this approach are:<br />
#1. Server scripts are never rendered inactive by a local 'hg merge' run<br />
<br />
#2. Engineers always need to retrieve (and test) the latest version, prior to being able to upload changes that may conflict with others.<br />
<br />
#3. The live server always has a single development graph, containing the most recent changes.<br />
<br />
<b>Installing NetBeans Forbid2Heads Mercurial hook</b><br />
<br />
<b>Step 1:</b> Locate your HG extensions folder<br />
<br />
The folder name is 'hgext' and it is typically installed under Mercurial's home folder.  For example:<br />
<br />
/usr/home/mercurial/work/mercurial-1.3.1/hgext<br />
<br />
<b>Step 2: </b> Install forbid_2heads Python script<br />
<br />
Create a new folder named 'forbid_2head' under 'hgext' and save this file under /hgext/forbid_2head/forbid_2head.py:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left"><BR># win32text.py - LF <-> CRLF translation utilities for Windows users<BR>#<BR># This software may be used and distributed according to the terms<BR># of the GNU General Public License, incorporated herein by reference.<BR>#<BR># To forbid pushes which creates two or more headss<BR>#<BR># [hooks]<BR># pretxnchangegroup.forbid_2heads = python:forbid2_head.forbid_2heads<BR><BR>from mercurial import ui<BR>from mercurial.i18n import gettext as _<BR><BR>def forbid_2heads(ui, repo, hooktype, node, **kwargs):<BR>&nbsp; &nbsp; if len(repo.heads()) > 1:<BR>&nbsp; &nbsp; &nbsp; &nbsp; ui.warn(_('Trying to push more than one head, try run "hg merge" before it.n'))<BR>&nbsp; &nbsp; &nbsp; &nbsp; return True</code><hr />
</div>
<br />
<b>Step 3:</b> Add hook to Mercurial config file<br />
<br />
Update your Mercurial hgweb.config, adding the new hook under the 'hooks' section, like this:<br />
<br />
[hooks]<br />
pretxnchangegroup.forbid_2heads = python:forbid_2head.forbid_2heads<br />
<br />
--<br />
<br />
Attempting to push changes to the repository that will create multiple heads is now blocked.<br />
<br />
Users will be presented with an error message and the transaction rolled back, until the user merges changes locally, so that no multiple heads are created:<br />
<br />
<div style="margin:20px; margin-top:5px; ">
	<div class="smallfont" style="margin-bottom:2px">Quote:</div>
	<table cellpadding="6" cellspacing="0" border="0" width="100%">
	<tr>
		<td class="alt2">
			<hr />
			
				
pushing to <a href="http://mydomain.com/" target="_blank">http://mydomain.com/</a><br />
searching for changes<br />
4 changesets found<br />
adding changesets<br />
adding manifests<br />
adding file changes<br />
added 4 changesets with 2 changes to 7 files (+1 heads)<br />
<b>Trying to push more than one head, try run "hg merge" before it.</b><br />
transaction abort!<br />
rollback completed<br />
abort: pretxnchangegroup.forbid_2heads hook failed<br />
[command returned code 1]<br />
			
			<hr />
		</td>
	</tr>
	</table>
</div>
<br />
--<br />
<br />
The live server repository will always have a single development branch.  Engineers will be forced to merge changes locally, before new changes can be pushed:<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/merge2.png" border="0" alt="" />]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-mercurial-hook-forbid-2-heads-1910.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-mercurial-hook-forbid-2-heads-1910.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[Were you just banned from Google Adwords?]]></title>
<link>http://www.softwareprojects.com/resources/traffic-attract-customers/t-were-you-just-banned-from-google-adwords-1907.html</link>
<pubDate>Fri, 04 Dec 2009 18:29:10 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Traffic - Attract Customers]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/traffic-attract-customers/t-were-you-just-banned-from-google-adwords-1907.html</guid>
<description><![CDATA[If you're doing any PPC affiliate marketing, chances are you've heard what's been going on these last 3 days...<br />
<br />
Google just completed another round of <b>banning PPC affiliates</b>, providing no information on the cause, other than a canned email.<br />
<br />
Unlike a "Google Slap" which is a temporary increase of bid-prices due to low quality-scores, a "Google Ban" is permanent and prevents you from ever advertising on Google using your credit-cards or ip-addresses that you previously used with Google.<br />
<br />
We've heard from hundreds of PPC affiliates who got banned on this recent round.  Search Engine Marketing forums are exploding with angry marketers who've lost their entire business over-night.<br />
<br />
<div style="margin:20px; margin-top:5px; ">
	<div class="smallfont" style="margin-bottom:2px">Quote:</div>
	<table cellpadding="6" cellspacing="0" border="0" width="100%">
	<tr>
		<td class="alt2">
			<hr />
			
				
Dear advertiser,<br />
<br />
We are writing to let you know that your Google AdWords account has been disabled due to one or more serious violations of our advertising policies related to Landing Page and Site Quality.  As a result, your ads will no longer run through the Google AdWords system and we are unable to accept advertising from you in the future.  Please <b>note that future accounts you open will also be disabled</b>.  <br />
<br />
...<br />
<br />
Please note that this action is related to sites that have recently been advertised through your account.  In a review of your account history, we found that your account had submitted a least one site that egregiously violated our advertising policies.  Although you may have removed these sites since our latest review, advertisers that have a history of promoting these types of sites are still subject to account-level disabling. <br />
<br />
...<br />
<br />
If you have additional questions or concerns not addressed by our policies or help center, you can contact support by replying to this email.   <br />
<br />
Sincerely,<br />
The Google AdWords team<br />
			
			<hr />
		</td>
	</tr>
	</table>
</div>
<br />
Is affiliate marketing on Google Adwords dying a slow death?  This remains to be seen.<br />
<br />
The recent ban wasn't limited to affiliates running rebill offers but rather a mix of accounts promoting anything from Clickbank products, CPA offers, poor landing pages, etc.<br />
<br />
If you're a PPC marketer, you're going to be forced to evolve or close shop.<br />
<br />
Remember this -<br />
<br />
Google accounts for about 15% of the traffic available online.  <br />
<br />
Look into other avenues such as <a href="http://www.softwareprojects.com/selling-online/email-marketing-spi" target="_blank">Email Marketing</a>, <a href="http://www.softwareprojects.com/ppc-management.php" target="_blank">PPC</a> on other engines such as Yahoo and MSN, <a href="http://www.softwareprojects.com/resources/traffic-attract-customers/t-the-beginners-guide-to-online-media-buys-1465.html" target="_blank">Media buys</a>, <a href="http://www.softwareprojects.com/resources/traffic-attract-customers/t-product-launch-marketing-quickest-path-to-a-6-figu-1886.html" target="_blank">Product launches</a> and <a href="http://www.softwareprojects.com/social/" target="_blank">Social media marketing</a>, as a way of driving traffic to your offers.]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/traffic-attract-customers/t-were-you-just-banned-from-google-adwords-1907.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/traffic-attract-customers/t-were-you-just-banned-from-google-adwords-1907.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[How to install PHP 5.2.11 with php-fpm]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-how-to-install-php-5211-with-php-fpm-1904.html</link>
<pubDate>Tue, 10 Nov 2009 09:39:29 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-how-to-install-php-5211-with-php-fpm-1904.html</guid>
<description><![CDATA[This post will walk you through the process of installing PHP 5.2.11 to run under NGinx using PHP-FPM.<br />
<br />
<a href="http://www.softwareprojects.com/resources/programming/t-installing-nginx-web-server-w-php-and-ssl-1474.html" target="_blank">NGinx</a> doesn't have built-in support for running PHP, it uses a third-party daemon to spawn instances of php-cgi and then communicates with those instances over sockets.<br />
<br />
PHP-FPM is a replacement for spawn-cgi.  Runs faster and is more reliable.<br />
<br />
<b>Step 1: Download PHP 5.2.11 and apply PHP-FPM patch</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">cd /home<BR>mkdir temp<BR>cd temp<BR>wget http://www.softwareprojects.com/files/auto/php-5.2.11.tar.gz<BR>wget http://www.softwareprojects.com/php-5.2.11-fpm-0.5.13.diff.gz<BR>tar zxvf php-5.2.11.tar.gz<BR>gzip -cd php-5.2.11-fpm-0.5.13.diff.gz | patch -d php-5.2.11 -p1</code><hr />
</div>
<br />
<b>Step 2: Configure PHP</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">cd php-5.2.11<BR>'./configure' '--enable-fastcgi' '--enable-fpm' '--enable-calendar' '--enable-ftp' '--enable-mbstring' '--enable-mysql' '--with-curl' '--with-dom' '--with-mcrypt' '--with-gd' '--with-iconv' '--with-jpeg-dir=/usr/lib' '--with-mysql=/usr/local/mysql' '--with-openssl' '--with-soap' '--with-sockets' '--with-zlib' '--enable-zip'<BR>make all</code><hr />
</div>
<br />
<b>Step 3: Install</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">make install<BR>strip /usr/local/bin/php-cgi</code><hr />
</div>
<br />
<b>Step 4: Start PHP-FPM</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">/usr/local/sbin/php-fpm start</code><hr />
</div>]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-how-to-install-php-5211-with-php-fpm-1904.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-how-to-install-php-5211-with-php-fpm-1904.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[How to install PHP ChartDirector under FreeBSD]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-how-to-install-php-chartdirector-under-f-1901.html</link>
<pubDate>Fri, 06 Nov 2009 14:54:42 GMT</pubDate>
<dc:creator><![CDATA[Michel Nadeau]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-how-to-install-php-chartdirector-under-f-1901.html</guid>
<description><![CDATA[PHP ChartDirector is a powerful PHP extension that allows to generate very complex charts. You can visit their Web site <a href="http://www.advsofteng.com/" target="_blank">here</a>.<br />
<br />
This tutorial will show you how to install it under FreeBSD.<br />
<br />
<font size="4">1. Download PHP ChartDirector</font><br />
<br />
The download page is located here -<br />
<a href="http://www.advsofteng.com/download.html" target="_blank">http://www.advsofteng.com/download.html</a><br />
<br />
Make sure you pick the FreeBSD version for PHP, and make sure you choose the good version between 32 and 64-bit. At the time of writing this post, the latest 32-bit version available for FreeBSD was this one -<br />
<a href="http://download2.advsofteng.com/chartdir_php_freebsd.tar.gz" target="_blank">http://download2.advsofteng.com/char...freebsd.tar.gz</a><br />
<br />
Now that you have the download link, the first thing to do is to find out where is your PHP extensions directory. You can find it by checking at phpinfo()'s output or in your php.ini file (which is usually located in /usr/local/lib/php.ini). Just search for "extension_dir" in php.ini - you will find it right away. In our case, our extensions directory was "/usr/local/lib/php/extensions/current". We can now download and extract ChartDirector...<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">cd /usr/local/lib/php/extensions/current<BR>wget http://download2.advsofteng.com/chartdir_php_freebsd.tar.gz<BR>tar xvfz chartdir_php_freebsd.tar.gz</code><hr />
</div>
<br />
When extracting ChartDirector, it creates a "ChartDirector" folder that contains these files/folders:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">doc/<BR>lib/<BR>phpdemo/<BR>LICENSE.TXT<BR>README.TXT</code><hr />
</div>
<br />
We are mainly interested by the "lib" directory. Let's copy the files that we need...<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">cd /usr/local/lib/php/extensions/current<BR>mv ChartDirector/lib/* .</code><hr />
</div>
<br />
You can get rid of these 2 PHP files:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">rm FinanceChart.php<BR>rm phpchartdir.php</code><hr />
</div>
<br />
<font size="4">2. Determine the right version</font><br />
<br />
To determine the right version of the DLL that you must use, refer to this page -<br />
<a href="http://www.advsofteng.com/doc/cdphpdoc/phpinstall.htm" target="_blank">http://www.advsofteng.com/doc/cdphpdoc/phpinstall.htm</a><br />
<br />
For example, if you have PHP 4.4.9, you will use this one -<br />
PHP Version 4.2.1 and above: phpchartdir421.dll<br />
<br />
Even if it's FreeBSD and not Windows, you are going to specify a DLL as the extension in your php.ini file. You can delete all the others DLL's that you are not using, but make sure you keep the "fonts" folder and the "libchardir.so" file - they are required. So your extensions directory might look like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">fonts/<BR>libchartdir.so<BR>phpchartdir421.dll</code><hr />
</div>
<br />
<font size="4">3. Configure the extension in php.ini</font><br />
<br />
Now that we have all we need, we're going to configure php.ini to add the PHP ChartDirector extension.<br />
<br />
Open your php.ini and add a line like this one in the extensions section:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">extension=phpchartdir421.dll</code><hr />
</div>
<br />
Make sure you use the right DLL for your PHP version. Save your php.ini file and restart your PHP engine and/or Web server (Apache, FastCGI, etc.) to reload your PHP configuration.<br />
<br />
To test PHP ChartDirector, you can use the "phpdemo" directory that you can find in the PHP ChartDirector archive. Just copy the folder in the root of your Web server and point it with your browser (ex: <a href="http://yourWebAddress/phpdemo)" target="_blank">http://yourWebAddress/phpdemo)</a>. This demo is also very convenient for charts examples.]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-how-to-install-php-chartdirector-under-f-1901.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-how-to-install-php-chartdirector-under-f-1901.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[How to count unique visitors in an nginx access.log]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-how-to-count-unique-visitors-in-an-nginx-1898.html</link>
<pubDate>Thu, 05 Nov 2009 01:25:06 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-how-to-count-unique-visitors-in-an-nginx-1898.html</guid>
<description><![CDATA[This nifty one-liner will count the number of unique visitors in an <a href="http://www.softwareprojects.com/resources/programming/t-installing-nginx-web-server-w-php-and-ssl-1474.html" target="_blank">NGinx</a> web-server access.log file, for a given day:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">grep "\[04/Nov/2009" access.log | cut -d" " -f1 | sort | uniq | wc -l</code><hr />
</div>
<br />
Replace <b>04/Nov/2009</b> with the date you'd like to count the number of unique visitors for.]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-how-to-count-unique-visitors-in-an-nginx-1898.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-how-to-count-unique-visitors-in-an-nginx-1898.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[FreeBSD No Ports Fix]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-freebsd-no-ports-fix-1895.html</link>
<pubDate>Wed, 04 Nov 2009 23:52:34 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-freebsd-no-ports-fix-1895.html</guid>
<description><![CDATA[When installing a FreeBSD system, you're asked if you would like to install the Ports Collection. If you chose no, you can follow these instructions to obtain the ports collection:<br />
<br />
<b>Option 1 - CVSup</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">csup -L 2 -h cvsup.FreeBSD.org /usr/share/examples/cvsup/ports-supfile<BR>csup</code><hr />
</div>
<br />
<b>Option 2 - Portsnap</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">portsnap fetch<BR>portsnap extract</code><hr />
</div>]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-freebsd-no-ports-fix-1895.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-freebsd-no-ports-fix-1895.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[How to: Add a Lead Opt-in Web Form]]></title>
<link>http://www.softwareprojects.com/resources/the-platform-all-in-one/t-how-to-add-a-lead-opt-in-web-form-1892.html</link>
<pubDate>Wed, 28 Oct 2009 09:21:38 GMT</pubDate>
<dc:creator><![CDATA[Adrian Singer]]></dc:creator>
<category><![CDATA[The Platform: All-In-One]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/the-platform-all-in-one/t-how-to-add-a-lead-opt-in-web-form-1892.html</guid>
<description><![CDATA[A lead opt-in web form is a short form, asking the user to provide name, emailaddress, phone and/or other optional fields, for the purpose of signing up for a program, or receiving more information about your offering.<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/76988008.png" border="0" alt="" /><br />
<br />
Unlike other shopping carts, the <a href="http://www.softwareprojects.com/shopping-cart" target="_blank">SPI cart</a> doesn't limit you to a single form style or any specific fields.<br />
<br />
You can create whatever html form you like, using any design and combination of fields (text, radio button, checkboxes, textareas) as needed.<br />
<br />
The only requirement is to have at least the emailaddress field, whenever saving a new lead to the database.<br />
<br />
<b>Step 1 - Design your opt-in form</b><br />
<br />
Use your favorite HTML editor to design your lead opt-in form.<br />
<br />
For simplicity, use 'name' as the fieldname for the user's name (or 'first_name' + 'last_name'), use 'emailaddress' as the fieldname for the user's email address and use 'phone' as the fieldname for the user's phone number.<br />
<br />
Here's a typical lead opt-in form with the basic name,emailaddress,phone fields as well as a few additional custom ones:<br />
<br />
<div style="margin:10px;  padding:4px; border:1px inset; background-color: #FDF8EB">

	<span style="margin:0px; width:550px; padding:4px;  overflow:auto; "><font face="courier new">  <br /></font><font color="#006600">&lt;</font><font color="#0000CC">form action</font><font color="#006600">=</font><font color="#CC0000">"#" </font><font color="#0000CC">method</font><font color="#006600">=</font><font color="#CC0000">"post"</font><font color="#006600">&gt;<br />&lt;</font><font color="#0000CC">p</font><font color="#006600">&gt;</font><font color="#0000CC">First Name</font><font color="#006600">: &lt;</font><font color="#0000CC">input type</font><font color="#006600">=</font><font color="#CC0000">"text" </font><font color="#0000CC">name</font><font color="#006600">=</font><font color="#CC0000">"first_name" </font><font color="#006600">/&gt;&lt;/</font><font color="#0000CC">p</font><font color="#006600">&gt;<br />&lt;</font><font color="#0000CC">p</font><font color="#006600">&gt;</font><font color="#0000CC">Last Name</font><font color="#006600">: &lt;</font><font color="#0000CC">input type</font><font color="#006600">=</font><font color="#CC0000">"text" </font><font color="#0000CC">name</font><font color="#006600">=</font><font color="#CC0000">"last_name" </font><font color="#006600">/&gt;&lt;/</font><font color="#0000CC">p</font><font color="#006600">&gt;<br />&lt;</font><font color="#0000CC">p</font><font color="#006600">&gt;</font><font color="#0000CC">Best Email</font><font color="#006600">: &lt;</font><font color="#0000CC">input type</font><font color="#006600">=</font><font color="#CC0000">"text" </font><font color="#0000CC">name</font><font color="#006600">=</font><font color="#CC0000">"email" </font><font color="#006600">/&gt;&lt;/</font><font color="#0000CC">p</font><font color="#006600">&gt;<br />&lt;</font><font color="#0000CC">p</font><font color="#006600">&gt;</font><font color="#0000CC">Best Phone Number</font><font color="#006600">: &lt;</font><font color="#0000CC">input type</font><font color="#006600">=</font><font color="#CC0000">"text" </font><font color="#0000CC">name</font><font color="#006600">=</font><font color="#CC0000">"phone" </font><font color="#006600">/&gt;&lt;/</font><font color="#0000CC">p</font><font color="#006600">&gt;<br />&lt;</font><font color="#0000CC">p</font><font color="#006600">&gt;</font><font color="#0000CC">Have you traded individual stocks</font><font color="#006600">?<br /></font><font color="#0000CC">Yes </font><font color="#006600">&lt;</font><font color="#0000CC">input name</font><font color="#006600">=</font><font color="#CC0000">"traded_indi_stock" </font><font color="#0000CC">type</font><font color="#006600">=</font><font color="#CC0000">"radio" </font><font color="#0000CC">value</font><font color="#006600">=</font><font color="#CC0000">"Yes" </font><font color="#006600">/&gt; </font><font color="#0000CC">No </font><font color="#006600">&lt;</font><font color="#0000CC">input name</font><font color="#006600">=</font><font color="#CC0000">"traded_indi_stock" </font><font color="#0000CC">type</font><font color="#006600">=</font><font color="#CC0000">"radio" </font><font color="#0000CC">value</font><font color="#006600">=</font><font color="#CC0000">"No" </font><font color="#006600">/&gt;<br />&lt;/</font><font color="#0000CC">p</font><font color="#006600">&gt;<br />&lt;</font><font color="#0000CC">p</font><font color="#006600">&gt;</font><font color="#0000CC">Have you traded options<br />Yes </font><font color="#006600">&lt;</font><font color="#0000CC">input name</font><font color="#006600">=</font><font color="#CC0000">"traded_option" </font><font color="#0000CC">type</font><font color="#006600">=</font><font color="#CC0000">"radio" </font><font color="#0000CC">value</font><font color="#006600">=</font><font color="#CC0000">"Yes" </font><font color="#006600">/&gt; </font><font color="#0000CC">No </font><font color="#006600">&lt;</font><font color="#0000CC">input name</font><font color="#006600">=</font><font color="#CC0000">"traded_option" </font><font color="#0000CC">type</font><font color="#006600">=</font><font color="#CC0000">"radio" </font><font color="#0000CC">value</font><font color="#006600">=</font><font color="#CC0000">"No" </font><font color="#006600">/&gt;<br />&lt;/</font><font color="#0000CC">p</font><font color="#006600">&gt;<br />&lt;</font><font color="#0000CC">input type</font><font color="#006600">=</font><font color="#CC0000">"submit" </font><font color="#0000CC">name</font><font color="#006600">=</font><font color="#CC0000">"submit" </font><font color="#0000CC">value</font><font color="#006600">=</font><font color="#CC0000">"Submit" </font><font color="#006600">/&gt;<br />&lt;/</font><font color="#0000CC">form</font><font color="#006600">&gt;  </font><font color="#0000CC"></font></span></div>
<br />
<b>Step 2 - Add custom fields to Leads table</b><br />
<br />
Since we're using a few custom fields in this example (traded_indi_stock, traded_option), we need to add those fields to the 'leads' table.<br />
<br />
Connect to your SPI database using <a href="https://softwareprojects.com/phpmyadmin" target="_blank">PHPMyAdmin</a>, locate the leads table and add the two new fields.  You only have to do this once every time you're adding a new custom field to a table.<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/9dbc9f19.png" border="0" alt="" /><br />
<br />
Make sure you're adding the custom fields to the 'leads' table and pay close attention to the fieldnames.  The fieldnames you choose are going to have to match the fieldnames you pass to the do_addlead() function.  <br />
<br />
<b>Step 3 - Save the lead to the database</b><br />
<br />
Now that we have the custom leads in the 'leads' table, saving the lead to the database is the easy part.<br />
<br />
The code below renders the opt-in form, saves the lead to the database and redirects the user to a thankyou.html page.<br />
<br />
<div style="margin:10px;  padding:4px; border:1px inset; background-color: #FDF8EB">

	<span style="margin:0px; width:550px; padding:4px;  overflow:auto; "><font face="courier new"> <br /></font><font color="#006600">&lt;?</font><font color="#0000CC">php<br /></font><font color="#FF9900">// Include SPICart shopping cart API<br /></font><font color="#006600">require_once(</font><font color="#CC0000">"spicart.php"</font><font color="#006600">);<br /><br /></font><font color="#FF9900">// If this is a lead submit<br /></font><font color="#006600">if (!empty(</font><font color="#0000CC">$_POST</font><font color="#006600">&#91;</font><font color="#CC0000">'email'</font><font color="#006600">&#93;))<br />{<br /></font><font color="#FF9900">// Save lead to the database<br /></font><font color="#0000CC">$input </font><font color="#006600">= array();<br /></font><font color="#0000CC">$input</font><font color="#006600">&#91;</font><font color="#CC0000">'first_name'</font><font color="#006600">&#93; = </font><font color="#0000CC">$_POST</font><font color="#006600">&#91;</font><font color="#CC0000">'first_name'</font><font color="#006600">&#93;;<br /></font><font color="#0000CC">$input</font><font color="#006600">&#91;</font><font color="#CC0000">'last_name'</font><font color="#006600">&#93; = </font><font color="#0000CC">$_POST</font><font color="#006600">&#91;</font><font color="#CC0000">'last_name'</font><font color="#006600">&#93;;<br /></font><font color="#0000CC">$input</font><font color="#006600">&#91;</font><font color="#CC0000">'emailaddress'</font><font color="#006600">&#93; = </font><font color="#0000CC">$_POST</font><font color="#006600">&#91;</font><font color="#CC0000">'emailaddres'</font><font color="#006600">&#93;;<br /></font><font color="#0000CC">$input</font><font color="#006600">&#91;</font><font color="#CC0000">'phone'</font><font color="#006600">&#93; = </font><font color="#0000CC">$_POST</font><font color="#006600">&#91;</font><font color="#CC0000">'phone'</font><font color="#006600">&#93;;<br /></font><font color="#0000CC">$input</font><font color="#006600">&#91;</font><font color="#CC0000">'traded_indi_stock'</font><font color="#006600">&#93; = </font><font color="#0000CC">$_POST</font><font color="#006600">&#91;</font><font color="#CC0000">'traded_indi_stock'</font><font color="#006600">&#93;;<br /></font><font color="#0000CC">$input</font><font color="#006600">&#91;</font><font color="#CC0000">'traded_option'</font><font color="#006600">&#93; = </font><font color="#0000CC">$_POST</font><font color="#006600">&#91;</font><font color="#CC0000">'traded_option'</font><font color="#006600">&#93;;<br /></font><font color="#0000CC">do_addlead</font><font color="#006600">(</font><font color="#0000CC">$input</font><font color="#006600">, &amp;</font><font color="#0000CC">$output</font><font color="#006600">, &amp;</font><font color="#0000CC">$result_str</font><font color="#006600">);<br /></font><font color="#0000CC">Header</font><font color="#006600">(</font><font color="#CC0000">"Location: thankyou.html"</font><font color="#006600">);<br />die;<br />}<br /></font><font color="#0000CC">?&gt;<br /></font>&lt;form action="#" method="post"&gt;<br />&lt;p&gt;First Name: &lt;input type="text" name="first_name" /&gt;&lt;/p&gt;<br />&lt;p&gt;Last Name: &lt;input type="text" name="last_name" /&gt;&lt;/p&gt;<br />&lt;p&gt;Best Email: &lt;input type="text" name="emailaddress" /&gt;&lt;/p&gt;<br />&lt;p&gt;Best Phone Number: &lt;input type="text" name="phone" /&gt;&lt;/p&gt;<br />&lt;p&gt;Have you traded individual stocks?<br />Yes &lt;input name="traded_indi_stock" type="radio" value="Yes" /&gt; No &lt;input name="traded_indi_stock" type="radio" value="No" /&gt;<br />&lt;/p&gt;<br />&lt;p&gt;Have you traded options<br />Yes &lt;input name="traded_option" type="radio" value="Yes" /&gt; No &lt;input name="traded_option" type="radio" value="No" /&gt;<br />&lt;/p&gt;<br />&lt;input type="submit" name="submit" value="Submit" /&gt;<br />&lt;/form&gt; </font></span></div>
<br />
<b>Note about Affiliate Tracking</b><br />
<br />
Often times, affiliates will be sending their traffic to your lead opt-in forms.  You're going to want to know which affiliate generated which leads.<br />
<br />
Luckily the system takes care of this automatically.<br />
<br />
One of the fields in the 'leads' table is aff_id.  This is the ID of the referring affiliate and serves as the glue, associating leads with the affiliates who referred them.<br />
<br />
When a user clicks on an affiliate link to visit the opt-in form on your website, they typically follow a link that looks like this:<br />
<br />
<font color="Blue"><u><a href="http://www.YourDomain.com/?aff_id=1234" target="_blank">www.YourDomain.com/?aff_id=1234</a></u></font> <br />
<br />
Where 1234 is the affiliate ID.<br />
<br />
As soon as the user lands on the lead opt-in form, the spicart.php include at the top of your file, identifies the aff_id url-parameter and saves it in a cookie on the end-user's machine.<br />
<br />
Later when you call do_addlead(), this method picks up the aff_id from the end-user's cookie and passes it along, so that when the lead is added, the referring aff_id is saved as well.]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/the-platform-all-in-one/t-how-to-add-a-lead-opt-in-web-form-1892.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/the-platform-all-in-one/t-how-to-add-a-lead-opt-in-web-form-1892.html</feedburner:origLink>

</item>
<item>
<title><![CDATA[Do It Yourself Web Server and Database monitoring]]></title>
<link>http://www.softwareprojects.com/resources/programming/t-do-it-yourself-web-server-and-database-m-1889.html</link>
<pubDate>Wed, 21 Oct 2009 06:44:12 GMT</pubDate>
<dc:creator><![CDATA[Mike Peters]]></dc:creator>
<category><![CDATA[Programming]]></category>
<guid isPermaLink="false">http://www.softwareprojects.com/resources/programming/t-do-it-yourself-web-server-and-database-m-1889.html</guid>
<description><![CDATA[When you have production web servers and databases, it is absolutely critical to have a monitoring system in-place that will alert you whenever service goes down.<br />
<br />
<b>Getting Started with website monitoring</b><br />
<br />
One of our favorite monitoring tools is <a href="http://www.pingdom.com" target="_blank">Pingdom</a>.  It's a $9.95/month easy-to-use service that will ping 5 of your servers, once every 60 seconds, alerting you via email &amp; SMS whenever any server goes down.<br />
<br />
In addition to downtime notifications, the service also provides response-time trends, raw data and uptime-over-time reports:<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/24d940d6.png" border="0" alt="" /><br />
<br />
If you don't have any monitoring in-place right one, you should definitely try out Pingdom or a similar service.<br />
<br />
In about 5 minutes of setting it up, you'll have the peace of mind, knowing exactly when your merchant website, affiliate landing page or payment gateway goes down.<br />
<br />
<b>Beyond simple HTTP monitoring</b><br />
<br />
While Pingdom and other similar tools are great in letting you know once your website is -already- down, a lot of times the outage can be prevented in the first place, by detecting a decrease available memory, cpu, disk space etc.<br />
<br />
At the pinnacle of server monitoring are tools such as <a href="http://www.nagios.org/" target="_blank">Nagios</a> and <a href="http://munin.projects.linpro.no/" target="_blank">Munin</a>. <br />
<br />
Munin will monitor every single resource on your server, including: memory, cpu utilization, available handles, open connections, average load, running processes and more.<br />
<br />
Nagios sends alerts to groups of users based on predetermined rules.<br />
<br />
<img src="http://www.softwareprojects.com/blogimages/6fd56f32.png" border="0" alt="" /><br />
<br />
<b>Do It Yourself Server Monitoring</b><br />
<br />
In this post, I'd like to focus on how to create a simple monitoring script, that will survey remote servers for a few critical metrics, displaying the results on the screen.<br />
<br />
Unlike Nagios+Munin, such a setup doesn't require installing a monitoring component on each server.  Your monitoring script can run remotely, surveying all servers once every 60 seconds on a cronjob, sending an email/sms whenever detecting abnormal behavior.<br />
<br />
For the purpose of this example, our script will monitor the following metrics:<br />
<br />
= MySQL Database server<br />
* Number of running threads<br />
* Number of threads connected<br />
* Queries per second<br />
* Open tables<br />
* Sample query response<br />
* Number of tables in database<br />
<br />
= Any FreeBSD/Linux server<br />
* CPU load over the last 5 minutes<br />
* Available memory<br />
* Open sockets<br />
* Number of running processes<br />
<br />
<div style="margin:10px;  padding:4px; border:1px inset; background-color: #FDF8EB">

	<span style="margin:0px; width:550px; padding:4px;  overflow:auto; "><font face="courier new">  <br /></font><font color="#FF9900">// Set these for easier access<br /></font><font color="#0000CC">$USERNAME&nbsp;  </font><font color="#006600">= </font><font color="#CC0000">"root"</font><font color="#006600">;<br /></font><font color="#0000CC">$SERVER&nbsp;  </font><font color="#006600">= </font><font color="#CC0000">"www.mydomain.com"</font><font color="#006600">;<br /></font><font color="#0000CC">$DBHOST&nbsp; &nbsp; </font><font color="#006600">= </font><font color="#CC0000">"www.mydatabase.com"</font><font color="#006600">;<br /></font><font color="#0000CC">$DBUSER&nbsp; &nbsp; </font><font color="#006600">= </font><font color="#CC0000">"root"</font><font color="#006600">;<br /></font><font color="#0000CC">$DBPASS&nbsp; &nbsp; </font><font color="#006600">= </font><font color="#CC0000">"dbpassword"</font><font color="#006600">;<br /></font><font color="#0000CC">$DBNAME&nbsp; &nbsp; </font><font color="#006600">= </font><font color="#CC0000">"dbdatabasename"</font><font color="#006600">;<br /><br /></font><font color="#FF9900">// Get load average, available memory and number of running processes<br /></font><font color="#0000CC">$load_average </font><font color="#006600">= </font><font color="#CC0000">"N/A"</font><font color="#006600">;<br /></font><font color="#0000CC">$available_memory </font><font color="#006600">= </font><font color="#CC0000">"N/A"</font><font color="#006600">;<br /></font><font color="#0000CC">$running_processes </font><font color="#006600">= </font><font color="#CC0000">"N/A"</font><font color="#006600">;<br /></font><font color="#0000CC">$CRLF </font><font color="#006600">= </font><font color="#CC0000">"\r\n"</font><font color="#006600">;<br /></font><font color="#0000CC">exec</font><font color="#006600">(</font><font color="#CC0000">"ssh -l$USERNAME $SERVER \"top -b -n 1\""</font><font color="#006600">,&amp;</font><font color="#0000CC">$buf</font><font color="#006600">);<br />for (</font><font color="#0000CC">$i</font><font color="#006600">=</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$str</font><font color="#006600">=</font><font color="#CC0000">""</font><font color="#006600">; </font><font color="#0000CC">$i</font><font color="#006600">&lt;</font><font color="#0000CC">count</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">); </font><font color="#0000CC">$i</font><font color="#006600">++) </font><font color="#0000CC">$str </font><font color="#006600">.= </font><font color="#0000CC">$buf</font><font color="#006600">&#91;</font><font color="#0000CC">$i</font><font color="#006600">&#93;.</font><font color="#0000CC">$CRLF</font><font color="#006600">;<br />if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">"load averages:"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />{<br />&nbsp; &nbsp; </font><font color="#0000CC">$str </font><font color="#006600">= </font><font color="#0000CC">trim</font><font color="#006600">(</font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"load averages:"</font><font color="#006600">)));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#0000CC">$CRLF</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$load_average </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; &nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">"up"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">) </font><font color="#0000CC">$load_average </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$load_average</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />}<br />else<br />if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">"load average:"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />{<br />&nbsp; &nbsp; </font><font color="#0000CC">$str </font><font color="#006600">= </font><font color="#0000CC">trim</font><font color="#006600">(</font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"load average:"</font><font color="#006600">)));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#0000CC">$CRLF</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$load_average </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />}<br />if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">"processes:"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />{<br />&nbsp; </font><font color="#0000CC">$str </font><font color="#006600">= </font><font color="#0000CC">trim</font><font color="#006600">(</font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"processes:"</font><font color="#006600">)));<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">","</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$running_processes </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; }<br />}<br />else<br />if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">"Tasks:"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />{<br />&nbsp; &nbsp; </font><font color="#0000CC">$str </font><font color="#006600">= </font><font color="#0000CC">trim</font><font color="#006600">(</font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"Tasks:"</font><font color="#006600">)));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">","</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; </font><font color="#0000CC">$str </font><font color="#006600">= </font><font color="#0000CC">trim</font><font color="#006600">(</font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">1</font><font color="#006600">));<br />&nbsp; &nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">"run"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; </font><font color="#0000CC">$running_processes </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; &nbsp; }<br />}<br />if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#CC0000">"Mem:"</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />{<br />&nbsp; </font><font color="#0000CC">$str </font><font color="#006600">= </font><font color="#0000CC">trim</font><font color="#006600">(</font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">+</font><font color="#0000CC">strlen</font><font color="#006600">(</font><font color="#CC0000">"Mem:"</font><font color="#006600">)));<br />&nbsp; if ((</font><font color="#0000CC">$pos</font><font color="#006600">=</font><font color="#0000CC">strpos</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">,</font><font color="#0000CC">$CRLF</font><font color="#006600">))!==</font><font color="#0000CC">false</font><font color="#006600">)<br />&nbsp; {<br />&nbsp; &nbsp; </font><font color="#0000CC">$available_memory </font><font color="#006600">= </font><font color="#0000CC">substr</font><font color="#006600">(</font><font color="#0000CC">$str</font><font color="#006600">, </font><font color="#0000CC">0</font><font color="#006600">, </font><font color="#0000CC">$pos</font><font color="#006600">);<br />&nbsp; }<br />}<br /><br /></font><font color="#FF9900">// Get open sockets<br /></font><font color="#0000CC">$open_sockets </font><font color="#006600">= </font><font color="#CC0000">"N/A"</font><font color="#006600">;<br /></font><font color="#0000CC">$buf </font><font color="#006600">= array();<br /></font><font color="#0000CC">exec</font><font color="#006600">(</font><font color="#CC0000">"ssh -l$USERNAME $SERVER "</font><font color="#0000CC">netstat </font><font color="#006600">-</font><font color="#0000CC">n </font><font color="#006600">| </font><font color="#0000CC">wc </font><font color="#006600">-</font><font color="#0000CC">l</font><font color="#CC0000">""</font><font color="#006600">,&amp;</font><font color="#0000CC">$buf</font><font color="#006600">);&nbsp;  <br /></font><font color="#0000CC">$open_sockets </font><font color="#006600">= </font><font color="#0000CC">trim</font><font color="#006600">(</font><font color="#0000CC">$buf</font><font color="#006600">&#91;</font><font color="#0000CC">0</font><font color="#006600">&#93;);&nbsp; &nbsp; &nbsp;  <br /><br /></font><font color="#FF9900">// Display server metrics<br /></font><font color="#006600">echo </font><font color="#CC0000">"== Server\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"&nbsp; &nbsp; Load average: $load_average\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"&nbsp; &nbsp; Open Sockets: $open_sockets\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"   Running Processes: $running_processes\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"&nbsp; Available memory: $available_memory\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"\r\n"</font><font color="#006600">;<br /><br /></font><font color="#FF9900">// Get running and connected threads<br /></font><font color="#0000CC">$db_threads_connected </font><font color="#006600">= </font><font color="#CC0000">"N/A"</font><font color="#006600">;<br /></font><font color="#0000CC">$db_running_threads </font><font color="#006600">= </font><font color="#CC0000">"N/A"</font><font color="#006600">;<br /></font><font color="#0000CC">mysql_connect</font><font color="#006600">(</font><font color="#0000CC">$DBHOST</font><font color="#006600">,</font><font color="#0000CC">$DBUSER</font><font color="#006600">,</font><font color="#0000CC">$DBPASS</font><font color="#006600">);<br /></font><font color="#0000CC">$Result </font><font color="#006600">= @</font><font color="#0000CC">mysql_query</font><font color="#006600">(</font><font color="#CC0000">"show status like '%thread%' "</font><font color="#006600">);<br /></font><font color="#0000CC">$cnt </font><font color="#006600">= @</font><font color="#0000CC">mysql_num_rows</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">);<br />while (</font><font color="#0000CC">$cnt</font><font color="#006600">)<br />{&nbsp; <br />&nbsp; &nbsp; </font><font color="#0000CC">$cnt</font><font color="#006600">--;<br />&nbsp; &nbsp; if (!(</font><font color="#0000CC">$Row </font><font color="#006600">= @</font><font color="#0000CC">mysql_fetch_array</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">))) continue;<br /><br />&nbsp; &nbsp; if (empty(</font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Value'</font><font color="#006600">&#93;)) continue;<br /><br />&nbsp; &nbsp; if (</font><font color="#0000CC">Strcasecmp</font><font color="#006600">(</font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Variable_name'</font><font color="#006600">&#93;,</font><font color="#CC0000">'Threads_connected'</font><font color="#006600">)==</font><font color="#0000CC">0</font><font color="#006600">)<br />&nbsp; &nbsp; </font><font color="#0000CC">$db_threads_connected </font><font color="#006600">= </font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Value'</font><font color="#006600">&#93;;<br />&nbsp; &nbsp; else<br />&nbsp; &nbsp; if (</font><font color="#0000CC">Strcasecmp</font><font color="#006600">(</font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Variable_name'</font><font color="#006600">&#93;,</font><font color="#CC0000">'Threads_running'</font><font color="#006600">)==</font><font color="#0000CC">0</font><font color="#006600">)<br />&nbsp; &nbsp; </font><font color="#0000CC">$db_running_threads </font><font color="#006600">= </font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Value'</font><font color="#006600">&#93;;<br />}<br /><br /></font><font color="#FF9900">// Get queries per second<br /></font><font color="#0000CC">$Result </font><font color="#006600">= @</font><font color="#0000CC">mysql_query</font><font color="#006600">(</font><font color="#CC0000">"show status like 'questions' "</font><font color="#006600">);<br /></font><font color="#0000CC">$Row </font><font color="#006600">= @</font><font color="#0000CC">mysql_fetch_array</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">);<br /></font><font color="#0000CC">$questions </font><font color="#006600">= </font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Value'</font><font color="#006600">&#93;+</font><font color="#0000CC">0</font><font color="#006600">;<br /></font><font color="#0000CC">$Result </font><font color="#006600">= @</font><font color="#0000CC">mysql_query</font><font color="#006600">(</font><font color="#CC0000">"show status like 'uptime' "</font><font color="#006600">);<br /></font><font color="#0000CC">$Row </font><font color="#006600">= @</font><font color="#0000CC">mysql_fetch_array</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">);<br /></font><font color="#0000CC">$uptime </font><font color="#006600">= </font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Value'</font><font color="#006600">&#93;+</font><font color="#0000CC">0</font><font color="#006600">;<br /></font><font color="#0000CC">$db_queries_per_second </font><font color="#006600">= </font><font color="#0000CC">number_format</font><font color="#006600">(</font><font color="#0000CC">$questions</font><font color="#006600">/</font><font color="#0000CC">$uptime</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">);<br /><br /></font><font color="#FF9900">// Get open tables<br /></font><font color="#0000CC">$db_open_tables </font><font color="#006600">= </font><font color="#CC0000">"N/A"</font><font color="#006600">;<br /></font><font color="#0000CC">$Result </font><font color="#006600">= @</font><font color="#0000CC">mysql_query</font><font color="#006600">(</font><font color="#CC0000">"show status like '%tables%' "</font><font color="#006600">);<br /></font><font color="#0000CC">$cnt </font><font color="#006600">= @</font><font color="#0000CC">mysql_num_rows</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">);<br />while (</font><font color="#0000CC">$cnt</font><font color="#006600">)<br />{<br />&nbsp; &nbsp; </font><font color="#0000CC">$cnt</font><font color="#006600">--;<br />&nbsp; &nbsp; if (!(</font><font color="#0000CC">$Row </font><font color="#006600">= @</font><font color="#0000CC">mysql_fetch_array</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">))) continue;<br /><br />&nbsp; &nbsp; if (empty(</font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Value'</font><font color="#006600">&#93;)) continue;<br />&nbsp; &nbsp; if (</font><font color="#0000CC">Strcasecmp</font><font color="#006600">(</font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Variable_name'</font><font color="#006600">&#93;,</font><font color="#CC0000">'Open_tables'</font><font color="#006600">)==</font><font color="#0000CC">0</font><font color="#006600">)<br />&nbsp; &nbsp; </font><font color="#0000CC">$db_open_tables </font><font color="#006600">= </font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#CC0000">'Value'</font><font color="#006600">&#93;;<br />}<br /><br /></font><font color="#FF9900">// Get query response<br /></font><font color="#0000CC">$Result </font><font color="#006600">= @</font><font color="#0000CC">mysql_query</font><font color="#006600">(</font><font color="#CC0000">"SELECT 1"</font><font color="#006600">);<br /></font><font color="#0000CC">$Row </font><font color="#006600">= @</font><font color="#0000CC">mysql_fetch_row</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">);<br /></font><font color="#0000CC">$db_query_response </font><font color="#006600">= </font><font color="#0000CC">$Row</font><font color="#006600">&#91;</font><font color="#0000CC">0</font><font color="#006600">&#93;==</font><font color="#CC0000">'1' </font><font color="#006600">? </font><font color="#CC0000">"Good" </font><font color="#006600">: </font><font color="#CC0000">"BAD"</font><font color="#006600">;<br /><br /></font><font color="#FF9900">// Get total number of tables<br /></font><font color="#006600">@</font><font color="#0000CC">mysql_query</font><font color="#006600">(</font><font color="#CC0000">"use $DBNAME"</font><font color="#006600">);<br /></font><font color="#0000CC">$Result </font><font color="#006600">= @</font><font color="#0000CC">mysql_query</font><font color="#006600">(</font><font color="#CC0000">"show tables"</font><font color="#006600">);<br /></font><font color="#0000CC">$db_tables_in_database </font><font color="#006600">= @</font><font color="#0000CC">mysql_num_rows</font><font color="#006600">(</font><font color="#0000CC">$Result</font><font color="#006600">);<br /><br /></font><font color="#FF9900">// Display database metrics<br /></font><font color="#006600">echo </font><font color="#CC0000">"== Database\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"&nbsp;  Running Threads: $db_running_threads\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"   Threads Connected: $db_threads_connected\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"  Queries Per Second: $db_queries_per_second\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"&nbsp; &nbsp;  Open Tables: $db_open_tables\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"&nbsp;   Query Response: $db_query_response\r\n"</font><font color="#006600">;<br />echo </font><font color="#CC0000">"&nbsp; Number of tables: $db_tables_in_database\r\n"</font><font color="#006600">;  </font><font color="#0000CC"></font></span></div>
<br />
The output of the script will look something like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">== Server<BR>&nbsp; &nbsp; &nbsp; &nbsp; Load average: 0.09,&nbsp; 0.23,&nbsp; 0.23&nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; Open Sockets: 226<BR>&nbsp;  Running Processes: 1 running<BR>&nbsp; &nbsp; Available memory: 2203M Active, 112M Buf, 4668K Free<BR><BR>== Database<BR>&nbsp; &nbsp;  Running Threads: 3<BR>&nbsp;  Threads Connected: 16<BR>&nbsp; Queries Per Second: 320<BR>&nbsp; &nbsp; &nbsp; &nbsp;  Open Tables: 200<BR>&nbsp; &nbsp; &nbsp; Query Response: Good<BR>&nbsp; &nbsp; Number of tables: 1648</code><hr />
</div>
<br />
<b>Tip:</b> If you're looking to monitor dozens of servers, consider applying our <a href="http://www.softwareprojects.com/resources/programming/t-ssh-no-password-without-any-private-keys-its-magi-1880.html" target="_blank">ssh no password</a> approach, to save the hassle of having to exchange private keys with each server.]]></description>

		<wfw:commentRss>http://www.softwareprojects.com/resources/programming/t-do-it-yourself-web-server-and-database-m-1889.html</wfw:commentRss>
		<feedburner:origLink>http://www.softwareprojects.com/resources/programming/t-do-it-yourself-web-server-and-database-m-1889.html</feedburner:origLink>

</item>

</channel></rss>