943,719 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 3970
  • PHP RSS
May 2nd, 2009
0

curl not working for getting a web page content, why?

Expand Post »
Hi all
i am using a curl script to go to a link and get its content for further manipulation. following is the link and curl script:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $url = 'http://criminaljustice.state.ny.us/cgi/internet/nsor/fortecgi?serviceName=WebNSOR&amp;templateName=detail.htm&amp;requestingHandler=WebNSORDetailHandler&amp;ID=368343543';
  3.  
  4. //curl script to get content of given url
  5. $ch = curl_init();
  6. // set the target url
  7. curl_setopt($ch, CURLOPT_URL,$url);
  8. // request as if Firefox
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );
  10. curl_setopt($ch, CURLOPT_NOBODY, false);
  11. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  13. $result= curl_exec ($ch);
  14. curl_close ($ch);
  15. echo $result;
  16. ?>

but the website is not excepting it through script it is giving user exception in result, but if we normally paste the url in browser it is opening the page perfectly alright.

Please help, what i am doing wrong here.

Thanks and regards
jyotiu
Last edited by jyotiu; May 2nd, 2009 at 1:29 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
jyotiu is offline Offline
33 posts
since Sep 2008
May 2nd, 2009
0

Re: curl not working for getting a web page content, why?

I got what the problem was in the url there is &amp; instead of & symbol that is creating a problem
Reputation Points: 10
Solved Threads: 0
Light Poster
jyotiu is offline Offline
33 posts
since Sep 2008
Jun 18th, 2010
0

curl not working for getting a web page content, why?

i also have same issue plz help me to send email me: [snipped]

Muhammad Sohail Qureshi
PHP Web Developer
Last edited by Ezzaral; Jun 18th, 2010 at 12:47 pm. Reason: Snipped email. Please keep it on site.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sohail_mubeen is offline Offline
3 posts
since Nov 2008
Jun 18th, 2010
0
Re: curl not working for getting a web page content, why?
to after execute url paste this code
print_r(curl_getinfo($ch));
use exit();function now check what show in array.
Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sohail_mubeen is offline Offline
3 posts
since Nov 2008
Jun 18th, 2010
0
Re: curl not working for getting a web page content, why?
After few hours of hard work i find a way to solve my problem. i install WAMP5 Version 1.4.3 change php.ini file the code from ;extension=php_curl.dll to extension=php_curl.dll this thing solve my problem.

code that i use:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. // create a new cURL resource
  3. $ch = curl_init();
  4.  
  5. // set URL and other appropriate options
  6. curl_setopt($ch, CURLOPT_URL, "http://news.google.com/news?hl=en&topic=t&output=rss");
  7. curl_setopt($ch, CURLOPT_HEADER, 0);
  8.  
  9. // grab URL and pass it to the browser
  10. curl_exec($ch);
  11.  
  12. // close cURL resource, and free up system resources
  13. curl_close($ch);
  14. ?>
Last edited by Ezzaral; Jun 18th, 2010 at 12:48 pm. Reason: Added code tags. Please use them to format any code that you post.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sohail_mubeen is offline Offline
3 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: #1062 - Duplicate entry Error
Next Thread in PHP Forum Timeline: Displaying content from another site





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC