Jump to content

Archived

This topic is now archived and is closed to further replies.

naeembhatti

getting error while connection fsocket to this site.

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]

Share this post


Link to post
Share on other sites
none of the IO socket functions follow redirects or location headers. You can create a handler to do it, but CURL is better for this sort of problem!

me!

Share this post


Link to post
Share on other sites
okey right, thank for the solution.
please can u tell me a little bit more about curl how can i use it or how can i access a socket of any site and is it installed on web server or i have to do?
where from download it?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
please have a look here
http://www.dealarmy.com/curl/
i wrote a code provided by u and it is returning me a same error?
i want to get all the images from this site like bookmarklet?

Share this post


Link to post
Share on other sites
sorry, my bad.

you can set CURLOPT_HEADER to false, and add CURLOPT_FOLLOWLOCATION, setting it to true.

PS > you can see all the options here: http://usphp.com/manual/en/function.curl-setopt.php

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
yes you are right this is exact my problem is actually
i need to fetch all the images from that link (bookmarklet feature as kaboodle.com) and a title from that link without posting any thing, possible?

Share this post


Link to post
Share on other sites

×

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.