<?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>Matheus Bratfisch &#187; php</title>
	<atom:link href="http://www.matbra.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matbra.com</link>
	<description>&#34;Cogito ergo sum&#34;</description>
	<lastBuildDate>Tue, 20 Dec 2011 00:03:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>URL Shortener using Auto-Increment field.</title>
		<link>http://www.matbra.com/en/2009/10/19/nova-versao-do-lurl-tiny-url/</link>
		<comments>http://www.matbra.com/en/2009/10/19/nova-versao-do-lurl-tiny-url/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 01:49:49 +0000</pubDate>
		<dc:creator>Matheus (X-warrior) Bratfisch</dc:creator>
				<category><![CDATA[Aprendendo]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[tinyurl]]></category>

		<guid isPermaLink="false">http://www.matbra.com/?p=597</guid>
		<description><![CDATA[Good Night, This is a new version of URL-Shortener that don&#8217;t create random IDs to websites, it uses the auto-increment field and replace it to other base. It was necessary to create two new methods function convertDecimalTo&#40;$decimal,$newBase,$str,$letters&#41; &#123; &#160; &#160; &#160; &#160; if &#40;$decimal &#62;= $newBase&#41; &#123; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Good Night,</p>
<p>This is a new version of URL-Shortener that don&#8217;t create random IDs to websites, it uses the auto-increment field and replace it to other base. </p>
<p><span id="more-597"></span></p>
<p>It was necessary to create two new methods</p>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">function</span> convertDecimalTo<span class="br0">&#40;</span><span class="re0">$decimal</span><span class="sy0">,</span><span class="re0">$newBase</span><span class="sy0">,</span><span class="re0">$str</span><span class="sy0">,</span><span class="re0">$letters</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$decimal</span> <span class="sy0">&gt;=</span> <span class="re0">$newBase</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$x</span> <span class="sy0">=</span> <span class="re0">$decimal</span> <span class="sy0">%</span> <span class="re0">$newBase</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$y</span> <span class="sy0">=</span> <span class="re0">$decimal</span> <span class="sy0">/</span> <span class="re0">$newBase</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$str</span> <span class="sy0">=</span> <span class="re0">$letters</span><span class="br0">&#123;</span><span class="re0">$x</span><span class="br0">&#125;</span> <span class="sy0">.</span> <span class="re0">$str</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$y</span> <span class="sy0">&lt;</span> <span class="re0">$newBase</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$str</span> <span class="sy0">=</span> <span class="re0">$letters</span><span class="br0">&#123;</span><span class="re0">$y</span><span class="br0">&#125;</span> <span class="sy0">.</span> <span class="re0">$str</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> convertDecimalTo<span class="br0">&#40;</span><span class="re0">$y</span><span class="sy0">,</span><span class="re0">$newBase</span><span class="sy0">,</span><span class="re0">$str</span><span class="sy0">,</span><span class="re0">$letters</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$str</span><span class="br0">&#41;</span> <span class="sy0">==</span> 0<span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$str</span> <span class="sy0">=</span> <span class="re0">$letters</span><span class="br0">&#123;</span><span class="re0">$decimal</span><span class="br0">&#125;</span> <span class="sy0">.</span> <span class="re0">$str</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$str</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">function</span> convertBaseToDecimal<span class="br0">&#40;</span><span class="re0">$value</span><span class="sy0">,</span><span class="re0">$newBase</span><span class="sy0">,</span><span class="re0">$letters</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sum</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$len</span> <span class="sy0">=</span> <a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$end</span> <span class="sy0">=</span> <span class="re0">$len</span><span class="sy0">-</span><span class="nu0">1</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$x</span><span class="sy0">=</span><span class="re0">$end</span><span class="sy0">;</span><span class="re0">$x</span><span class="sy0">&gt;=</span><span class="nu0">0</span><span class="sy0">;</span><span class="re0">$x</span><span class="sy0">&#8211;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sum</span> <span class="sy0">=</span> <span class="re0">$sum</span> <span class="sy0">+</span> <a href="http://www.php.net/strpos"><span class="kw3">strpos</span></a><span class="br0">&#40;</span><span class="re0">$letters</span><span class="sy0">,</span><span class="re0">$value</span><span class="br0">&#123;</span><span class="re0">$x</span><span class="br0">&#125;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$newBase</span><span class="sy0">,</span><span class="br0">&#40;</span><span class="re0">$end</span> <span class="sy0">-</span> <span class="re0">$x</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$sum</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>You can download the full new version to PHP4<br />
<a href='http://www.matbra.com/2009/10/19/nova-versao-do-lurl-tiny-url/lurl2-php/' rel='attachment wp-att-598'>URL Shortener (LURL) using auto increment field to generate the &#8220;TAG&#8221;</a></p>
<p>Hope you enjoy,<br />
Matheus</p>
<p><a href="http://www.matbra.com/en/2009/07/04/graficos-para-seu-tiny-url/">Chart to your URL Shortener with Statistics. PHP4</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.matbra.com/en/2009/10/19/nova-versao-do-lurl-tiny-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Flickr Widget 1.2.10.2, WordPress</title>
		<link>http://www.matbra.com/en/2009/07/05/quick-flickr-widget/</link>
		<comments>http://www.matbra.com/en/2009/07/05/quick-flickr-widget/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 20:37:46 +0000</pubDate>
		<dc:creator>Matheus (X-warrior) Bratfisch</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[quick]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.matbra.com/?p=360</guid>
		<description><![CDATA[Hello, The author of Quick-Flickr-Widget the Konstantin Kovshenin just launched a new version. So I decided to re-update his plugin with my modifications to get a better random system. Quick-Flickr-Widget 1.2.10.2 &#8211; With random on tags Quick-Flickr-Widget first modification in version 1.2.7.2 (Explain better what is the updates that I did) Best Regards, Matheus]]></description>
			<content:encoded><![CDATA[<p>Hello,</p>
<p>The author of <a href="http://wordpress.org/extend/plugins/quick-flickr-widget/" target="_blank">Quick-Flickr-Widget</a> the <a href="http://kovshenin.com/"  target="_blank">Konstantin Kovshenin</a> just launched a new version. So I decided to re-update his plugin with my modifications to get a better random system. </p>
<p><a href="http://www.matbra.com/?attachment_id=359">Quick-Flickr-Widget 1.2.10.2 &#8211; With random on tags</a></p>
<p><a href="http://www.matbra.com/2009/05/06/quick-flickr-widget-wordpress/">Quick-Flickr-Widget first modification in version 1.2.7.2</a> (Explain better what is the updates that I did)</p>
<p>Best Regards,<br />
Matheus</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matbra.com/en/2009/07/05/quick-flickr-widget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chart to your URL Shortener with Statistics.</title>
		<link>http://www.matbra.com/en/2009/07/04/graficos-para-seu-tiny-url/</link>
		<comments>http://www.matbra.com/en/2009/07/04/graficos-para-seu-tiny-url/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 21:01:03 +0000</pubDate>
		<dc:creator>Matheus (X-warrior) Bratfisch</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programação]]></category>

		<guid isPermaLink="false">http://www.matbra.com/?p=353</guid>
		<description><![CDATA[Hello I decided to implement a Chart vision of the access to a address of the last 30 days. THe system that I choosed is Open Flash Chart. The new methods: getAccess($id) &#8211; Return an Associative Array with the access by date and the total formatData($data) &#8211; Receive the access of getAccess and transform it [...]]]></description>
			<content:encoded><![CDATA[<p>Hello</p>
<p>I decided to implement a Chart vision of the access to a address of the last 30 days. THe system that I choosed  is <a href="http://teethgrinder.co.uk/open-flash-chart/">Open Flash Chart</a>. </p>
<p>The new methods:<br />
getAccess($id) &#8211; Return an Associative Array with the access by date and the total<br />
formatData($data) &#8211; Receive the access of getAccess and transform it in a Numeric Array.<br />
criarLabels() &#8211; Create the labels to the bottom part of the chart.</p>
<p>If you want to access it, you have to manually get the ID and use http://www.example.com/diretorio/chart.php?id=ID where ID is UID from the MySQL table.</p>
<p>Example:<br />
<script src="js/swfobject.js" type="text/javascript"></script><br />
<object id="ie_chart" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="500" height="250" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="align" value="middle" /><param name="allowScriptAccess" value="sameDomain" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><param name="src" value="http://www.matbra.com/lurl/open-flash-chart.swf?width=500&amp;height=250&amp;data=http%3A%2F%2Fwww.matbra.com%2Flurl%2Fchart-data.php%3Fid%3D50" /><param name="name" value="chart" /><embed id="ie_chart" type="application/x-shockwave-flash" width="500" height="250" src="http://www.matbra.com/lurl/open-flash-chart.swf?width=500&amp;height=250&amp;data=http%3A%2F%2Fwww.matbra.com%2Flurl%2Fchart-data.php%3Fid%3D50" name="chart" bgcolor="#FFFFFF" quality="high" allowscriptaccess="sameDomain" align="middle"></embed></object></p>
<p><a href="http://www.matbra.com/?attachment_id=369">URL Shortener with Statistics and Chart.</a></p>
<p><a href="http://www.matbra.com/en/2009/05/09/criando-seu-proprio-tiny-url/">Creating your own Url shortener</a><br />
<a href="http://www.matbra.com/en/2009/07/02/estatisticas-no-seu-tinyurl/">Statistics on your URL Shortener</a></p>
<p>Best Regards,<br />
Matheus</p>
<p>PS: Don&#8217;t forget the Rewrite Rules.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matbra.com/en/2009/07/04/graficos-para-seu-tiny-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install Apache2, PHP5, PHPmyAdmin, MySQL</title>
		<link>http://www.matbra.com/en/2009/07/04/instalar-apache2-php5-phpmyadmin-mysql/</link>
		<comments>http://www.matbra.com/en/2009/07/04/instalar-apache2-php5-phpmyadmin-mysql/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 18:47:49 +0000</pubDate>
		<dc:creator>Matheus (X-warrior) Bratfisch</dc:creator>
				<category><![CDATA[Aprendendo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[instalação]]></category>
		<category><![CDATA[phpmyadmin]]></category>

		<guid isPermaLink="false">http://www.matbra.com/?p=344</guid>
		<description><![CDATA[Hello, I will just show how to quickly install Apache 2, PHP5, MYSQL and PHPmyAdmin in Ubuntu. Install apache2 with: $ sudo apt-get install apache2 Install PHP5: $ sudo apt-get install php5 php5-common php5-cli Install MYSQL: $ sudo apt-get install mysql-client mysql-server (During the installation it will ask you password for root user of MySQL) [...]]]></description>
			<content:encoded><![CDATA[<p>Hello,</p>
<p>I will just show how to quickly install Apache 2, PHP5, MYSQL and PHPmyAdmin in Ubuntu. </p>
<p>Install apache2 with: </p>
<blockquote><p>
$ sudo apt-get install apache2
</p></blockquote>
<p>Install PHP5:</p>
<blockquote><p>
$ sudo apt-get install php5 php5-common php5-cli
</p></blockquote>
<p>Install MYSQL:</p>
<blockquote><p>
$ sudo apt-get install mysql-client mysql-server
</p></blockquote>
<p>(During the installation it will ask you password for root user of MySQL)</p>
<p>Install PHPMyAdmin:</p>
<blockquote><p>
$ sudo apt-get install phpmyadmin
</p></blockquote>
<p>(It will ask the MySQL password and of the PHPMyAdmin user)</p>
<p>Best Regards,<br />
Matheus</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matbra.com/en/2009/07/04/instalar-apache2-php5-phpmyadmin-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Statistics on your URL Shortener.</title>
		<link>http://www.matbra.com/en/2009/07/02/estatisticas-no-seu-tinyurl/</link>
		<comments>http://www.matbra.com/en/2009/07/02/estatisticas-no-seu-tinyurl/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 20:48:50 +0000</pubDate>
		<dc:creator>Matheus (X-warrior) Bratfisch</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[como fazer]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[little url]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[tinyurl]]></category>

		<guid isPermaLink="false">http://www.matbra.com/?p=336</guid>
		<description><![CDATA[Hello A few weeks ago I showed you how to create your own URL-Shortener. I decide to improve it, creating a simple system to control the number of access First of all you need to add some tables to your data base: CREATE TABLE access &#40; &#160; aid INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, &#160; urls_uid [...]]]></description>
			<content:encoded><![CDATA[<p>Hello</p>
<p>A few weeks ago I showed you <a href="http://www.matbra.com/2009/05/09/criando-seu-proprio-tiny-url/">how to create your own URL-Shortener</a>. I decide to improve it, creating a simple system to control the number of access</p>
<p>First of all you need to add some tables to your data base: </p>
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">CREATE</span> <span class="kw1">TABLE</span> access <span class="br0">&#40;</span><br />
&nbsp; aid INTEGER <span class="kw1">UNSIGNED</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span> <span class="kw1">AUTO_INCREMENT</span><span class="sy0">,</span><br />
&nbsp; urls_uid INTEGER <span class="kw1">UNSIGNED</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span><span class="sy0">,</span><br />
&nbsp; information_iid INTEGER <span class="kw1">UNSIGNED</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span><span class="sy0">,</span><br />
&nbsp; date DATE <span class="kw1">NULL</span><span class="sy0">,</span><br />
&nbsp; <span class="kw1">PRIMARY</span> <span class="kw1">KEY</span><span class="br0">&#40;</span>aid<span class="br0">&#41;</span><span class="sy0">,</span><br />
&nbsp; <span class="kw1">INDEX</span> access_FKIndex1<span class="br0">&#40;</span>information_iid<span class="br0">&#41;</span><span class="sy0">,</span><br />
&nbsp; <span class="kw1">INDEX</span> access_FKIndex2<span class="br0">&#40;</span>urls_uid<span class="br0">&#41;</span><br />
<span class="br0">&#41;</span>;</p>
<p><span class="kw1">CREATE</span> <span class="kw1">TABLE</span> information <span class="br0">&#40;</span><br />
&nbsp; iid INTEGER <span class="kw1">UNSIGNED</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span> <span class="kw1">AUTO_INCREMENT</span><span class="sy0">,</span><br />
&nbsp; ip VARCHAR<span class="br0">&#40;</span>255<span class="br0">&#41;</span> <span class="kw1">NULL</span><span class="sy0">,</span><br />
&nbsp; <span class="kw1">PRIMARY</span> <span class="kw1">KEY</span><span class="br0">&#40;</span>iid<span class="br0">&#41;</span><br />
<span class="br0">&#41;</span>;</div>
</div>
<p>After this you should do a modification in your function-little-url.php in the function take_url($url):</p>
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">function</span> take_lurl<span class="br0">&#40;</span><span class="re0">$lurl</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">global</span> <span class="re0">$link</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$q</span> <span class="sy0">=</span> <span class="st0">&quot;SELECT * FROM `urls` WHERE `unique_chars` = &#8216;&quot;</span><span class="sy0">.</span><span class="re0">$lurl</span><span class="sy0">.</span><span class="st0">&quot;&#8217;&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$r</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$q</span><span class="sy0">,</span> <span class="re0">$link</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// Realiza consulta.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/mysql_num_rows"><span class="kw3">mysql_num_rows</span></a><span class="br0">&#40;</span><span class="re0">$r</span><span class="br0">&#41;</span><span class="sy0">&gt;</span>0<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$info</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_fetch_array"><span class="kw3">mysql_fetch_array</span></a><span class="br0">&#40;</span><span class="re0">$r</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$url</span> <span class="sy0">=</span> <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;url&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span> <span class="co1">// Pega endereço real</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$uid</span> <span class="sy0">=</span> <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;uid&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span> <span class="co1">// Pega ID do endereço</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$ip</span> <span class="sy0">=</span> <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st_h">&#8216;REMOTE_ADDR&#8217;</span><span class="br0">&#93;</span><span class="sy0">;</span> <span class="co1">// Pega IP do usuário</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$qr</span> <span class="sy0">=</span> <span class="st0">&quot;select iid from `information` where ip = &#8216;&quot;</span><span class="sy0">.</span><span class="re0">$ip</span><span class="sy0">.</span><span class="st0">&quot;&#8217;&quot;</span> <span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$rr</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$qr</span><span class="sy0">,</span> <span class="re0">$link</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp;<span class="co1">// Procura se este IP já está no banco de dados</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/mysql_num_rows"><span class="kw3">mysql_num_rows</span></a><span class="br0">&#40;</span><span class="re0">$rr</span><span class="br0">&#41;</span><span class="sy0">&gt;</span><span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1">// Caso esteja insere somente um acesso novo proveniente deste IP</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$iid</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_result"><span class="kw3">mysql_result</span></a><span class="br0">&#40;</span><span class="re0">$rr</span><span class="sy0">,</span><span class="nu0">0</span><span class="sy0">,</span><span class="st0">&quot;iid&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;INSERT INTO `access` (urls_uid,information_iid,date) values (&quot;</span><span class="sy0">.</span><span class="re0">$uid</span><span class="sy0">.</span><span class="st0">&quot;, &quot;</span><span class="sy0">.</span><span class="re0">$iid</span><span class="sy0">.</span><span class="st0">&quot;, now())&quot;</span><span class="sy0">,</span> <span class="re0">$link</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span> <span class="co1">// Caso não esteja, cria um registro com este IP e após cria um acesso.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$qr</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;INSERT INTO `information` (ip) values (&#8216;&quot;</span><span class="sy0">.</span><span class="re0">$ip</span><span class="sy0">.</span><span class="st0">&quot;&#8217;)&quot;</span><span class="sy0">,</span> <span class="re0">$link</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$iid</span> <span class="sy0">=</span> <a href="http://www.php.net/mysql_insert_id"><span class="kw3">mysql_insert_id</span></a><span class="br0">&#40;</span><span class="re0">$qr</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&quot;INSERT INTO `access` (urls_uid,information_iid,date) values (&quot;</span><span class="sy0">.</span><span class="re0">$uid</span><span class="sy0">.</span><span class="st0">&quot;, &quot;</span><span class="sy0">.</span><span class="re0">$iid</span><span class="sy0">.</span><span class="st0">&quot;, now())&quot;</span><span class="sy0">,</span> <span class="re0">$link</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">echo</span> <span class="st0">&quot;Sorry, link not found!&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$url</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>In this System there is a table with IPs that already accessed	some URL, when a URL is accessed it verify the IP, if it is on the table just create an access to this IP in the new address. Otherwise, add the IP and create the access to the address.</p>
<p><a href="http://www.matbra.com/?attachment_id=351">How to create a URL-Shortener with Statistics</a></p>
<p>Matheus</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matbra.com/en/2009/07/02/estatisticas-no-seu-tinyurl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating your own Url shortener.</title>
		<link>http://www.matbra.com/en/2009/05/09/criando-seu-proprio-tiny-url/</link>
		<comments>http://www.matbra.com/en/2009/05/09/criando-seu-proprio-tiny-url/#comments</comments>
		<pubDate>Sat, 09 May 2009 06:49:18 +0000</pubDate>
		<dc:creator>Matheus (X-warrior) Bratfisch</dc:creator>
				<category><![CDATA[Aprendendo]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[como fazer]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[little url]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[tinyurl]]></category>

		<guid isPermaLink="false">http://www.matbra.com/?p=221</guid>
		<description><![CDATA[Good Night, Here I will show you how to create your own url shortener. First of all you need to create a table like this: CREATE TABLE IF NOT EXISTS `urls` ( `uid` int(11) NOT NULL auto_increment, `url` text default NULL, `unique_chars` varchar(25) BINARY NOT NULL, PRIMARY KEY (`uid`), UNIQUE KEY `unique_chars` (`unique_chars`) ); This [...]]]></description>
			<content:encoded><![CDATA[<p>Good Night,</p>
<p>Here I will show you how to create your own url shortener. </p>
<p>First of all you need to create a table like this:</p>
<blockquote><p>
 CREATE TABLE IF NOT EXISTS `urls` (<br />
   `uid` int(11) NOT NULL auto_increment,<br />
   `url` text default NULL,<br />
   `unique_chars` varchar(25) BINARY NOT NULL,<br />
   PRIMARY KEY  (`uid`),<br />
   UNIQUE KEY `unique_chars` (`unique_chars`)<br />
 );  </p></blockquote>
<p><em>This code was taken from Abhise in this post &#8220;<a href="http://ad1987.blogspot.com/2008/12/create-your-own-tinyurl-with-php-and.html" target="_blank">Create your own tinyurl with php and mySQL</a>&#8221; that was my bigest reference, from it I took some functions and update other ones to be more efficient. For an example I changed the field to BINARY so it be CASE SENSITIVE (aaaa different from AAAA)</em></p>
<p>The Abhise says to create many files, I particularly, created one file with all functions where I add all the functions and just called the functions in the files. </p>
<p><span id="more-221"></span></p>
<p>We need a fucntion to connect/disconnect to mysql </p>
<blockquote><p>
error_reporting(E_ALL);<br />
$link;<br />
$config;<br />
function connect_db_lurl() {<br />
	global $link;<br />
	global $config;<br />
	$hostname = &#8220;localhost&#8221;;<br />
	$username = &#8220;USUARIO&#8221;;<br />
	$password = &#8220;SENHA&#8221;;<br />
	$dbname = &#8220;DATABASE&#8221;;<br />
	$link = mysql_connect($hostname, $username, $password);  // Conecta ao mysql.<br />
	mysql_select_db($dbname) or die(&#8220;Unknown database!&#8221;);   // Seleciona o Banco de dados.<br />
	$config["domain"] = &#8220;http://seudominio.com&#8221;;  // Define a configuração da URL inicial<br />
}</p>
<p>function close_db_lurl() {<br />
	mysql_close(); // Fecha a conexão com o banco de dados<br />
}
</p></blockquote>
<p>After this I created a function to redirect to the URL.</p>
<blockquote><p>function redirect($url) {<br />
	header(&#8220;Location:&#8221;.$url); // Redireciona para a url.<br />
}</p></blockquote>
<p>Than I used the function from Abhise to generate the char sequence. (I add some chars to elevate the number of combinations</p>
<blockquote><p>function generate_chars() {<br />
	$num_chars = 6; // Tamanho que você deseja as strings<br />
	$i = 0;<br />
	$my_keys = &#8220;123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&#8221;; // Caracteres que valem para formação de endereço<br />
	$keys_length = strlen($my_keys);<br />
	$url  = &#8220;&#8221;;<br />
	while($i<$num_chars) {  // Gera sequencia aleatoria<br />
		$rand_num = mt_rand(1, $keys_length-1);<br />
	   	$url .= $my_keys[$rand_num];<br />
		$i++;<br />
	}<br />
	return $url;<br />
}  </p></blockquote>
<p>Created a function to verify if the key is unique.</p>
<blockquote><p>function isUnique($chars)  {<br />
	global $link;<br />
	$q = &#8220;SELECT * FROM `urls` WHERE `unique_chars`=&#8217;&#8221;.$chars.&#8221;&#8216;&#8221;;<br />
	$r = mysql_query($q, $link);  // Verifica se a chave é unica.<br />
	if( mysql_num_rows($r)>0 ) {<br />
		return false;<br />
	} else {<br />
		return true;<br />
	}<br />
}  </p></blockquote>
<p>And other to verify if the URL is in DB</p>
<blockquote><p>function isThere($url) {<br />
	global $link;<br />
	$q = &#8220;SELECT * FROM `urls` WHERE `url`=&#8217;&#8221;.$url.&#8221;&#8216;&#8221;;<br />
	$r = mysql_query($q);  // Verifica se já existe a url<br />
	if(mysql_num_rows($r)>0) {<br />
		return true;<br />
	} else {<br />
		return false;<br />
	}<br />
}</p></blockquote>
<p>Function to create</p>
<blockquote><p>function create() {<br />
	global $link;<br />
	global $config;<br />
	$chars = generate_chars(); // Gera sequencia de caracteres.</p>
<p>	while(!isUnique($chars)){ // Verifica se é unico, se não for gera denovo.<br />
	  $chars = generate_chars();<br />
	}</p>
<p>	$url = $_GET["u"]; // Pega o endereço que está em ?u=endereço<br />
	$url = trim($url); // Retira espaços em branco do inicio e do fim<br />
	$url = mysql_real_escape_string($url);</p>
<p>	if(!isThere($url)) { // Caso não exista o endereço no banco.<br />
		$q = &#8220;INSERT INTO `urls` (url, unique_chars) VALUES (&#8216;&#8221;.$url.&#8221;&#8216;, &#8216;&#8221;.$chars.&#8221;&#8216;)&#8221;;<br />
		$r = mysql_query($q, $link); // Insere o endereço<br />
		if(mysql_affected_rows()) {<br />
			$q = &#8220;SELECT * FROM `urls` WHERE `url`=&#8217;&#8221;.$url.&#8221;&#8216;&#8221;;<br />
			$r = mysql_query($q);<br />
			$row = mysql_fetch_row($r);<br />
			echo $config["domain"].&#8221;/&#8221;.$row[2]; // Imprime endereço para acesso da nova url<br />
		} else {<br />
			 echo &#8220;Desculpe, problemas com o banco de dados.&#8221;;<br />
		}<br />
	} else { // Caso já exista<br />
		$q = &#8220;SELECT * FROM `urls` WHERE `url` = &#8216;&#8221;.$url.&#8221;&#8216;&#8221;;<br />
		$r = mysql_query($q); // Seleciona endereço para URL<br />
		$row = mysql_fetch_row($r);<br />
		echo $config["domain"].&#8221;/&#8221;.$row[2]; // Imprime endereço para acesso da url.<br />
 	}<br />
}</p></blockquote>
<p>Looking to the code I thought to create a function to get the url.</p>
<blockquote><p>function take_lurl($lurl) {<br />
	global $link;<br />
	$q = &#8220;SELECT url FROM `urls` WHERE `unique_chars` = &#8216;&#8221;.$lurl.&#8221;&#8216;&#8221;;<br />
	$r = mysql_query($q, $link); // Pega endereço original para tal string.<br />
	if(mysql_num_rows($r)>0) {<br />
		 $info = mysql_fetch_array($r);<br />
		 $url = $info["url"];<br />
	} else {<br />
		echo &#8220;Sorry, link not found!&#8221;;<br />
	}<br />
	return $url;<br />
}</p></blockquote>
<p>Created the file &#8220;functions-little-url.php&#8221; with these functions.</p>
<p>index.php:</p>
<blockquote><p><?<br />
ob_start(); //Inicia Buffer de saida<br />
include("functions-little-url.php");<br />
connect_db_lurl();<br />
$lurl = $_GET["u"]; //Sequencia de caracteres<br />
$url = take_lurl($lurl);<br />
redirect($url);<br />
close_db_lurl();<br />
ob_end_flush(); // Fecha buffer de saida<br />
?></p></blockquote>
<p>create.php:</p>
<blockquote><p><?<br />
include("functions-little-url.php");<br />
connect_db_lurl();<br />
create();<br />
close_db_lurl();<br />
?></p></blockquote>
<p>We need to add some lines do .htaccess and enable mod_rewrite.</p>
<blockquote><p><IfModule mod_rewrite.c><br />
RewriteEngine On<br />
RewriteRule   ^([1-9a-zA-Z]*)$ index.php\?u=$1 [L]<br />
</IfModule></p></blockquote>
<p>I did this in my system that uses wordpress (that already uses mod_rewrite) so it work a little bit different. This is my .htaccess</p>
<blockquote><p><IfModule mod_rewrite.c><br />
RewriteEngine On<br />
RewriteBase /</p>
<p>RewriteCond %{REQUEST_FILENAME} !-f # Verifica se a página acessada não é um arquivo real<br />
RewriteCond %{REQUEST_FILENAME} !-d# Verifica se a página acessada não é um diretório<br />
RewriteRule ^([A-Za-z0-9]{6})$ /lurl/index.php?u=$1 [L] # Caso coincida com a expressão regular redirecione para /lurl/index.php?u=$1 onde /lurl/ é o diretório que está os meus arquivos de tiny-url e [L] indica que é a ultima instrução a ser executada. </p>
<p># Caso não feche com a parte em cima continua nas regras &#8220;padrões&#8221; do WordPress<br />
RewriteCond %{REQUEST_FILENAME} !-f # Verifica se a página acessada não é um arquivo real<br />
RewriteCond %{REQUEST_FILENAME} !-d# Verifica se a página acessada não é um diretório<br />
RewriteRule . /index.php [L]<br />
</IfModule></p></blockquote>
<p>(my URL shortener is inside /lurl/ directory but the redirect was done in matbra.com/XXXXXXX so it redirects to /lurl/</p>
<p>To create URLs acess create.php?u=ADDRESS</p>
<p><a href="http://www.matbra.com/?attachment_id=219">URL-Shortener</a></p>
<p>If you have any problem feel free to contact me. </p>
<p>Best Regards,<br />
Matheus Bratfisch</p>
<p>References:<br />
&#8212;- &#8220;Tiny Url&#8221;:<br />
<a href="http://www.php.net" target="_blank">www.php.net</a><br />
<a href="http://www.wynia.org/wordpress/2007/05/06/making-your-own-tiny-urls-with-php/" target="_blank">Wynia.org</a><br />
<a href="http://www.htmlcenter.com/blog/make-your-own-tinyurl-service/" target="_blank">htmlCenter</a><br />
&#8212;- &#8220;Mod Rewrite&#8221;:<br />
<a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html" target="_blank"> Apache Mod Rewrite</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.matbra.com/en/2009/05/09/criando-seu-proprio-tiny-url/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Quick Flickr Widget, WordPress.</title>
		<link>http://www.matbra.com/en/2009/05/06/quick-flickr-widget-wordpress/</link>
		<comments>http://www.matbra.com/en/2009/05/06/quick-flickr-widget-wordpress/#comments</comments>
		<pubDate>Wed, 06 May 2009 20:19:49 +0000</pubDate>
		<dc:creator>Matheus (X-warrior) Bratfisch</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[quick]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.matbra.com/?p=164</guid>
		<description><![CDATA[Hello, I found this interesting plugin for wordpress Quick-flickr-widget. A widget to show pics from Flickr in your blog. You can configure it in many ways, to get the last pic, to use tags, to get random pics. But this last one I didn`t like, this option use a feed with your last updates. So [...]]]></description>
			<content:encoded><![CDATA[<p>Hello, </p>
<p>I found this interesting plugin for wordpress <a href="http://wordpress.org/extend/plugins/quick-flickr-widget/" target="_blank">Quick-flickr-widget</a>. A widget to show pics from Flickr in your blog. You can configure it in many ways, to get the last pic, to use tags, to get random pics. But this last one I didn`t like, this option use a feed with your last updates. So I have an idea to improve this, to get all tags, and select random tags and use this tags to select pics. It uses to random system, so it is better. </p>
<p>I implemented this in Quick Flickr Widget creating the interface and the new functions. I contacted the author of this plugin to see if he have interest to put this in his. If he don`t want to, you can take it from here. <a href="http://www.matbra.com/?attachment_id=163" target="_blank">Quick flickr widget with random tags</a></p>
<p>See you,<br />
Matheus</p>
<p>PS: I used the version as 1.2.7.2. I did this improvements in two steps that is way .2. The original version is 2.7.2 and .2 from this new implementation. Probably if the author use this it will be a different version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matbra.com/en/2009/05/06/quick-flickr-widget-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

