Jump to content


Photo

getting error while connection fsocket to this site.


  • Please log in to reply
8 replies to this topic

#1 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 02 October 2006 - 10:06 AM

this is my example 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);
}
?>

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.

[edited by a moderator kenrbnsn, to surround the code with [code][/code] tags]

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 02 October 2006 - 12:31 PM

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!

#3 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 03 October 2006 - 04:14 AM

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?

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 03 October 2006 - 04:43 AM

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

<?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);
?>


#5 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 03 October 2006 - 04:54 AM

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?

#6 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 03 October 2006 - 05:00 AM

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/man...curl-setopt.php

#7 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 03 October 2006 - 05:17 AM

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.canadiant...romSearch=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.

#8 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 03 October 2006 - 01:49 PM

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.

#9 naeembhatti

naeembhatti
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 04 October 2006 - 04:51 AM

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?





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users