<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Siblog :: Web Design News &#187; Code</title>
	<atom:link href="http://www.sibagraphics.com/wp/category/web-design/resources/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sibagraphics.com/wp</link>
	<description>Web development resources, articles and discussion.</description>
	<lastBuildDate>Wed, 28 Dec 2011 13:50:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spam-proof email addresses on web sites</title>
		<link>http://www.sibagraphics.com/wp/2007/01/22/spam-proof-email-addresses-on-web-sites/</link>
		<comments>http://www.sibagraphics.com/wp/2007/01/22/spam-proof-email-addresses-on-web-sites/#comments</comments>
		<pubDate>Mon, 22 Jan 2007 08:39:56 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2007/01/22/spam-proof-email-addresses-on-web-sites/</guid>
		<description><![CDATA[Over the weekend, I cobbled together another handy javascript method for foiling evil spam bots, whilst making life easy for web developers. The script below enables you to change the subject of the email as you go as well &#8211; &#8230; <a href="http://www.sibagraphics.com/wp/2007/01/22/spam-proof-email-addresses-on-web-sites/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Over the weekend, I cobbled together another handy javascript method for foiling evil spam bots, whilst making life easy for web developers. The script below enables you to change the subject of the email as you go as well &#8211; you could add other variables like a link title too if you wished. Functions are very useful devices!</p>
<p>Firstly, the content of email.js:</p>
<blockquote><p><code>function sibaem(subject) {<br />
var username = "emailprefixhere";<br />
var domain = "whatever.com";<br />
var atsign = "@";<br />
var address = username + atsign + domain;<br />
document.write('&lt;' + 'a' + ' ' + 'href=' + '"mailto:' + address + '?Subject=' + subject + '"&gt;');<br />
}<br />
</code></p></blockquote>
<p>Save the above as email.js in your scripts folder and link to it in the head of your document like this:</p>
<blockquote><p><code>&lt;script src="scripts/email.js" type="text/javascript"&gt;&lt;/script&gt;</code></p></blockquote>
<p>Then in the body of the document, call the function with the following code where you want an email to appear, for example:</p>
<blockquote><p><code>&lt;script type="text/javascript"&gt;<br />
&lt;!--<br />
sibaem( "Website enquiry" );<br />
document.write ( 'email me&lt;/a&gt;' );<br />
//--&gt;<br />
&lt;/script&gt;&lt;noscript&gt;&lt;a href='contact_form.php' title='Complete my contact form'&gt;contact me&lt;/a&gt;&lt;/noscript&gt;</code></p></blockquote>
<p>If you wish to make the user changeable and for the email address to be visible to the human eye on your site, here&#8217;s the content of email.js:</p>
<blockquote><p><code>function sibaem(username, subject) {<br />
var domain = "whatever.com";<br />
var atsign = "@";<br />
var address = username + atsign + domain;<br />
document.write('&lt;' + 'a' + ' ' + 'href=' + '"mailto:' + address + '?Subject=' + subject + '"&gt;' + address + '&lt;/a&gt;');<br />
}<br />
</code></p></blockquote>
<p>and here&#8217;s what goes in the body:</p>
<blockquote><p><code>&lt;script type="text/javascript"&gt;<br />
&lt;!--<br />
sibaem( "youremailusername, Website enquiry" );<br />
//--&gt;<br />
&lt;/script&gt;&lt;noscript&gt;&lt;a href='contact_form.php' title='Complete my contact form'&gt;contact me&lt;/a&gt;&lt;/noscript&gt;</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2007/01/22/spam-proof-email-addresses-on-web-sites/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript Flash Detect Script</title>
		<link>http://www.sibagraphics.com/wp/2006/01/04/javascript-flash-detect-script/</link>
		<comments>http://www.sibagraphics.com/wp/2006/01/04/javascript-flash-detect-script/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 06:44:17 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2006/01/04/javascript-flash-detect-script/</guid>
		<description><![CDATA[Place this code in a .js file and link it in the head of your document: function FlashInstalled() { result = false; if (navigator.mimeTypes &#038;&#038; navigator.mimeTypes["application/x-shockwave-flash"]) { result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin; } else if (document.all &#038;&#038; (navigator.appVersion.indexOf("Mac")==-1)) { eval ('try {var &#8230; <a href="http://www.sibagraphics.com/wp/2006/01/04/javascript-flash-detect-script/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Place this code in a .js file and link it in the head of your document:</p>
<blockquote><p><code>function FlashInstalled()<br />
{<br />
result = false;<br />
if (navigator.mimeTypes &#038;&#038; navigator.mimeTypes["application/x-shockwave-flash"])<br />
{<br />
result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;<br />
}<br />
else if (document.all &#038;&#038; (navigator.appVersion.indexOf("Mac")==-1))<br />
{<br />
eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)   result = true; xObj = null;   } catch (e)   {}');<br />
}<br />
return result;<br />
}<br />
function FlashWrite(url,width,height)<br />
{<br />
document.write('&lt;OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');<br />
document.write('  codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0" ');<br />
document.write('  WIDTH=' + width + ' HEIGHT=' + height + '&gt;');<br />
document.write(' &lt;PARAM NAME=movie VALUE="' + url + '"&gt; &lt;PARAM NAME=loop VALUE=false&gt; &lt;PARAM NAME=quality VALUE=best&gt; &lt;PARAM NAME=scale value=exactfit&gt; &lt;PARAM NAME=bgcolor VALUE=#CCFFFF&gt; &lt;PARAM NAME=menu value=false&gt; ');<br />
document.write(' &lt;EMBED xsrc="' + url + '" quality=best bgcolor=#CCFFFF  loop=false scale=exactfit menu=false ');<br />
document.write(' swLiveConnect=FALSE WIDTH=' + width + ' HEIGHT=' + height);<br />
document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?<br />
P1_Prod_Version=ShockwaveFlash"&gt;');<br />
document.write(' &lt;/EMBED&gt;&lt;/OBJECT&gt;');<br />
}</code></p>
</blockquote>
<p>You can call the above code flash.js file and link it in the head of your document like this:</p>
<blockquote><p><code>&lt;script language="JavaScript1.2" xsrc="flash.js" mce_src="flash.js"      type="text/javascript"&gt;&lt;/script&gt;</code></p>
</blockquote>
<p>Then where you want your flash file to appear, place this code:</p>
<blockquote><p><code>&lt;script Language = "JavaScript" type="text/javascript"&gt;<br />
if (FlashInstalled())<br />
{<br />
FlashWrite('images/flash/yourflashfile.swf',468,240);<br />
}<br />
else<br />
{<br />
var url = "linkyourflatimagetosomefile.php"<br />
var image = "&lt;img alt='Name of your flat image' xsrc='images/flash/yourstillimage.jpg' height=240 width=468 border=0&gt;"<br />
document.write(image.link(url));}&lt;/script&gt;<br />
&lt;noscript&gt;&lt;a xhref='linkyourflatimagetosomefile.php'&gt;&lt;img alt='Name of your flat image' xsrc='images/flash/yourstillimage.jpg' height=240 width=468 border=0>&lt;/a&gt;<br />
&lt;/noscript&gt;</code></p>
</blockquote>
<p>If the browser doesn&#8217;t have flash installed or doesn&#8217;t have java turned on, they will see yourstillimage.jpg instead of the flash file. Change the file width and height to match your .swf and image files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2006/01/04/javascript-flash-detect-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image protection with .htaccess</title>
		<link>http://www.sibagraphics.com/wp/2006/01/04/image-protection-with-htaccess/</link>
		<comments>http://www.sibagraphics.com/wp/2006/01/04/image-protection-with-htaccess/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 06:26:32 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2006/01/04/image-protection-with-htaccess/</guid>
		<description><![CDATA[How to stop people stealing your images/bandwidth remotely: (1) Make an image called dontsteal.gif and place it in a directory below the directory in which you are going to put the .htaccess file. (2) Open notepad and copy this code &#8230; <a href="http://www.sibagraphics.com/wp/2006/01/04/image-protection-with-htaccess/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>How to stop people stealing your images/bandwidth remotely:</p>
<p>(1) Make an image called dontsteal.gif and place it in a directory below the directory in which you are going to put the .htaccess file.</p>
<p>(2) Open notepad and copy this code &#8230; no hard carriage returns between lines.</p>
<blockquote><p><code>RewriteEngine On<br />
RewriteCond %{HTTP_REFERER} !^$<br />
RewriteCond %{HTTP_REFERER} !^http://whateverdomain.com/.*$ [NC]<br />
RewriteCond %{HTTP_REFERER} !^http://www.whateverdomain.com/.*$ [NC]<br />
RewriteRule .*\.(gif|GIF|jpg|JPG|zip|ZIP|png|PNG|swf|SWF)$ http://www.whateverdomain.com/dontsteal.gif [R,L]</code></p>
</blockquote>
<p>(3) Change whateverdomain.com to whatever your domain is called.</p>
<p>(4) This code works with apache servers with mod_rewrite.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2006/01/04/image-protection-with-htaccess/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obscuring email addresses from spammers</title>
		<link>http://www.sibagraphics.com/wp/2006/01/04/obscuring-email-addresses-from-spammers/</link>
		<comments>http://www.sibagraphics.com/wp/2006/01/04/obscuring-email-addresses-from-spammers/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 05:58:00 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2006/01/04/obscuring-email-addresses-from-spammers/</guid>
		<description><![CDATA[Here&#8217;s how to use an image and a .js script to disguise your email address from spam bot email collectors. This method splits the email address server side. (1) Make an image of the email address you wish to use &#8230; <a href="http://www.sibagraphics.com/wp/2006/01/04/obscuring-email-addresses-from-spammers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how to use an image and a .js script to disguise your email address from spam bot email collectors. This method splits the email address server side.</p>
<p>(1) Make an image of the email address you wish to use in .jpg, .gif or .png form.</p>
<p>(2) Creat a .js script as follows*:</p>
<blockquote><p><code>var sb_domain = "yourdomain.com"<br />
var sb_user = "whatever"<br />
var sb_recipient = sb_user + "@" + sb_domain<br />
var image = "&lt;img alt='Contact Me' xsrc='images/e.png' height='11' width='166' style='margin-top:2px;border:0' /&gt;"<br />
var sb_url = "mailto:" + sb_recipient<br />
document.write(image.link(sb_url)); </code></p>
</blockquote>
<p>If you want to include a subject, use this code:</p>
<blockquote><p><code>var sb_domain = "yourdomain.com"<br />
var sb_user = "whatever"<br />
var subject = "Whatever you like"<br />
var sb_recipient = sb_user + "@" + sb_domain<br />
var image = "&lt;img alt='Contact Me' xsrc='images/e.png' height='13' width='187' style='vertical-align:bottom;border:0' /&gt;"<br />
var sb_url = "mailto:" + sb_recipient + "?subject=" + escape(subject)<br />
document.write(image.link(sb_url));</code></p>
</blockquote>
<p>* The &#8216;/&#8217; at the end of the image is for XHTML &#8211; if you are using HTML doctypes, leave it out.</p>
<p>(3) Save the file as whateveryoulike.js in your js includes directory or wherever you wish.</p>
<p>(4) Link to your .js script in the body of the page where you want it to appear as follows:</p>
<blockquote><p><code>&lt;script language="JavaScript" xsrc="directorywhereyousavedthescript/whateveryoulike.js" mce_src="directorywhereyousavedthescript/whateveryoulike.js"     type="text/javascript"&gt;&lt;/script&gt;&lt;noscript&gt;Email Me&lt;/noscript&gt;</code></p>
</blockquote>
<p>Good luck in thwarting spammers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2006/01/04/obscuring-email-addresses-from-spammers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Form Script Security</title>
		<link>http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/</link>
		<comments>http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 05:29:27 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/</guid>
		<description><![CDATA[Some ideas to tighten up form script security &#8230; more specifically to counter form spoofing and cross browser attacks. (1) Check for extra _POST variables, and disallow any _GET variables. { $limit_post=count($_POST); $limit_get=count($_GET); if ($limit_post>8&#124;&#124;$limit_get>0) { include ("formhead.php"); echo "Submission &#8230; <a href="http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some ideas to tighten up form script security &#8230; more specifically to counter form spoofing and cross browser attacks.</p>
<p>(1) Check for extra _POST variables, and disallow any _GET variables.</p>
<blockquote><p><code>{<br />
$limit_post=count($_POST);<br />
$limit_get=count($_GET);<br />
if ($limit_post>8||$limit_get>0)<br />
{<br />
include ("formhead.php");<br />
echo "Submission failed.";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(2) Prevent the exceeding of maximum field length from the server side in the script &#8211; setting form field maximum length inputs is not sufficient.</p>
<blockquote><p><code>{<br />
$length = strlen($_POST['Name'] || $_POST['Email'] || $_POST['Address'] || etc);<br />
if($length>30)<br />
{<br />
include ("formhead.php");<br />
echo "Too many characters.";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(3) Check for legal use of characters (white list approach).</p>
<blockquote><p><code>{<br />
if (eregi("[^-a-z]+$", $_POST['Name']) || eregi("[^-/\.a-z0-9]+$", $_POST['Address']) || eregi("[^-a-z]+$", $_POST['City']) etc)<br />
{<br />
include ("formhead.php");<br />
echo "Invalid characters.";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(4) Check for well-formed email address.</p>
<blockquote><p><code>{<br />
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$", $_POST['Email']))<br />
{<br />
include ("formhead.php");<br />
echo "Please enter a valid email.";<br />
$_POST['Email']="";<br />
include ("form2.php");<br />
exit;<br />
}<br />
}</code></p>
</blockquote>
<p>(5) Use quotemeta to filter output (note that quotemeta doesn&#8217;t filter the pipe character &#8211; hence the productiveness of using the previous eregi function).</p>
<p>(6) Use the Session token method described at <a class="postlink" target="_blank" href="http://shiflett.org/archive/96">http://shiflett.org/archive/96</a> to further prevent XSS attacks.</p>
<p>eg.</p>
<p>In the document head:</p>
<blockquote><p><code>&lt;?php $token = md5(uniqid(rand(), true));<br />
$_SESSION['token'] = $token; ?&gt;</code></p>
</blockquote>
<p>In the form:</p>
<blockquote><p><code>&lt;input type="hidden" name="sekret" value="&lt;?php echo $token; ?&gt;" /&gt;</code></p>
</blockquote>
<p>In the script:</p>
<blockquote><p><code> {<br />
if ($_SESSION['token'] != $_POST['token'])<br />
{<br />
echo "Invalid submission.";<br />
//go to error page<br />
exit;<br />
}<br />
} </code></p>
</blockquote>
<p>References:</p>
<p><small><a class="postlink" target="_blank" href="http://phpsec.org/projects/guide/2.html">http://phpsec.org/projects/guide/2.html</a><br />
<a class="postlink" target="_blank" href="http://www.devshed.com/c/a/PHP/Reconsidering-PHP-variables/">http://www.devshed.com/c/a/PHP/Reconsidering-PHP-variables/</a><br />
<a class="postlink" target="_blank" href="http://au.php.net/manual/en/function.quotemeta.php">http://au.php.net/manual/en/function.quotemeta.php</a><br />
<a class="postlink" target="_blank" href="http://shiflett.org/">http://shiflett.org/</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2006/01/04/php-form-script-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Countering form spam bot attacks</title>
		<link>http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/</link>
		<comments>http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 04:56:32 +0000</pubDate>
		<dc:creator>Siba</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/</guid>
		<description><![CDATA[Spammers, the dregs of the internet, are now using automated bots to explore form security. The bot completes the form to test for possible usage as a spam relay, attempting to inject extra headers which, if successful, will send the &#8230; <a href="http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Spammers, the dregs of the internet, are now using automated bots to explore form security.</p>
<p>The bot completes the form to test for possible usage as a spam relay, attempting to inject extra headers which, if successful, will send the response to the bot owner.</p>
<p>To counter their tactics, fields like the mailto, from and subject fields can be checked server side (all user input should be checked server side).</p>
<p>eg.</p>
<p>mailto:</p>
<blockquote><p><code>$to=$mailTo;<br />
if ($to !== "youraddy@yourdomain.com")<br />
{<br />
die("Getawoollyoneupyah, spammer!");<br />
}</code></p>
</blockquote>
<p>from and subject fields:</p>
<blockquote><p><code>if ((preg_match(' /[\r\n,;\'"]/ ', $_POST['Email'])) ||  (preg_match(' /[\r\n,;\'"]/ ', $mailSubject)))<br />
{<br />
die("Go away, spammer!");<br />
}</code></p>
</blockquote>
<p>Then, to prevent the bot filling in the form at all, the contact name field for example, can be checked as the bot attempts to fill in all fields with an email address.</p>
<blockquote><p><code>elseif (eregi("[^-a-z ]", $_POST[Name]))<br />
{<br />
echo "Characters in name field are invalid.";<br />
$_POST[Name] ="";<br />
} </code></p>
</blockquote>
<p>More information about the relevant email injection exploit can be found here:</p>
<p><a target="_blank" href="http://computerbookshelf.com/email_injection/">http://computerbookshelf.com/email_injection/</a><br />
<a target="_blank" href="http://securephp.damonkohler.com/index.php/Email_Injection">http://securephp.damonkohler.com/index.php/Email_Injection</a></p>
<p>There&#8217;s a form testing script linked here as well as an explanation re asp scripts:</p>
<p><a target="_blank" href="http://www.twologs.com/en/services/test/spamrelay.asp">http://www.twologs.com/en/services/test/spamrelay.asp</a></p>
<p>and a script to ban known spam bots here:</p>
<p><a target="_blank" href="http://www.foto50.com/spammercheck.phps">http://www.foto50.com/spammercheck.phps</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sibagraphics.com/wp/2006/01/04/countering-form-spam-bot-attacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

