cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-and-php mailing list Archives

libcurl and cookies

From: Georges EL OJAIMI <G-OJAIMI_at_cyberia.net.lb>
Date: Thu, 24 Apr 2008 23:39:53 +0200

I am writing a function to automatically connect to simple machine
forum, however on my locahost I have PHP Version 4.3.3 and libcurl/7.10.5
However on my hosting provider server, I have PHP Version 5.2.5 and
libcurl/7.18.0

The following code works very well on my locahost but on the hosting
provider the cookie is not being transfered.
Is there any problem with version 7.18.0 of libcurl and how can I
overcome this problem?

Best regards,
Georges

    function checkLogin($pu, $pp)
    {
        $post_data = array();
       
        $post_data['user'] = $pu;
        $post_data['passwrd'] = $pp;
        $post_data['cookielength'] = 60;
        $post_data['hash_passwrd'] = "";

        $cookie_new = tempnam("/tmp","NHO");
       
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,
"http://localhost/smf/index.php?action=login2");
        curl_setopt($ch, CURLOPT_POST, 1 );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_new);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_new);
        curl_setopt($ch, CURLOPT_HEADER,1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
               
        $postResult = curl_exec($ch);
       
        if (curl_errno($ch))
        {
            return false;
        }
       
        curl_close($ch);
       
        $cookie_status = array();
        $cookie_contents = file_get_contents($cookie_new);
       
        if(file_exists($cookie_new))
        {
            unlink($cookie_new);
        }
       
        $cookie_contents_array = explode("\n",$cookie_contents);
       
// print_r ($cookie_contents_array);
       
        for($i = 0; $i < count($cookie_contents_array); $i++)
        {
            if(strpos($cookie_contents_array[$i],"localhost")!==false)
            {
                $cookie_array = explode("\t",$cookie_contents_array[$i]);
               
                if($cookie_array[4]!=0)
                {
                    
header("Set-Cookie:".$cookie_array[5]."=".$cookie_array[6].";
expires=".date("r",$cookie_array[4])."; path=/",false);
                }
                else
                {
                    
header("Set-Cookie:".$cookie_array[5]."=".$cookie_array[6].";
path=/",false);
                }
            }
        }
       
        header("Set-Cookie: PHPSESSID=".session_id()."; path=/",false);

        return true;
    }

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-04-24

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET