<?php
$PostData = array(
'zipCode' => '12345',
'langId' => '-1',
'storeId' => '10001',
'URL' => '/Brother-TN-580-Toner-Cartridge-High-Yield/product_612784',
'errorUrl' => 'zipcode'
);
$ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)';
$url = 'http://www.staples.com/Brother-TN-580-Toner-Cartridge-High-Yield/product_612784';
$host = $_SERVER['DOCUMENT_ROOT'];
if ( $curl = curl_init() )
{
curl_setopt($curl, CURLOPT_URL, 'http://www4.staples.com/eluminate?ci=90028341&st=1255528609146&vn1=4.0.23B&ec=ISO-8859-1&pi=zipcode&tid=8&ti=1255528737238&hr=javascript%3AformSub%28addZipCodeForm%29%3B');
curl_setopt($curl, CURLOPT_COOKIE, 'CoreID6=30201255514912193294815;Path=/;Domain=www4.staples.com;expires=Mon, 13-Oct-24 13:08:16 GMT');
curl_setopt($curl, CURLOPT_COOKIE, 'TestSess3=x;Path=/;Domain=www4.staples.com;expires=End Of Session');
curl_setopt($curl, CURLOPT_COOKIE, '90028341_login=1255528626018461671490028341;Path=/;Domain=www4.staples.com;expires=End Of Session');
curl_setopt($curl, CURLOPT_COOKIE, '90028341_reset=1255528626;Path=/;Domain=www4.staples.com;expires=End Of Session');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_exec($curl);
curl_close($curl);
} else {
die('1 fails:' . curl_error($curl));
}
unset($curl);
//get cookie for sent
if ( $curl = curl_init($url) )
{
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_NOBODY, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $ua);
ob_start();
curl_exec($curl);
curl_close($curl);
$headers = explode("/n", ob_get_contents());
ob_end_clean();
/* TO DO: if $headers == '' error */
foreach ($headers as $key => $value)
{
if ( stripos($value, 'Set-Cookie:') !== FALSE )
{
list($field, $cookie[]) = explode(' ', $headers[$key]);
}
}
//echo '<pre>';
//print_r($headers);
//print_r($cookie);
/* TO DO: if $cookie == '' error */
} else {
die('2 fails:' . curl_error($curl));
}
unset($curl);
if( $curl = curl_init($url) )
{
curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($curl, CURLOPT_COOKIEFILE, $host . 'cookiefile');
// responce in variable not in flow
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl,CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl,CURLOPT_USERAGENT, $ua);
if( $html = curl_exec($curl) )
{
curl_setopt($curl, CURLOPT_URL, 'http://www.staples.com/office/supplies/StaplesZipCodeAdd?');
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $PostData);
for ($i=0; $i<sizeof($cookie); $i++)
{
curl_setopt($curl, CURLOPT_COOKIE, $cookie[$i]);
}
curl_setopt($curl, CURLOPT_COOKIE, $host . 'cookiefile');
}
curl_close($curl);
} else {
die('3 fails:' . curl_error($curl));
}
unset ($curl);
unset ($html);
if ( $curl = curl_init() )
{
curl_setopt($curl, CURLOPT_URL, 'http://www.staples.com/Brother-TN-580-Toner-Cartridge-High-Yield/product_612784?errorUrl=zipcode&storeId=10001&zipCode=12345&jspStoreDir=Staples&langId=-1&ddkey=StaplesZipCodeAdd');
for ($i=0; $i<sizeof($cookie); $i++)
{
curl_setopt($curl, CURLOPT_COOKIE, $cookie[$i]);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($curl);
curl_close($curl);
} else {
die('4 fails:' . curl_error($curl));
}
echo $html;