Jump to content

php curl not working


hisoka

Recommended Posts

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

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

"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

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

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

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 by hisoka
Link to comment
Share on other sites

"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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...