hisoka Posted June 8, 2015 Share Posted June 8, 2015 I have apache 2.2 installed in my computer os = windows xp 32 php version is 5.9.9 I tried to use php curl like this : <?php$ch=curl_init();$url1 = "http://www.facebook.com";curl_setopt($ch , CURLOPT_URL , $url1);$response = curl_exec($ch);print $response;curl_close($ch);?> However when I run the above script , I got this error : Fatal error: Call to undefined function curl_init() in C:Apache Software FoundationApache2.2htdocs10.php on line 3 So I follwed this article http://artofsimplicity.co.uk/php-5-2-14-curl-not-working-on-windows/ but my problem was not solved and I still got the same error . I did all the five steps in the article : 1) extension=php_curl.dll is uncommented 2) the php installation directory is in my path environment 3) ssleay32.dll and lbeay32.dll are in the php directory and in my path 4) checked phpinfo(); and I can’t see an entry for cURL listed there. 5) I restarted apache again and the problem persisted plus the sixth from the article : 6)I replaced the broken DLL with one from a previous version of PHP after all that I failed and the error remained Fatal error: Call to undefined function curl_init() in C:Apache Software FoundationApache2.2htdocs10.php on line 3 Link to comment Share on other sites More sharing options...
justsomeguy Posted June 8, 2015 Share Posted June 8, 2015 Make sure the settings in the ini file to use an error log, to report all errors, and to report startup errors are enabled, then check the error log to see what the problem is. Link to comment Share on other sites More sharing options...
hisoka Posted June 9, 2015 Author Share Posted June 9, 2015 I did as you told me : error_reporting = E_ALL (uncommented)display_errors = On (uncommented)log_errors = On (uncommented)display_startup_errors = On (uncommented) saved change and restarted apache . Then I checked the error file in logs directory which is in apache2.2 directory C:Apache Software FoundationApache2.2logs and all what I could get is this error : [Tue Jun 09 18:22:23 2015] [error] [client 127.0.0.1] File does not exist: C:/Apache Software Foundation/Apache2.2/htdocs/favicon.ico and of course the Fatal error: Call to undefined function curl_init() in C:Apache Software FoundationApache2.2htdocs10.php on line 3 error I am really confused and I need help Link to comment Share on other sites More sharing options...
dsonesuk Posted June 9, 2015 Share Posted June 9, 2015 IF using WAMP click wamp server icon -> PHP -> PHP extensions -> second from top select php_curl, this corrected it for me. Link to comment Share on other sites More sharing options...
dsonesuk Posted June 9, 2015 Share Posted June 9, 2015 Make sure you are editing the correct php.ini file, there can be more than one, in phpinfo() look at 'Loaded Configuration File' that will tell the php.ini file it is loading. Link to comment Share on other sites More sharing options...
hisoka Posted June 9, 2015 Author Share Posted June 9, 2015 "Make sure you are editing the correct php.ini file, there can be more than one, in phpinfo() look at 'Loaded Configuration File' that will tell the php.ini file it is loading." when I run phpinfo(); I got the follwing concerning php.ini: Configuration File (php.ini) Path = C:WINDOWS // the direct path to my php.ini is C:php and Loaded Configuration File= (none) Besides I got another error when I tried to run the above cur script again : php startup : unable to load dynamic library php_curl.dll . The specified module could not be found . the php_curl.dll is in my php/ext directory but php does not detect it Link to comment Share on other sites More sharing options...
hisoka Posted June 9, 2015 Author Share Posted June 9, 2015 Thanks to both of you now after some trying I solved the problem : now I see my load configuration file and curl enabled in my php info . Now after running this php script : <?php$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://www.youtube.com");curl_setopt($ch, CURLOPT_HEADER, 0);$response = curl_exec($ch);print $response ;curl_close($ch);?> I got only 1 displayed I wonder why and how to make the youtube page displayed? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 9, 2015 Share Posted June 9, 2015 Check the section on return values:http://php.net/manual/en/function.curl-exec.php Link to comment Share on other sites More sharing options...
hisoka Posted June 9, 2015 Author Share Posted June 9, 2015 Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure. 1 is true or success and 0 is false or failure therefore the script run correctly and succeed and the value of success is returned but I need the webpage to be displayed not the result of success or failure . Whatever I do I cannot let curl display the content of the webpage in my browser <?php $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://www.youtube.com"); $data = curl_exec($c); echo $data ; curl_close($c); ?> <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.youtube.com"); $contents = curl_exec ($ch);echo $contents;?> I am really stuck . Why I cannot get to let curl php in the above scripts to show youtube page content ? Link to comment Share on other sites More sharing options...
hisoka Posted June 9, 2015 Author Share Posted June 9, 2015 (edited) problem solved : php curl is not able to display the content of the sites using SSH that is https . It can only display sites that do not use SSH that is http : this is displayed: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://stackoverflow.com") $contents = curl_exec ($ch);echo $contents;?> meanwhile this cannot be displayed : <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.youtube.com") $contents = curl_exec ($ch);echo $contents;?> Justsomeguy how can use curl php with SSH to let it display the https sites ??? Edited June 9, 2015 by hisoka Link to comment Share on other sites More sharing options...
justsomeguy Posted June 9, 2015 Share Posted June 9, 2015 Did you ignore this part: However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.If you want it to return the page then set that option. Link to comment Share on other sites More sharing options...
hisoka Posted June 9, 2015 Author Share Posted June 9, 2015 "If you want it to return the page then set that option." I still do not understand what do you mean exactly : I set it like this : <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.youtube.com");curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$contents = curl_exec ($ch);echo $contents;?> but when I run the script , it gives nothing only a white page Link to comment Share on other sites More sharing options...
justsomeguy Posted June 9, 2015 Share Posted June 9, 2015 That should be true, not 1. This page lists the options broken up into section based on whether they take a boolean, integer, etc.http://php.net/manual/en/function.curl-setopt.php Link to comment Share on other sites More sharing options...
justsomeguy Posted June 9, 2015 Share Posted June 9, 2015 There's some more information here about using cURL with SSL:http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/ Link to comment Share on other sites More sharing options...
hisoka Posted June 10, 2015 Author Share Posted June 10, 2015 (edited) yes yes now it worked . all what I needed is to add this line : curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); Edited June 10, 2015 by hisoka Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now