<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Fireproof Socks</title>
	<link>http://www.fireproofsocks.com</link>
	<description>Audio, Computers, and Stuff...</description>
	<pubDate>Sun, 10 Aug 2008 07:47:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Preparing MySQL statements in PHP 5</title>
		<link>http://www.fireproofsocks.com/php/preparing-mysql-statements-in-php-5/</link>
		<comments>http://www.fireproofsocks.com/php/preparing-mysql-statements-in-php-5/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 07:47:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Mysqli]]></category>

		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.fireproofsocks.com/php/preparing-mysql-statements-in-php-5/</guid>
		<description><![CDATA[This revolves around the PHP mysqli module (for PHP 5).  Yeah, I know, it&#8217;s in the manual, but the examples aren&#8217;t straightforward enough, so here&#8217;s a couple of my own.  
The idea here is SECURE database interaction.  Follow these steps:
1.  Create a database user with ONLY the permissions that you need [...]]]></description>
			<content:encoded><![CDATA[<p>This revolves around the PHP <a href="http://www.php.net/manual/en/book.mysqli.php">mysqli</a> module (for PHP 5).  Yeah, I know, it&#8217;s in the manual, but the examples aren&#8217;t straightforward enough, so here&#8217;s a couple of my own.  </p>
<p>The idea here is SECURE database interaction.  Follow these steps:</p>
<p>1.  Create a database user with ONLY the permissions that you need for a given function. E.g. if you have a page that only needs to DISPLAY information, use a database user that only has SELECT privileges. </p>
<p>2.  Create your database columns so they can ONLY store the types of information they need.  E.g. if the field is for a phone number area code, make the column an INTEGER, not a CHAR, VARCHAR or TEXT field.  Nothing bad can end up in an integer column&#8230; but if you have a wide open data-type, you could be asking for trouble.</p>
<p>3.  Put your database connect functions ABOVE the html root directory.  E.g. most web sites should utilize a directory structure with something like the following:<br />
/html (contains all your html pages&#8230; this is the document root of the web site).<br />
/lib (contains your database connect function and other PHP code).</p>
<p>4.  Use regular expressions to sanitize any user input to a form.  Javascript enhances the user experience, but it cannot stop someone from posting data directly to your submission page.  E.g. you might have something like this to get only alpha-numeric input:</p>
<p><code>function get_alphanumeric_regex ($input) {<br />
    $pattern = '/\W/';<br />
    $input = preg_replace($pattern, ' ', $input);<br />
    return $input;<br />
}<br />
</code></p>
<p>5.  Finally, use prepared statements&#8230; they are MUCH safer than piecing together statements as strings.  If someone hijacks your string, then they&#8217;ve hijacked your statement.  A prepared statement can&#8217;t be messed with.  With mysqli, they look something like this:</p>
<p><code>< ?php</p>
<p>/*-------------------------------------------------------------------------*/<br />
define("DATABASE_HOST", 'localhost');<br />
define("DATABASE", 'my_database');</p>
<p>function connect_db ($handle) {<br />
        switch($handle) {<br />
        case 'form_insert':<br />
                $link = new mysqli(DATABASE_HOST, $handle, "some_p@ssword", DATABASE);<br />
                break;<br />
        case 'form_update':<br />
                $link = new mysqli(DATABASE_HOST, $handle, "some_oth3r_p@ssword", DATABASE);<br />
                break;<br />
        case 'form_select':<br />
                $link = new mysqli(DATABASE_HOST, $handle, "ke3p_gues$ing!", DATABASE);<br />
                break;<br />
        case 'form_delete':<br />
                $link = new mysqli(DATABASE_HOST, $handle, "still-KE3p-Gu3ssing", DATABASE);<br />
                break;<br />
        }</p>
<p>        return $link;</p>
<p>}</p>
<p>/*-------------------------------------------------------------------------*/<br />
function insert_something ($input) {<br />
/*<br />
INPUT:<br />
        Hash with values from form, e.g. $input['first_name'].<br />
OUTPUT:<br />
        id from database if successful insert; otherwise null.<br />
*/<br />
        $link = connect_db('form_insert');<br />
        /* check connection */<br />
        if (mysqli_connect_errno()) {<br />
                        printf("Connect failed: %s\n", mysqli_connect_error());<br />
                        exit();<br />
        }</p>
<p>        $sql = "INSERT INTO some_table<br />
        (<br />
        first_name,<br />
        last_name,<br />
        datestamp<br />
        ) VALUES (<br />
        ?,<br />
        ?,<br />
        NOW()<br />
        )";</p>
<p>        $statement = $link->prepare($sql);</p>
<p>        if (!$statement) {<br />
                printf(&#8221;Error - SQLSTATE %s.\n&#8221;, mysqli_sqlstate($db_connection));<br />
                exit();<br />
        };</p>
<p>        $first_name             = get_name_regex($input[&#8217;first_name&#8217;]);<br />
        $last_name              = get_name_regex($input[&#8217;last_name&#8217;]);</p>
<p>        $statement->bind_param(&#8221;ss&#8221;, $first_name, $last_name);</p>
<p>        $statement->execute();</p>
<p>        $link->close();</p>
<p>        return $result;<br />
}</p>
<p>/*&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-*/<br />
function get_name_regex ($input) {<br />
    $pattern = &#8216;/(;|\||`|=|&#8211;|\/|\.|>|< |&#038;|^|"|'."\n|\r".'|{|}|[|]|\)|\(|[0-9])/i';<br />
    $input = preg_replace($pattern, ' ', $input);<br />
    return trim(ucfirst($input));<br />
}<br />
?></code></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.fireproofsocks.com%2Fphp%2Fpreparing-mysql-statements-in-php-5%2F';
  addthis_title  = 'Preparing+MySQL+statements+in+PHP+5';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.fireproofsocks.com/php/preparing-mysql-statements-in-php-5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Grandcentral: Phone Number Forwarding</title>
		<link>http://www.fireproofsocks.com/uncategorized/grandcentral-phone-number-forwarding/</link>
		<comments>http://www.fireproofsocks.com/uncategorized/grandcentral-phone-number-forwarding/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 02:42:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[call forwarding]]></category>

		<category><![CDATA[Phone number]]></category>

		<category><![CDATA[voicemail]]></category>

		<guid isPermaLink="false">http://www.fireproofsocks.com/uncategorized/grandcentral-phone-number-forwarding/</guid>
		<description><![CDATA[I guess I&#8217;m the last one to hear about this awesome free service: Grandcentral.com

Screen Callers
Record calls on the fly and access recordings online
Block Callers
Receive Notifications
One number that rings different phones based on who&#8217;s calling
Personalize your voicemail greetings by caller or group
Let people call you from a web page without showing your number
Visual voicemail for your [...]]]></description>
			<content:encoded><![CDATA[<p>I guess I&#8217;m the last one to hear about this awesome free service: <a href="http://grandcentral.com/">Grandcentral.com</a></p>
<ul>
<li>Screen Callers</li>
<li>Record calls on the fly and access recordings online</li>
<li>Block Callers</li>
<li>Receive Notifications</li>
<li>One number that rings different phones based on who&#8217;s calling</li>
<li>Personalize your voicemail greetings by caller or group</li>
<li>Let people call you from a web page without showing your number</li>
<li>Visual voicemail for your mobile phone</li>
<li>And more!</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5121424398135626";
/* 468x60, created 3/15/08 */
google_ad_slot = "6666906371";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.fireproofsocks.com%2Funcategorized%2Fgrandcentral-phone-number-forwarding%2F';
  addthis_title  = 'Grandcentral%3A+Phone+Number+Forwarding';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.fireproofsocks.com/uncategorized/grandcentral-phone-number-forwarding/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Google Gods</title>
		<link>http://www.fireproofsocks.com/software/the-google-gods/</link>
		<comments>http://www.fireproofsocks.com/software/the-google-gods/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 18:31:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<category><![CDATA[Google]]></category>

		<category><![CDATA[Rant]]></category>

		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.fireproofsocks.com/software/the-google-gods/</guid>
		<description><![CDATA[Sometimes people ask me why I named my website FireproofSocks&#8230; there is an answer for that, and I&#8217;ll tell the story if you ask.  But what I didn&#8217;t foresee in my choice of a name was how poor my Google Ads would be.  Usually when I look at my page, I sneer in [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes people ask me why I named my website FireproofSocks&#8230; there is an answer for that, and I&#8217;ll tell the story if you ask.  But what I didn&#8217;t foresee in my choice of a name was how poor my Google Ads would be.  Usually when I look at my page, I sneer in frustration at the idiotic ads that appear in articles about Perl and MySQL.  Safes?  Are you serious?  Is anyone really surprised when a door-knob has an IQ that is higher than my click-through rate? </p>
<p>The lesson I&#8217;ve learned from the <a href="http://www.thechurchofgoogle.org/Scripture/Proof_Google_Is_God.html">Google Gods</a> is that the NAME of your domain trumps your content to a huge degree.  Bastards.  As Frank Zappa might say &#8220;Who&#8217;s @#% do you have to suck to get some relevant ads around here?&#8221;  </p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5121424398135626";
/* 468x60, created 3/15/08 */
google_ad_slot = "6666906371";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.fireproofsocks.com%2Fsoftware%2Fthe-google-gods%2F';
  addthis_title  = 'The+Google+Gods';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.fireproofsocks.com/software/the-google-gods/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Javascript document.write for SEO</title>
		<link>http://www.fireproofsocks.com/php/using-javascript-documentwrite-for-seo/</link>
		<comments>http://www.fireproofsocks.com/php/using-javascript-documentwrite-for-seo/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 08:30:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.fireproofsocks.com/php/using-javascript-documentwrite-for-seo/</guid>
		<description><![CDATA[The idea here is that search-engines read a bunch of text on your page that may not be relevant.  You can use javascript to write text to a page on the client-side, and that text won&#8217;t be processed by the search-engines, thus achieving Search Engine Optimization (SEO).
There are a couple ways to do this&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>The idea here is that search-engines read a bunch of text on your page that may not be relevant.  You can use javascript to write text to a page on the client-side, and that text won&#8217;t be processed by the search-engines, thus achieving Search Engine Optimization (SEO).</p>
<p>There are a couple ways to do this&#8230; the easiest is using javascript&#8217;s document.write:</p>
<p><code><br />
&lt;script type="text/javascript"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;document.write('Hello World');<br />
&lt;/script&gt;<br />
</code></p>
<p>This works great for simple little messages, but what if you have a large multi-line text string?  What if your text has HTML tags and double quotes in it?  Then you&#8217;re in for some trouble, because the nice little javascript examples will die on you most ingloriously.  PHP to the rescue.  Use PHP to replace the spaces (and double-quotes)&#8230; you may have to escape your double-quotes in the source text.  </p>
<p><!--adsense--></p>
<p>Extending that simple little example with some meaty text and some PHP, you end up with something like this:</p>
<p><code><br />
&lt;?php</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;$text = "<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hello,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;big, multi-line<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"stuff\", watch out!<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/p&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;";</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;$text = preg_replace("/\s+/"," ",$text);<br />
&nbsp;&nbsp;&nbsp;&nbsp;$text = preg_replace('/\\"/',"''",$text);     </p>
<p>?&gt;</p>
<p>                &lt;script type="text/javascript"&gt;<br />
                        &nbsp;&nbsp;&nbsp;&nbsp;document.write('&lt;?php echo $text; ?&gt;');<br />
                &lt;/script&gt;</p>
<p></code></p>
<p>That solution works (at least, it did before I had to replace all the tags with html entities to make this post).  The text gets written at that point in the document once it loads on the client-side.  Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced.  But what if you want something more complicated&#8230; what if you don&#8217;t like the regular expressions and having to escape your double-quotes?  The above method is sorta techie for some, and prone to error.  There is another solution: use an Ajax library to pipe HTML directly to a div tag.  This solution is more scalable because you can put all the HTML in a separate file, and you don&#8217;t have to escape characters.</p>
<p>Download this Javascript library from <a href="http://www.prototypejs.org/">http://www.prototypejs.org/</a> and copy the file somewhere in your site&#8217;s html directory (here I called it div_updater.js and put it in my js directory).  Reference the file in a script tag using the &#8217;src&#8217; element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.</p>
<p><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="target_div"&gt;&lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;script type="text/javascript" src="js/div_updater.js"&gt;&lt;/script&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;script type="text/javascript"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Ajax.Updater('target_div', 'include_file.php');<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/script&gt;<br />
</code></p>
<p>This solution will write the text to where-ever you have the target_div.  Just make sure you use give the div an &#8216;id&#8217; and that its name is referenced correctly by the Updater function.  Using one of these solutions, you can utilize javascript to hide text from the search engines.<br />
<!--adsense--></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.fireproofsocks.com%2Fphp%2Fusing-javascript-documentwrite-for-seo%2F';
  addthis_title  = 'Using+Javascript+document.write+for+SEO';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.fireproofsocks.com/php/using-javascript-documentwrite-for-seo/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
