tags:

views:

114

answers:

3

Hi

I am importing the contacts from gmail to my page .....

The process does not work due to this error

'curl_init' is not defined

The suggestion i got is to

  1. uncomment destination curl.dll
  2. copy the following libraries to the windows/system32 dir: ssleay32.dll and libeay32.dll
  3. copy php_curl.dll to windows/system32

After trying all these, I refreshed my xampp, but even then error occurs.

This is my page where I am trying to import the gmail contacts:

<?php
resource curl_init  ([  string $url = NULL  ] )

$ch = curl_init();


curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);


curl_exec($ch);


curl_close($ch);
?>

<?php
echo "hi";

if($_POST['submit'] != '') {
    echo "hi";

    $clientlogin_url = "https://www.google.com/accounts/ClientLogin";


    $clientlogin_post = array(
    "accountType" => "HOSTED_OR_GOOGLE",
    "Email" => $_POST['Email'],
    echo "Passwd" => $_POST['Passwd'],
    "service" => "cp",
    "source" => "tutsmore/1.2"
    );


    $curl = curl_init($clientlogin_url);


    curl_setopt($curl, CURLOPT_POST, true);


    curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);


    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);


    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);


    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);


    $response = curl_exec($curl);



    preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
    $auth = $matches[1];


    $headers = array("Authorization: GoogleLogin auth=" . $auth);


    $curl = curl_init('http://www.google.com/m8/feeds/contacts/default/full?max-results=10000');


    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);


    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);


    $feed = curl_exec($curl);


    echo "contacts".$contacts=array();


    $doc=new DOMDocument();



    if (!empty($feed)) $doc->loadHTML($feed);


    $xpath=new DOMXPath($doc);


    $query="//entry";
    $data=$xpath->query($query);

    foreach ($data as $node) {


        $entry_nodes=$node->childNodes;


        $tempArray=array();


        foreach($entry_nodes as $child) {


            $domNodesName=$child->nodeName;

            switch($domNodesName) {
                case 'title' : { 
                        $tempArray['fullName']=$child->nodeValue;
                    } break
                    ;
                case 'email' : {
                        if (strpos($child->getAttribute('rel'),'home')!==false)
                            $tempArray['email_1']=$child->getAttribute('address');
                        elseif(strpos($child->getAttribute('rel'),'work')!=false)
                            $tempArray['email_2']=$child->getAttribute('address');
                        elseif(strpos($child->getAttribute('rel'),'other')!==false)
                            $tempArray['email_3']=$child->getAttribute('address');
                    } break
                    ;
            }
        }
        if (!empty($tempArray['email_1']))$contacts[$tempArray['email_1']]=$tempArray;
        if(!empty($tempArray['email_2'])) $contacts[$tempArray['email_2']]=$tempArray;
        if(!empty($tempArray['email_3'])) $contacts[$tempArray['email_3']]=$tempArray;
    }
    foreach($contacts as $key=>$val) {

        echo $key."<br/>";
    }
}
else {

    ?>
<form action="<?=$PHP_SELF?>" method="POST">
    <table>
        <tr>
            <td>Email:</td><td><input type="text" name="Email" /></td>
        </tr>
        <tr>
            <td>Password:</td><td><input type="password" name="Passwd" /></td>
        </tr>
        <tr><td colspan="2" align="center">tutsmore don't save your email and password trust us.</td></tr>
        <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Get Contacts" /></td></tr>
    </table>
</form>
    <?php
}
?>

This code is completely provided for debugging; if any optimization is needed, I will try to optimize the code.

A: 

HAve you printed pgpinfo to check if curl is loaded?

Syed
no the curl is not initialized
udaya
@Syed: Where and how to take the page info is it like page info in tools or page info in webdeveloper tool bar
udaya
Sorry for the late replay, phpinfo is a php function. You use it like this<?phpphpinfo();?>
Syed
+1  A: 

Create a new php file - like temp.php - and just add:

phpinfo();

It should give you information of your entire PHP configuration. Scroll through the installed libraries and see if cURL is there. If not, hit the Manual - http://php.net/manual/en/book.curl.php - and get it setup. The instructions there are pretty good.

CaseySoftware
+2  A: 

resource curl_init ([ string $url = NULL ] )

Does this really appear in your source code? If so, comment it out, as it's just documentation of curl_init's return type and arguments.

Now, if curl is still giving you trouble at this point, you need to check in php.ini and make sure extension=php_curl.dll does not have a ; in front of it. (I can't tell if that's what you meant by your first comment or not.) Then use XAMPP to restart Apache.

R. Bemrose