<?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>Reversed Entropy</title>
	<atom:link href="http://reversedentropy.net/feed" rel="self" type="application/rss+xml" />
	<link>http://reversedentropy.net</link>
	<description>Can entropy ever be reversed?</description>
	<lastBuildDate>Sun, 25 Sep 2011 03:56:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>mflowDet 1.3</title>
		<link>http://reversedentropy.net/wordpress/mflowdet-1-3</link>
		<comments>http://reversedentropy.net/wordpress/mflowdet-1-3#comments</comments>
		<pubDate>Sun, 25 Sep 2011 03:48:38 +0000</pubDate>
		<dc:creator>Angel</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://reversedentropy.net/?p=76</guid>
		<description><![CDATA[I just updated my mflow widget to add some functionality and bug fixes. You can check it's page to check the whole changelog and download it, as I don't have automatic updates yet.]]></description>
			<content:encoded><![CDATA[<p>I just updated my mflow widget to add some functionality and bug fixes. <a href="http://reversedentropy.net/wordpress/mflowdet-mflow-widget-for-wordpress">You can check it's page</a> to check the whole changelog and download it, as I don't have automatic updates yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://reversedentropy.net/wordpress/mflowdet-1-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cron job to check if minecraft server is running</title>
		<link>http://reversedentropy.net/system-administration/cron-job-to-check-if-minecraft-server-is-running</link>
		<comments>http://reversedentropy.net/system-administration/cron-job-to-check-if-minecraft-server-is-running#comments</comments>
		<pubDate>Sun, 25 Sep 2011 02:49:03 +0000</pubDate>
		<dc:creator>Angel</dc:creator>
				<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://reversedentropy.net/?p=64</guid>
		<description><![CDATA[I wrote a little script that checks if my Minecraft server status is running, and if it's not try to start it up. I run my server on Ubuntu and I use a wrapper I found on a forum. I can't find the post now (it was on http://www.minecraftforums.com), but I will post it in [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a little script that checks if my Minecraft server status is running, and if it's not try to start it up. I run my server on Ubuntu and I use a wrapper I found on a forum. I can't find the post now (it was on http://www.minecraftforums.com), but I will post it in case anyone want to use this solution, seems to work pretty well and has bukkit support.</p>
<p>My script will call the service status, check if the status is 'not running' or 'running', start it if it's not running and mail myself the results. I'm running it every 5 minutes using cron and, for now, it has waken the server 2 times in 24 hours. This is great as some friends play while I'm sleeping, so they won't wake me up in order to reset the server!</p>
<p>My crontab line is:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>minecraft<span style="color: #000000; font-weight: bold;">/</span>check.sh <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> check.log</div></td></tr></tbody></table></div>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/sh</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Email config</span><br />
<span style="color: #007800;">mail_bin</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail<br />
<span style="color: #007800;">mail_subject</span>=<span style="color: #ff0000;">&quot;Minecraft server&quot;</span><br />
<span style="color: #007800;">mail_address</span>=<span style="color: #ff0000;">&quot;devnulls@gmail.com&quot;</span><br />
<span style="color: #007800;">mail_file</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(mktemp)</span>&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Example for worlds=&quot;mars venus earth&quot;</span><br />
<span style="color: #666666; font-style: italic;"># minecraft_server contains your wrapper script file</span><br />
<span style="color: #007800;">worlds</span>=<span style="color: #ff0000;">&quot;mars&quot;</span><br />
<span style="color: #007800;">minecraft_server</span>=<span style="color: #ff0000;">&quot;/etc/init.d/minecraft_server&quot;</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;----------------------- MINECRAFT BARKING DAEMON -----------------------&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;------------------------------------------------------------------------&quot;</span><br />
<br />
check_servers<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">w</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$worlds</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Checking <span style="color: #007800;">$w</span> status...&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">status</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$minecraft_server</span> status <span style="color: #007800;">$w</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'not running'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$status</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;<span style="color: #007800;">${status/not running/}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$w</span> is offline, trying to restart it...&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$w</span> is offline, trying to restart it...&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$mail_file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">$minecraft_server</span> start <span style="color: #007800;">$w</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail <span style="color: #660033;">-s</span> <span style="color: #007800;">$mail_subject</span> <span style="color: #007800;">$mail_address</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$mail_file</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$w</span> is online&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$w</span> is online&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$mail_file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail <span style="color: #660033;">-s</span> <span style="color: #007800;">$mail_subject</span> <span style="color: #007800;">$mail_address</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$mail_file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;------------------------------------------------------------------------&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># MAIN</span><br />
check_servers<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://reversedentropy.net/system-administration/cron-job-to-check-if-minecraft-server-is-running/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usando los DNS dinámicos de CDmon</title>
		<link>http://reversedentropy.net/internet/usando-los-dns-dinamicos-de-cdmon</link>
		<comments>http://reversedentropy.net/internet/usando-los-dns-dinamicos-de-cdmon#comments</comments>
		<pubDate>Sun, 26 Jun 2011 01:38:52 +0000</pubDate>
		<dc:creator>Angel</dc:creator>
				<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://reversedentropy.net/?p=56</guid>
		<description><![CDATA[Llevo varios meses mudando todos mis dominios desde GoDaddy y algún otro registrador a CDmon. Su servicio de atención al cliente es muy bueno, sus precios competitivos y son una compañía nacional, que siempre es bueno. Andaba buscando la forma de, ahora que tengo IP dinámica otra vez, poder volver siempre a mi equipo sin [...]]]></description>
			<content:encoded><![CDATA[<p>Llevo varios meses mudando todos mis dominios desde GoDaddy y algún otro registrador a <a href="https://www.cdmon.com/">CDmon</a>. Su servicio de atención al cliente es muy bueno, sus precios competitivos y son una compañía nacional, que siempre es bueno.</p>
<p>Andaba buscando la forma de, ahora que tengo IP dinámica otra vez, poder volver siempre a mi equipo sin tener que usar servicios externos, aplicaciones funcionando constantemente y soluciones similares. Así que, a medio camino de escribir un script enorme para navegar a través del panel de administración y cambiar el registro de IP de un subdominio, he encontrado que CDmon ofrece un servicio de <a href="http://info.cdmon.com/index.php?page=uso-de-la-api-de-actualizacion-de-ip-dinamica">DNS dinámico con API</a>.</p>
<p>En Mac OS (también funcionará en Linux y seguramente no sea difícil hacerlo funcionar en Windows) ha sido tan fácil como añadir un cronjob que se ejecuta cada 10 minutos, haciendo simplemente una petición a la API de CDmon que actualiza la IP.</p>
<p>Dejo aquí como referencia lo que hay en mi crontab, solo hay que sustituir USR por tu usuario y PWD por el MD5 de tu contraseña. Ojo, que no es el usuario con el que accedes al panel de CDmon, si no el que hayas creado para actualizar ese subdominio.</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>curl <span style="color: #660033;">--silent</span> <span style="color: #ff0000;">&quot;https://dinamico.cdmon.org/onlineService.php?enctype=MD5&amp;amp;n=USR&amp;amp;p=PWD&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</div></td></tr></tbody></table></div>
<p>PD. Sí, voy a empezar a escribir en castellano por aquí.</p>
]]></content:encoded>
			<wfw:commentRss>http://reversedentropy.net/internet/usando-los-dns-dinamicos-de-cdmon/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validating email addresses</title>
		<link>http://reversedentropy.net/language-agnostic/validating-email-addresses</link>
		<comments>http://reversedentropy.net/language-agnostic/validating-email-addresses#comments</comments>
		<pubDate>Sat, 26 Jun 2010 19:30:53 +0000</pubDate>
		<dc:creator>Angel</dc:creator>
				<category><![CDATA[Language Agnostic]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://reversedentropy.net/?p=38</guid>
		<description><![CDATA[Email address validation is a common issue in any language, but it's more common in those oriented to create web pages like PHP. The standar for email address naming is the RFC 2882, and it's long, long and complicated. Too complicated to fit in a regular expression, so I don't recommend anybody to try a regex implementation [...]]]></description>
			<content:encoded><![CDATA[<p>Email address validation is a common issue in any language, but it's more common in those oriented to create web pages like PHP.</p>
<p>The standar for email address naming is the <a href="http://tools.ietf.org/html/rfc2822#section-3.4.1">RFC 2882</a>, and it's long, long and complicated. Too complicated to fit in a regular expression, so I don't recommend anybody to try a regex implementation of the full standar, it's simply impossible.</p>
<p>The best approach to solve this particular problem is to write a small and understandable regular expression that accepts some invalid email addresses but catches all the valid ones. Is better to let some inexistent emails than don't let an user register with his completely valid and working email.</p>
<p>Double check: one using regex and once passed validate the email address on the only way that you'll now that is valid for sure: send an email containing an activation link.</p>
<p>Since we are going to double check is OK to trust the client and do the first validation using JavaScript. Once passed  we'll send an email to that address on the server side, and it won't be confirmed until the activation link is clicked, so as I said before: is OK if you get some invalid email address.</p>
<p>Keeping it simple: I only check for <em>something</em> followed for a <em>@</em> then <em>another something</em> with a <em>dot</em> and a final <em>something</em> (with any characters and even more dots!).</p>
<div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">/</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">.+</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">.+</span><span style="color: #000000;">&#41;</span>\<span style="color: #000000;">.</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">.+</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">/</span></div></div>
<p>The above regular expression will:</p>
<p>Match</p>
<div id="_mcePaste">
<ul>
<li>user@mail.com</li>
<li>user+mail@mail.com</li>
<li>user+mail@mail.co.uk</li>
<li>mail@mail.commm</li>
<li>user/mail@gmail.com</li>
</ul>
</div>
<div>Not Match</div>
<div>
<ul>
<li>user+mail@.com</li>
<li>@mail.com</li>
<li>user@mail</li>
</ul>
</div>
<p>As said, it will match invalid email addresses, just confirm them sending an email, the rest is just meaningless effort to solve a problem that cannot be solved using regular expressions.</p>
]]></content:encoded>
			<wfw:commentRss>http://reversedentropy.net/language-agnostic/validating-email-addresses/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cookies, cURL and PHP without a jar</title>
		<link>http://reversedentropy.net/php/cookies-curl-and-php-without-a-jar</link>
		<comments>http://reversedentropy.net/php/cookies-curl-and-php-without-a-jar#comments</comments>
		<pubDate>Mon, 21 Jun 2010 23:11:46 +0000</pubDate>
		<dc:creator>Angel</dc:creator>
				<category><![CDATA[cURL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://reversedentropy.net/?p=18</guid>
		<description><![CDATA[cURL is one of the best ways of implementing the client side of a RESTful service with PHP, is also really handy to take some data from other websites and do with it whatever you want. Taking this data can be a problem when you need to autenticate on the third party website using cookies. Rest [...]]]></description>
			<content:encoded><![CDATA[<p>cURL is one of the best ways of implementing the client side of a RESTful service with PHP, is also really handy to take some data from other websites and do with it whatever you want.</p>
<p>Taking this data can be a problem when you need to autenticate on the third party website using cookies. Rest supports sending and retrieving them, but all the tutorials I've found use txt files to cache those cookies for being able to send them back to the server.</p>
<p>I don't like this approach, so let's see how to grab and store them on-the-fly using a simple regular expresion. First, let's setup a simple authentication page in PHP.</p>
<p>We're going to do at least two connections to the target server, the first one will send the password to the form and grab the cookie, the second one will call again the same server but this time we will send the cookie along our petitions, so we can navigate through private pages like we were a normal user.</p>
<p><span id="more-18"></span></p>
<p>I think that the first file (set.php) don't need commenting, is pretty basic and it only show debug text and sets the cookies/sessions. It would be something like this:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> pre<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;pre&gt;&quot;</span><span style="color: #339933;">;</span> <a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&amp;lt;\/pre&amp;gt;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
 <br />
<br />
<a href="http://www.php.net/session_start"><span style="color: #990000;">session_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/setcookie"><span style="color: #990000;">setcookie</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TestCookie1&quot;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/setcookie"><span style="color: #990000;">setcookie</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TestCookie2&quot;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">/* expire in 1 hour */</span><br />
<a href="http://www.php.net/setcookie"><span style="color: #990000;">setcookie</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TestCookie3&quot;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;/~rasmus/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.example.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> OR <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;Island&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;John&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You're logged in as &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; (Private, using cURL with POST)&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You're now logged in as &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; (Private, using cURL with Cookies)&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;(Public Access - No auth received)&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHPSESSID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; pre<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Here are the cookies sent:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; pre<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The following code is the interesting part, here you can see how to do the cURL connection, grab the cookies and prepare them to be sent back with the next request.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/* A little function to trace the results when<br />
&nbsp;* needed, is not used on the functionality<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">function</span> pre<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<br />
<br />
<br />
&lt;pre&gt;&quot;</span><span style="color: #339933;">;</span> <a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&amp;lt;\/pre&amp;gt;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
 <br />
<br />
<span style="color: #666666; font-style: italic;">/* We open the first cURL connection against an authentication form<br />
&nbsp;* using only a valid password,<br />
&nbsp;*/</span><br />
<span style="color: #000088;">$webservice</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.reversedentropy.net/scripts/cookie-set.php&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_init"><span style="color: #990000;">curl_init</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$webservice</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password=Island&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp;<span style="color: #666666; font-style: italic;">// Execute the request</span><br />
<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_exec"><span style="color: #990000;">curl_exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* We need to use regex to catch the cookies from the received<br />
&nbsp;* header and match them to a variable<br />
&nbsp;*/</span><br />
<a href="http://www.php.net/preg_match_all"><span style="color: #990000;">preg_match_all</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/Set-Cookie: (.*)/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$request</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookies</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* Let's show the header to see which cookies did we receive.<br />
&nbsp;*<br />
&nbsp;*/</span><br />
pre<span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* Now that we have an array with all the cookies we need to parse<br />
&nbsp;* them in order to be able to send them back in the second request<br />
&nbsp;* against the server, so first of all we'll create a new variable<br />
&nbsp;* to store them.<br />
&nbsp;*/</span><br />
<span style="color: #000088;">$jar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookies</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* This is a little tricky, as the cookies may have a path or expire<br />
&nbsp; &nbsp; &nbsp;* time set that we don't need at all but can interfere with the parse<br />
&nbsp; &nbsp; &nbsp;* so first we'll catch the cookie name (as $ckey)<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$ckey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* Then we have two possible scenarios: no more parameters apart from the<br />
&nbsp; &nbsp; &nbsp;* cookie and it's value, and a path, lifetime... If there's a &quot;;&quot; on the<br />
&nbsp; &nbsp; &nbsp;* string there's another parameter, so we explode again and catch only<br />
&nbsp; &nbsp; &nbsp;* the cookie value, forgetting about the rest. If there's no &quot;;&quot; we catch<br />
&nbsp; &nbsp; &nbsp;* directly the value and set it to $cval.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$cval</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$cval</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* The string containing all cookies should be in key=value;key=value[..] format<br />
&nbsp; &nbsp; &nbsp;* so we'll first of all remove all whitespaces, then urlencode the value and<br />
&nbsp; &nbsp; &nbsp;* add it to the $jar string that we created before<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$cval</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\s+/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cval</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$cval</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cval</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$jar</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$ckey</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$cval</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;; &quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* Now we'll output the cookie string as reference and make another<br />
&nbsp;* call to the same server, thsi time without posting any password<br />
&nbsp;* We'll show the response as we want to see the logged message<br />
&nbsp;*/</span><br />
pre<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cookies inside the virtual jar:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
pre<span style="color: #009900;">&#40;</span><span style="color: #000088;">$jar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>By now we got a virtual cookie jar processed, we have all the cookies (the test script is setting a PHPSESSID and three test cookies without any relevant data) and we can store them on a database, on a file or work directly with them on the same script. So let's try it, we are going now to call the same server, but we're not going to send the password, we'll send the cookie.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_COOKIE<span style="color: #339933;">,</span> <span style="color: #000088;">$jar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_exec"><span style="color: #990000;">curl_exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* And that's it, we're now logging against this server using cookies<br />
&nbsp;* on-the-fly, without storing them. &nbsp;<br />
&nbsp;*/</span><br />
pre<span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/curl_close"><span style="color: #990000;">curl_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>And that's it, easy, right? You can see a <a href="http://www.reversedentropy.net/scripts/cookie-get.php">little demo of this script</a> working here, or <a href="http://reversedentropy.net/wp-content/uploads/2010/06/cookies-curl.zip">download a zip containing the example source</a> code. </p>
]]></content:encoded>
			<wfw:commentRss>http://reversedentropy.net/php/cookies-curl-and-php-without-a-jar/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>mflowDet: mflow widget for WordPress</title>
		<link>http://reversedentropy.net/wordpress/mflowdet-mflow-widget-for-wordpress</link>
		<comments>http://reversedentropy.net/wordpress/mflowdet-mflow-widget-for-wordpress#comments</comments>
		<pubDate>Wed, 16 Jun 2010 22:19:36 +0000</pubDate>
		<dc:creator>Angel</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://reversedentropy.net/?p=3</guid>
		<description><![CDATA[View download links and changelog info. Do you know what is mflow? As many people said, in few words, is the son of Twitter and iTunes. Right now it's only available on the UK, but probably will spread across Europe soon. You can read more and try it on it's website. I just coded a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="#changelog">View download links and changelog info.</a></p>
<p>Do you know what is mflow? As many people said, in few words, is the son of Twitter and iTunes. Right now it's only available on the UK, but probably will spread across Europe soon. You can read more and try it <a href="http://www.mflow.com" target="_blank">on it's website.</a></p>
<p>I just coded a little widget for WordPress that grabs the last flow from your <a href="http://www.mflow.com" target="_blank">mflow</a> web profile (<a href="http://my.mflow.com/Adirael" target="_blank">http://my.mflow.com/username</a>) and adds it to your sidebar.</p>
<p>This plugin used to work with an HTML parser, now it just uses the mflow API. Still missing a lot of things but it gets the job done!</p>
<p>The installation is simple: drop the mflowdet folder into your plugins folder and add the widget on the Appearance section of your WordPress admin panel, there you can change the username.</p>
<p><span style="text-decoration: underline;"><a name="changelog"></a>Changelog</span></p>
<p>1.3 (<a href="http://reversedentropy.net/wp-content/uploads/2010/06/mflowdet-1.3.zip">Download</a>)</p>
<ul>
<li>Fixed date</li>
<li>Fixed user URL (mflow changed their url scheme)</li>
<li>Added option to show more than 1 flows (up to 10)</li>
</ul>
<p>1.2 (<a href="http://reversedentropy.net/wp-content/uploads/2010/06/mflowdet-1.2.zip">Download</a>)</p>
<ul>
<li>PHP4+ Compatibility added</li>
<li>Removed PHP Simple HTML DOM Parser</li>
<li>Uses the <a href="http://code.google.com/p/mflowapi/">mflow API</a> to grab the data</li>
<li>Cleaner code</li>
<li>Pre custom HTML built</li>
<li>Plugin cache has been removed as I am grabbing the data from a web service. I'll add it again if needed.</li>
</ul>
<p>1.1 (<a href="http://reversedentropy.net/wp-content/uploads/2010/06/mflowdet.zip">Download</a>)</p>
<ul>
<li>Removed classes and objects from the plugin.</li>
<li>Changed the data array to made it more understandable</li>
<li>Minor bug fixes</li>
</ul>
<p>1.0 (Not available)</p>
<ul>
<li>First version</li>
</ul>
<p><span style="text-decoration: underline;">Requeriments</span></p>
<ul>
<li>PHP4+</li>
<li>WordPress 2.7.x or higher</li>
<li>PHP Simple HTML DOM Parser (included)</li>
</ul>
<p><span style="text-decoration: underline;">Roadmap</span></p>
<ul>
<li>Add an option to output custom HTML</li>
<li>Add error handling for the web service and the plugin itself</li>
<li>Upload to wordpress.org and have automatic updates</li>
</ul>
<p><span style="text-decoration: underline;">Known Issues</span></p>
<ul>
<li>Fails when the last flow is an album (only occurs when buying and flowing the whole album)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://reversedentropy.net/wordpress/mflowdet-mflow-widget-for-wordpress/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

