<?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/"
	>

<channel>
	<title>Noel Rocha &#187; Programação</title>
	<atom:link href="http://www.noelrocha.com/blog/category/programacao/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.noelrocha.com/blog</link>
	<description>Capacitando o sistema...</description>
	<pubDate>Sun, 07 Jun 2009 22:09:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>O que o IE 8 tem que o Firefox não tem</title>
		<link>http://www.noelrocha.com/blog/2009/06/07/o-que-o-ie-8-tem-que-o-firefox-nao-tem/</link>
		<comments>http://www.noelrocha.com/blog/2009/06/07/o-que-o-ie-8-tem-que-o-firefox-nao-tem/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 22:09:50 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

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

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

		<category><![CDATA[Programação]]></category>

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

		<category><![CDATA[Internet Explorer 8]]></category>

		<category><![CDATA[Nova sessão]]></category>

		<category><![CDATA[recursos novos]]></category>

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=346</guid>
		<description><![CDATA[Eu nunca fui fã do IE e na maioria das vezes eu utilizo-o por necessidade seja para testar compatibilidade de sites que faço com outros navegadores ou para acessar sites que burramente só funcionam no IE.
Certa vez estudando o IE descobri que ele tem uma opção chamada &#8220;Nova sessão&#8220;.

Se você é programador web já deve [...]]]></description>
			<content:encoded><![CDATA[<p>Eu nunca fui fã do <strong>IE </strong>e na maioria das vezes eu utilizo-o por necessidade seja para testar compatibilidade de <strong>sites que faço</strong> com outros navegadores ou para acessar sites que <strong>burramente</strong> só funcionam no IE.</p>
<p>Certa vez estudando o IE descobri que ele tem uma opção chamada &#8220;<strong>Nova sessão</strong>&#8220;.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-348" title="ie8-vs-firefox1" src="http://www.noelrocha.com/blog/wp-content/uploads/2009/06/ie8-vs-firefox1.gif" alt="O que o IE 8 tem que o Firefox não tem" width="393" height="215" /></p>
<p>Se você é <strong>programador web</strong> já deve fazer idéia o que é isso e como é útil. Para quem não conhece vou explicar o que é e como pode ser útil.</p>
<p>Uma sessão seria um bilhete, passaporte, flyer e sendo mais específico um identificador entre o seu navegador e o servidor. Esse identificador é gerado de acordo com o nome do site que você está acessando e o tipo de navegador que você está utilizando.</p>
<p>Geralmente sessão é utilizada em sites como o do painel da HostNet, Gmail, Orkut e etc&#8230; para permanecer logado mesmo quando você fecha a janela ou aba e reabre novamente.</p>
<p>A opção &#8220;<strong>Nova Sessão</strong>&#8221; do IE 8 permite que você logue no Gmail, Orkut, painel da HostNet com várias contas diferentes. Por exemplo, eu posso logar com meu usuário no Orkut em uma sessão e depois abrir uma nova sessão e logar com meu usuário Fake. Nesse caso em cada sessão só terá dados pertecentes ao perfil que eu loguei.</p>
<p>Exista um site que gerenciava informações de várias empresas e para você ver a informação de uma empresa você teria que logar com o usuário referente a ela. Caso você quisesse ver informações de outra empresa você teria que deslogar de uma empresa e logar na outra. Com o tempo surgiu a necessidade de comparar dados de duas ou mais empresas lado a lado porém seria trabalhoso ficar logando e deslogando toda hora que fosse necessário ver informações de uma empresa.</p>
<p>Uma solução rápida na época a nível de servidores foi criar um alias no Virtual Host que recebesse qualquer coisa como subdomínio. Exemplo:<br />
*.site_comparador_de_empresas.com</p>
<p>Assim quando fosse necessário abrir informações de 2 empresas bastava abrir uma nova aba e digitar algo antes do domínio principal e logar com os dados da segunda empresa. Exemplo:<br />
segunda_empresa.site_comparador_de_empresas.com</p>
<p>Desse jeito era criada uma nova sessão para o domínio  segunda_empresa.site_comprador_de_empresas.com.</p>
<p>Talvez o Firefox também adote essa solução e a que citei fique obsoleta.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2009/06/07/o-que-o-ie-8-tem-que-o-firefox-nao-tem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tabela de Produto com preço total gerado a cada seleção</title>
		<link>http://www.noelrocha.com/blog/2009/06/07/tabela-de-produto-com-preco-total-gerado-a-cada-selecao/</link>
		<comments>http://www.noelrocha.com/blog/2009/06/07/tabela-de-produto-com-preco-total-gerado-a-cada-selecao/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 20:38:59 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

		<category><![CDATA[Programação]]></category>

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

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

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

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

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

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

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=331</guid>
		<description><![CDATA[Esse foi um exercício bastante interessante que tive semana passada na faculdade durante a aula de Linguagem de Script do professor Carlos Sicsu. Nesse aplicativo que faremos será utilizado as tecnologias HTML, DOM e JAVASCRIPT.
O enunciado do exercício era o seguinte:
Construir uma página que contenha uma tabela chamada &#8220;produto-preco&#8221;. A cada selecao de um produto, [...]]]></description>
			<content:encoded><![CDATA[<p>Esse foi um exercício bastante interessante que tive semana passada na faculdade durante a aula de <strong>Linguagem de Script</strong> do professor<a title="Currículo Lattes" href="http://buscatextual.cnpq.br/buscatextual/visualizacv.jsp?id=K4701776P6" target="_blank"> Carlos Sicsu</a>. Nesse aplicativo que faremos será utilizado as tecnologias <strong>HTML</strong>, <strong>DOM </strong>e <strong>JAVASCRIPT</strong>.</p>
<p>O enunciado do exercício era o seguinte:<br />
<em>Construir uma página que contenha uma tabela chamada &#8220;produto-preco&#8221;. A cada selecao de um produto, o preco total de compra deve ser visualizado ao final da tabela. O preço poderá conter casas decimais.<br />
</em></p>
<p>Criando função <em>calc_value_of_selected_products()</em> em JavaScript que calculará o preço total dos produtos:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> calc_price_of_selected_products<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// Obtendo formulário que contém os checkboxes com o valor dos produtos</span>
	<span style="color: #003366; font-weight: bold;">var</span> products    <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;product&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #006600; font-style: italic;">// Preço será do tipo float por causa dos produtos que podem ter</span>
	<span style="color: #006600; font-style: italic;">// centavos em seu valor</span>
	<span style="color: #003366; font-weight: bold;">var</span> total_price <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.0</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Verificando quais checkboxes foram selecionados e somando seu valor;</span>
  	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> products.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>products<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">checked</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			total_price <span style="color: #339933;">=</span> total_price <span style="color: #339933;">+</span> parseFloat<span style="color: #009900;">&#40;</span>products<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Atualizando div que contém o preço total dos produtos</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;total&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Total: R$ &quot;</span> <span style="color: #339933;">+</span> total_price.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Para que o valor em centavos fique com 2 casas decimais é necessário usar a função <strong>toFixed()</strong>. Exemplo de seu uso:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">parseFloat<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;10.2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// 10.20</span>
parseFloat<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;100&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// 100.00</span></pre></div></div>

<p>O preço de cada produto ficará dentro do value em cada checkbox. O checkbox deverá chamar a função calc_price_of_selected_product() que criamos toda vez que for clicado nele.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;135.00&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;calc_price_of_selected_products()&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p> A Construindo a estrutura da tabela em <strong>HTML</strong> com alguns produtos e seus respectivos preços:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;product&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Produtos<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>R$<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;135.99&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calc_price_of_selected_products()&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Oculos<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>135.99<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;53.20&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calc_price_of_selected_products()&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Sunga<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>53.20<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;97.30&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calc_price_of_selected_products()&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Biquini<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>97.30<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>A soma de todos os valores selecionados deverá ser exibido pela div total. Essa div deverá ser inserida após o formulário.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;total&quot;</span>&gt;</span>Total: R$ 0.00<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>O funcionamento desse script pode ser visto no endereço abaixo:<br />
<a href=" http://www.noelrocha.com/blog/examples/tabela_produtos_preco.html" target="_new"> http://www.noelrocha.com/blog/examples/tabela_produtos_preco.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2009/06/07/tabela-de-produto-com-preco-total-gerado-a-cada-selecao/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Função recursiva para evitar Sql Injection</title>
		<link>http://www.noelrocha.com/blog/2009/05/31/funcao-recursiva-para-evitar-sql-injection/</link>
		<comments>http://www.noelrocha.com/blog/2009/05/31/funcao-recursiva-para-evitar-sql-injection/#comments</comments>
		<pubDate>Sun, 31 May 2009 03:33:47 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

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

		<category><![CDATA[Programação]]></category>

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=322</guid>
		<description><![CDATA[Sempre gostei de fazer funções recursivas e quando posso tento utilizá-las pois acho charmosas e economizam código mas elas requerem um pouco mais de raciocíonio e atenção devido a facilidade de se criar loop/laço infinito. 
A primeira função recursiva você nunca esquece. Eu lembro que a minha primeira foi uma implementação de um rm -rf [...]]]></description>
			<content:encoded><![CDATA[<p>Sempre gostei de fazer <strong>funções recursivas</strong> e quando posso tento utilizá-las pois acho charmosas e economizam código mas elas requerem um pouco mais de raciocíonio e atenção devido a facilidade de se criar loop/laço infinito. </p>
<p>A primeira função recursiva você nunca esquece. Eu lembro que a minha primeira foi uma implementação de um rm -rf em PHP.</p>
<p>A função recursiva que está logo abaixo é útil quando se tem um site vulnerável a <strong>Sql Injection</strong> por falta de crítica dos dados ou por causa da diretiva <strong><a title="Diretiva Register Globals" href="http://br.php.net/manual/pt_BR/ini.core.php#ini.register-globals" target="_blank">register_globals</a></strong> estar habilitada. Eu fiz e nunca mais precisei dar manutenção nessa função mas se precisarem é só falar.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> 1<span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$chave</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$valor</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$chave</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$valor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Seu funcionamento é muito simples.</p>
<p><em><strong>1</strong> - Receber Argumento.<br />
<strong>2</strong> - Se o argumento não for um array ele deverá ser escapado e retornado.<br />
<strong>3</strong> - Caso contrário o elemento é um array.<br />
<strong>3.1</strong> - Logo a função escape() deverá ser chamada para cada elemento do array.<br />
<strong>3.2</strong> - O resultado da chamada da função escape() deverá ser salvo na posição em que estava o elemento.<br />
<strong>3.3</strong> - O array deverá ser retornado com os seus elementos escapados.</em></p>
<p>O modo de usar essa função é muito simples e é orientado que seja chamada antes das queries que recebem valores externos.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Escapando variáveis passadas por GET</span>
<span style="color: #000088;">$_GET</span> <span style="color: #339933;">=</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Escapando variáveis passadas por POST</span>
<span style="color: #000088;">$_POST</span> <span style="color: #339933;">=</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Exemplo de array escapado com essa função:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'select'</span> <span style="color: #339933;">=&gt;</span> 
  <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
    <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'car'</span><span style="color: #339933;">,</span>
    <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1 or \\\'\\\''</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2009/05/31/funcao-recursiva-para-evitar-sql-injection/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Se as linguagens de programação fossem religiões</title>
		<link>http://www.noelrocha.com/blog/2008/12/22/se-as-linguagens-de-programacao-fossem-religioes/</link>
		<comments>http://www.noelrocha.com/blog/2008/12/22/se-as-linguagens-de-programacao-fossem-religioes/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 23:41:17 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Outros]]></category>

		<category><![CDATA[Programação]]></category>

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

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=239</guid>
		<description><![CDATA[Esse artigo foi postado em inglês no slashdot.org. Então mãos a obra:

C seria o Judaísmo - É velho e restritivo, mas a maior parte do mundo está familiarizado com as suas leis e respeitando-as. Você não pode se converter, você tem que nascer com um, senão você achará que é uma loucura. Além disso, quando [...]]]></description>
			<content:encoded><![CDATA[<p>Esse artigo foi postado em inglês no <a href="http://www.aegisub.net/2008/12/if-programming-languages-were-religions.html"><em><strong>slashdot.org</strong></em></a>. Então mãos a obra:</p>
<ul>
<li><strong>C</strong> seria o <strong>Judaísmo</strong> - É velho e restritivo, mas a maior parte do mundo está familiarizado com as suas leis e respeitando-as. Você não pode se converter, você tem que nascer com um, senão você achará que é uma loucura. Além disso, quando as coisas correm mal, muitas pessoas estão dispostas a culpar essa linguagem por causa dos problemas do mundo.</li>
<li><strong>C + +</strong> seria <strong>Islã</strong> - Pega algumas caracteristicas do C porém não mantém todas as suas leis mas acrescenta um novo conjunto muito complexo de leis em cima. É tão versátil que pode ser usado para ser o alicerce de tudo, desde grandes atrocidades a belas obra de arte. Seus seguidores estão convencidos de que é a derradeira linguagem universal e são irritados por aqueles que discordam disso. Além disso, se você insultá-la, ou a seu fundador, provavelmente vai ser ameaçado de morte pelos mais radicais seguidores.</li>
<li><strong>Java</strong> seria <strong>O fundamentalismo Cristão</strong> - Trata-se de uma base teórica sobre C, mas vazios de tantos das antigas leis que não são originais em tudo. Em vez disso, ela adiciona o seu próprio conjunto de regras rígidas, que seus seguidores acreditam ser muito superior ao original. Não só eles estão certos de que essa é a melhor linguagem do mundo mas que estão dispostos a queimar aqueles que discordam disso.</li>
<li><strong>PHP</strong> seria <strong>Cristianismo</strong> - Combate o Java para o mercado web. Inspira-se alguns conceitos de Java e C mas fica somente com aqueles conceitos que são bons para ela. Talvez não é tão coerente quanto as outras línguas mas pelo menos ela deixa  mais liberdade e ostensivamente mantém a idéia de tudo junto. Além disso, todo o conceito de &#8220;goto inferno&#8221; foi abandonada.</li>
<li><strong>Perl</strong> seria <strong>Voodoo</strong> - Uma série de encantações incompreensíveis que envolvem o sangue de cabras e permanentemente corrompem sua alma. Muitas vezes usado quando o seu patrão exige que você faça uma tarefa urgente a 21:00 de sexta-feira à noite.</li>
<li><strong>Lua</strong> seria <strong>Wicca</strong> - Uma panteísta linguagem que é facilmente adaptada para diferentes culturas e locais. Seu código é muito liberal e permite a utilização de técnicas que poderiam ser descritas como os usados por mágicos de linguagens mais tradicionais. Tem uma forte ligação com o &#8220;mundo da lua&#8221;.</li>
<li><strong>Ruby</strong> seria <strong>Neo-Paganismo</strong> - Uma mistura de línguas diferentes e idéias que foram empacotadas em conjunto em algo que possa ser identificada como uma linguagem. Seus seguidores estão crescendo rápido, e embora a maioria das pessoas olha para ela com suspeitas são quase todas as pessoas que mexe com Ruby bem-intencionadas e que não tem a intenção de prejudicar ninguém.</li>
</ul>
<p>Parece que quem fez o artigo era católico :p mas nos comentários do post original não faltaram comparações de linguagens como Delphi, FORTRAN e JavaScript com o catolicismo porém não é minha intenção fugir mais do que fugi do post original.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2008/12/22/se-as-linguagens-de-programacao-fossem-religioes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Indicação de sites utilizando Gmail/Google Apps na HostNet</title>
		<link>http://www.noelrocha.com/blog/2008/12/16/indicacao-de-sites-utilizando-gmailgoogle-apps-na-hostnet/</link>
		<comments>http://www.noelrocha.com/blog/2008/12/16/indicacao-de-sites-utilizando-gmailgoogle-apps-na-hostnet/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 20:28:51 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

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

		<category><![CDATA[Programação]]></category>

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=191</guid>
		<description><![CDATA[Esse script é baseado no post como enviar emails autenticados pelo gmail/google apps. É altamente recomendado ler tal post antes de cair de mãos na massa no post de hoje.
Vamos a algumas considerações do script:
- Assim como a HostNet o Gmail também  não permite forjar o From(&#8221;de&#8221;), ou seja, o from(&#8221;de&#8221;) sempre será o [...]]]></description>
			<content:encoded><![CDATA[<p>Esse script é baseado no post <a title="Como enviar emails autenticados pelo gmail/google apps" href="http://www.noelrocha.com/blog/2008/07/21/como-enviar-emails-autenticados-pelo-gmailgoogle-apps" target="_blank">como enviar emails autenticados pelo gmail/google apps</a>. É altamente recomendado ler tal post antes de cair de mãos na massa no post de hoje.</p>
<p>Vamos a algumas considerações do script:<br />
- Assim como a <a href="http://www.hostnet.com">HostNet</a> o Gmail também  não permite forjar o From(&#8221;de&#8221;), ou seja, o from(&#8221;de&#8221;) sempre será o email que autenticará no Gmail. Eu utilizo o reply-to no cabeçalho para o destinatário quando clicar em responder aparecer o email de quem indicou e não do email do gmail. </p>
<p>- Outra coisa, no exemplo abaixo o debug está ligado, para desligar o debug basta comentar a linha abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      <span style="color: #0000ff;">'debug'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Debug ligado</span></pre></div></div>

<p>Esse script foi pedido pelo Ramon, acho que é isso, no post sobre o google apps.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>                                    
<span style="color: #666666; font-style: italic;">// Incluindo arquivo com a classe Mail   </span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mail.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Nome de quem está indicando o site    </span>
  <span style="color: #000088;">$indicador_nome</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meu_nome'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>    
&nbsp;
  <span style="color: #666666; font-style: italic;">// Email de quem está indicando o site</span>
  <span style="color: #000088;">$indicador_email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meu_email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Nome de quem receberá o email</span>
  <span style="color: #000088;">$nome</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nome_do_amigo'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Email que receberá o email</span>
  <span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email_do_amigo'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Nome de quem está enviando</span>
  <span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$indicador_nome</span> &lt;<span style="color: #006699; font-weight: bold;">$indicador_email</span>&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Assunto da mensagem</span>
  <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Indicação de site'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*                             
   Corpo da mensagem             
   Em caso de formulário alterar para a variável $_POST['CAMPO']
  */</span>                                                            
  <span style="color: #000088;">$body</span> <span style="color: #339933;">=</span><span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOM                                                 
Indicação de site de $indicador_nome!!!                         
EOM</span><span style="color: #339933;">;</span>                                                            
&nbsp;
  <span style="color: #666666; font-style: italic;">// Servidor do Gmail                                          </span>
  <span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ssl://smtp.gmail.com&quot;</span><span style="color: #339933;">;</span>                               
&nbsp;
  <span style="color: #666666; font-style: italic;">// Email do Gmail que fará o envio autenticado                </span>
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'noel@noelrocha.com'</span><span style="color: #339933;">;</span>                        
&nbsp;
  <span style="color: #666666; font-style: italic;">// Sua senha do GMAIL                                         </span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SECRETA'</span><span style="color: #339933;">;</span>                                        
&nbsp;
  <span style="color: #666666; font-style: italic;">// Cabeçalho do email                                         </span>
  <span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>                                            
    <span style="color: #0000ff;">'From'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$from</span><span style="color: #339933;">,</span>                                        
    <span style="color: #0000ff;">'Reply-to'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$from</span><span style="color: #339933;">,</span>                                        
    <span style="color: #0000ff;">'To'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$to</span><span style="color: #339933;">,</span>                                          
    <span style="color: #0000ff;">'Subject'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$subject</span>                                      
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                                            
&nbsp;
  <span style="color: #000088;">$smtp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Mail</span><span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtp'</span><span style="color: #339933;">,</span>                                 
    <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>                                                     
      <span style="color: #0000ff;">'host'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$host</span><span style="color: #339933;">,</span>                                      
      <span style="color: #0000ff;">'port'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">465</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// SMTPS(para mais detalhes ver /etc/services</span>
      <span style="color: #0000ff;">'auth'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>                                             
      <span style="color: #0000ff;">'debug'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Debug ligado                             </span>
      <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span>                                        
      <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span>                                         
    <span style="color: #009900;">&#41;</span>                                                                 
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                                                  
&nbsp;
  <span style="color: #666666; font-style: italic;">// Efetuando o envio autenticado                                    </span>
  <span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$smtp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                          
&nbsp;
  <span style="color: #666666; font-style: italic;">// Verificando se houve erro                                        </span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>PEAR<span style="color: #339933;">::</span><span style="color: #004000;">isError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mail</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>                                         
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Email enviado com sucesso!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;form method=&quot;POST&quot;&gt;
    Nome:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;meu_nome&quot;&gt;&lt;br/&gt;
    Email:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;meu_email&quot;&gt;&lt;br/&gt;
    Nome do seu amigo:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;nome_do_amigo&quot;&gt;&lt;br/&gt;
    Email do amigo:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;email_do_amigo&quot;&gt;&lt;br/&gt;
    &lt;br/&gt;
    &lt;input type=&quot;submit&quot;&gt;
  &lt;/form&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2008/12/16/indicacao-de-sites-utilizando-gmailgoogle-apps-na-hostnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Paradigmas errados sobre o Java</title>
		<link>http://www.noelrocha.com/blog/2008/11/20/paradigmas-errados-sobre-o-java/</link>
		<comments>http://www.noelrocha.com/blog/2008/11/20/paradigmas-errados-sobre-o-java/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 22:59:05 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

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

		<category><![CDATA[Programação]]></category>

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

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=179</guid>
		<description><![CDATA[O JavaScript é derivado do Java ou vice-versa?
De jeito nenhum. Java foi criado pela sun e tem diversas aplicações tanto cliente como server-side já o JavaScript é apenas uma aplicação que roda no cliente.
A linguagem Java é interpretada, sendo assim, é lenta para aplicações críticas?
Não. A linguagem Java pode ser interpretada ou compilada e seu [...]]]></description>
			<content:encoded><![CDATA[<p><strong>O JavaScript é derivado do Java ou vice-versa?</strong></p>
<p>De jeito nenhum. Java foi criado pela sun e tem diversas aplicações tanto cliente como server-side já o JavaScript é apenas uma aplicação que roda no cliente.</p>
<p><strong>A linguagem Java é interpretada, sendo assim, é lenta para aplicações críticas?</strong></p>
<p>Não. A linguagem Java pode ser interpretada ou compilada e seu desempenho muitas vezes equivalente ao do C++ porém é muito mais fácil programar em Java.</p>
<p><strong>É díficil programar em Java?</strong></p>
<p>Não, pelo contrário, é super fácil porém pode haver alguns equívocos quando não se tem conhecimento de orientação a objetos.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2008/11/20/paradigmas-errados-sobre-o-java/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

