Jump to content

getting error while connection fsocket to this site.


naeembhatti

Recommended Posts

this is my example code.

[code]<?php
$fp = fsockopen("www.canadiantire.ca", 200, $errno, $errstr, 30);
if (!$fp) {
  echo "$errstr ($errno)<br />\n";
} else {
  $out = "GET / HTTP/1.1\r\n";
  $out .= "Host: http://www.canadiantire.ca/assortments/product_detail.jsp?FOLDER%3C%3Efolder_id=1408474396669883&ASSORTMENT%3C%3East_id=1408474396670271&bmUID=1159779949708&PRODUCT%3C%3Eprd_id=845524441896143&assortment=primary&fromSearch=true
\r\n";
  $out .= "Connection: Close\r\n\r\n";

  fwrite($fp, $out);
  while (!feof($fp)) {
      echo fgets($fp, 128);
  }
  fclose($fp);
}
?>[/code]

this function works for all sites but when ever i use this function for canadiantire.ca it generates this error
"
HTTP/1.0 302 Found Server: CacheFlow-Proxy/1.0 Location:http://www.http.com/ Connection: close Content-Length: 90
Redirect
"

i don't know what could be its solution please help me out.

[nobbc][edited by a moderator kenrbnsn, to surround the code with [code][/code] tags][/nobbc]
Link to comment
Share on other sites

from the PHP manual (with some slight modifications). Should work for you.
http://usphp.com/curl_exec

[code=php:0]
<?php
// create a new CURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.canadiantire.ca/assortments/product_detail.jsp?FOLDER%3C%3Efolder_id=1408474396669883&ASSORTMENT%3C%3East_id=1408474396670271&bmUID=1159779949708&PRODUCT%3C%3Eprd_id=845524441896143&assortment=primary&fromSearch=true");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL and pass it to the browser
echo curl_exec($ch);

// close CURL resource, and free up system resources
curl_close($ch);
?>[/code]
Link to comment
Share on other sites

actually i did not want that this site redirect to other page
i need to get the contents of current page having same variables
i use this as u recommend me.
<?php
// create a new CURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.canadiantire.ca/assortments/product_detail.jsp?FOLDER%3C%3Efolder_id=1408474396669883&ASSORTMENT%3C%3East_id=1408474396670271&bmUID=1159850265943&PRODUCT%3C%3Eprd_id=845524441896143&assortment=primary&fromSearch=true");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// grab URL and pass it to the browser
echo curl_exec($ch);

// close CURL resource, and free up system resources
curl_close($ch);
?>

thank u for help.
Link to comment
Share on other sites

Then you had it right the first time... the problem is that page is generating a "302 Moved Temporarily" error, and is redirecting you to a page asking for a zip code.

So, the script is working perfectly. The problem is that perhaps you aren't passing the server the right information. You might also have to post data to the server. If that's the case, you'll need to set CURLOPT_POST to true, and then set CURLOPT_POSTFIELDS to the fields you want to post.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.