naeembhatti Posted October 2, 2006 Share Posted October 2, 2006 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: 90Redirect"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] Quote Link to comment Share on other sites More sharing options...
printf Posted October 2, 2006 Share Posted October 2, 2006 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! Quote Link to comment Share on other sites More sharing options...
naeembhatti Posted October 3, 2006 Author Share Posted October 3, 2006 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? Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 3, 2006 Share Posted October 3, 2006 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 optionscurl_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 browserecho curl_exec($ch);// close CURL resource, and free up system resourcescurl_close($ch);?>[/code] Quote Link to comment Share on other sites More sharing options...
naeembhatti Posted October 3, 2006 Author Share Posted October 3, 2006 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? Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 3, 2006 Share Posted October 3, 2006 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 Quote Link to comment Share on other sites More sharing options...
naeembhatti Posted October 3, 2006 Author Share Posted October 3, 2006 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 optionscurl_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 browserecho curl_exec($ch);// close CURL resource, and free up system resourcescurl_close($ch);?>thank u for help. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 3, 2006 Share Posted October 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
naeembhatti Posted October 4, 2006 Author Share Posted October 4, 2006 yes you are right this is exact my problem is actuallyi 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.