<?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>Phaneronsoft &#187; rastrear</title>
	<atom:link href="http://www.phaneronsoft.com/phaneronsoft/tag/rastrear/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phaneronsoft.com/phaneronsoft</link>
	<description>Desenvolvimento Web</description>
	<lastBuildDate>Sat, 28 Aug 2010 00:11:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Sistema para rastrear entregas nos Correios.</title>
		<link>http://www.phaneronsoft.com/phaneronsoft/2009/10/14/sistema-para-rastrear-entregas-nos-correios/</link>
		<comments>http://www.phaneronsoft.com/phaneronsoft/2009/10/14/sistema-para-rastrear-entregas-nos-correios/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 20:13:49 +0000</pubDate>
		<dc:creator>Marcelo Korjenioski</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[correios]]></category>
		<category><![CDATA[entregas]]></category>
		<category><![CDATA[rastrear]]></category>

		<guid isPermaLink="false">http://www.phaneronsoft.com/phaneronsoft/?p=374</guid>
		<description><![CDATA[Olá pessoal depois de um tempo sem postar surgiu uma necessidade de rastrear minhas encomendas nos  Correios. Como não gosto de ficar apertando F5 no site dos Correios que vive com problemas resolvi fazer a consulta via Ajax. O codigo é simples e aproveitei a ideia do sistema para calcular frete. Segue exemplo funcionando. &#60;/p&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal depois de um tempo sem postar surgiu uma necessidade de rastrear minhas encomendas nos  Correios.</p>
<p>Como não gosto de ficar apertando F5 no site dos Correios que vive com problemas resolvi fazer a consulta via Ajax. O codigo é simples e aproveitei a ideia do <a href="http://www.phaneronsoft.com/phaneronsoft/2009/05/28/sistema-para-calcular-frete-sedex-e-pac-a-partir-de-cep-informado/" target="_blank">sistema para calcular frete</a>.</p>
<p>Segue <a href="http://www.phaneronsoft.com/exemplos/rastrear/rastrear.php">exemplo funcionando</a>.</p>
<pre class="brush: php">&lt;/p&gt;
&lt;?php
if($_POST) {
header(&quot;Content-Type: text/html; charset=ISO-8859-1&quot;);
$p_cod_lis = $_POST[&#039;P_COD_LIS&#039;];
if($p_cod_lis == &#039;&#039;) {
echo &#039;&lt;center&gt;Código não informado&lt;/center&gt;&#039;;
}
$url = &quot;http://websro.correios.com.br/sro_bin/txect01$.Inexistente?P_LINGUA=001&amp;P_TIPO=002&amp;P_COD_LIS=$p_cod_lis&quot;;

$conecurl = @fopen(&quot;$url&quot;,&quot;r&quot;) or die (&#039;&lt;center&gt;erro na conexão&lt;/center&gt;&#039;);
while(!feof($conecurl)) {
$lin .= fgets($conecurl,4096);
}
fclose($conecurl);

$lin = strtolower($lin);

$rest = substr($lin,0);
$nprimetable = strpos($rest,&#039;&lt;table &#039;);
$fechatable = strpos($rest,&#039;&lt;hr &#039;);
$quantopula = $fechatable - $nprimetable ;
$conteudo = substr($lin, $nprimetable ,$quantopula);

function get_anchor($html)
{
$er = &quot;/&lt;td.*?&gt;.*?&lt;\/td&gt;/&quot;;
preg_match_all($er,$html,$links);
$link = $links[0];
return $link;
}

function get_label($url)
{
$label = str_replace(&quot;&lt;/td&gt;&quot;,&quot;&quot;,preg_replace(&quot;/^&lt;td.*?&gt;/&quot;,&quot;&quot;,$url));
return $label;
}

echo $conteudo;

} else {
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot; /&gt;
&lt;link href=&quot;http://demo.phaneronsoft.com/img/favicon.ico&quot; rel=&quot;shortcut icon&quot; type=&quot;image/x-icon&quot; /&gt;
&lt;title&gt;Sistema para rastrear entregas no correio. | Phaneronsoft&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
* {
font-family:&quot;Trebuchet MS&quot;,&quot;Lucida Grande&quot;,Verdana,Tahoma,Helvetica,Arial,sans-serif;
font-size:12px;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal;
}

body {
background:#FFFFFF none repeat scroll 0 0;
height:100%;
margin:0;
margin-top:20px;
width:100%;
}

div#wrapper {
margin:auto;
position:relative;
width:390px;
z-index:0;
}

.select {
text-transform:uppercase;
width:99%;
border:1px solid #B6B6B6;
display:block;
}

.formSearch fieldset {
border:1px solid #CCCCCC;
margin:0;
padding:0 10px;
}

label {
display:block;
/*float:left;*/
margin-right:4px;
padding-bottom:5px !important;
}

legend {
color:#1E398D;
font-family:&quot;Legacy Sans ITC TT Bold&quot;,&quot;Trebuchet MS&quot;,&quot;Lucida Grande&quot;,Verdana,Tahoma,Helvetica,Arial,sans-serif;
font-size:1.5em;
padding:10px 5px;
}

.button {
background:#F5EED3;
border:1px solid #CCCCCC;
color:#666666;
cursor:pointer;
font-size:12px;
font-weight:bold;
letter-spacing:1px;
margin:10px 0 0;
overflow:visible;
text-transform:uppercase;
width:150px;
}

.formMain .inline {
margin:15px 0 0 !important;
}

.text,  .select,  .textarea, .password {
border:1px solid #B6B6B6;
display:block;
text-transform:uppercase;
}

fieldset span.nameField {
color:#666666;
text-transform:uppercase;
}

h3 {
border-bottom:1px solid #F58220;
margin:0;
padding:0;
}

h3 span {
-x-system-font:none;
color:#1E398D;
font-family:&quot;Legacy Sans ITC TT Bold&quot;,&quot;Trebuchet MS&quot;,&quot;Lucida Grande&quot;,Verdana,Tahoma,Helvetica,Arial,sans-serif;
font-size:1.5em;
font-style:normal;
font-variant:normal;
font-weight:bold;
line-height:normal;
}

#value {
-x-system-font:none;
font-family:&quot;Legacy Sans ITC TT Bold&quot;,&quot;Trebuchet MS&quot;,&quot;Lucida Grande&quot;,Verdana,Tahoma,Helvetica,Arial,sans-serif;
font-size:1.5em;
font-style:normal;
font-variant:normal;
font-weight:bold;
line-height:normal;
text-transform:capitalize;
}

#value table {
margin:0;
padding:0;
border:0;
}

#rastrear {
padding-top:30px;
}

#loading {
display:none;
color:#9B0000;
font-family:&quot;Legacy Sans ITC TT Bold&quot;,&quot;Trebuchet MS&quot;,&quot;Lucida Grande&quot;,Verdana,Tahoma,Helvetica,Arial,sans-serif;
font-size:1.5em;
font-style:normal;
font-variant:normal;
font-weight:bold;
line-height:normal;
text-transform:capitalize;
}

&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id=&quot;wrapper&quot;&gt;
&lt;h3&gt;
&lt;span&gt;Rastrear pedido&lt;/span&gt;
&lt;/h3&gt;

&lt;form method=&quot;post&quot; action=&quot;&quot; name=&quot;rastreamentohome&quot; onsubmit=&quot;submitForm(this); return false;&quot;&gt;
&lt;fieldset&gt;
&lt;legend&gt;Identificador do objeto:&lt;/legend&gt;
&lt;label for=&quot;P_COD_LIS&quot;&gt;
&lt;textarea cols=&quot;48&quot; id=&quot;P_COD_LIS&quot; rows=&quot;3&quot; name=&quot;P_COD_LIS&quot;&gt;&lt;/textarea&gt;
&lt;/label&gt;
&lt;label for=&quot;pesquisar&quot;&gt;
&lt;input type=&quot;submit&quot; id=&quot;pesquisar&quot; name=&quot;pesquisar&quot; value=&quot;pesquisar&quot; tabindex=&quot;3&quot; /&gt;
&lt;/label&gt;
&lt;/fieldset&gt;
&lt;/form&gt;

&lt;span id=&quot;value&quot;&gt;&lt;/span&gt;
&lt;span id=&#039;loading&#039;&gt;Pesquisando...&lt;/span&gt;
&lt;/div&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function submitForm(form) {
/*
usa metodo request() da classe Form da prototype, que serializa os campos
do formulario e submete (por POST como default) para a action especificada no form
*/
function mostrarLoading(){
$(&#039;loading&#039;).style.display = &#039;block&#039;;
$(&#039;value&#039;).innerHTML = &#039; &#039;;
}

form.request({
onLoading:mostrarLoading,
onComplete: function(transport){
/*
se o retorno for diferente de -1, entende-se que nao houve problemas, entao apaga-se
os campos do formulario usando o metodo reset() da classe Form
*/
if(transport.responseText !=-1)  {
$(&#039;loading&#039;).style.display = &#039;none&#039;;
$(&#039;value&#039;).innerHTML = transport.responseText;
} else {
form.reset();
$(&#039;loading&#039;).style.display = &#039;none&#039;;
$(&#039;value&#039;).innerHTML = &#039;Erro ao consultar&#039;;
}
}

});
return false;
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php } ?&gt;</pre>
<p>Caso tenha alguma duvida ou suges­tão deixe um comen­tá­rio que terei pra­zer em aju­dar.<br />
Comen­tá­rios são bem vin­dos assim posso melho­rar a qua­li­dade dos tuto­ri­ais aqui apresentados.</p>
<p>É isso pes­soal uma ótima semana e até o próximo post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phaneronsoft.com/phaneronsoft/2009/10/14/sistema-para-rastrear-entregas-nos-correios/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
