curl-and-php
RE: libcurl and cookies
Date: Fri, 25 Apr 2008 04:23:19 +0200
Hello georges
Does http://localhost/smf/index.php?action=login2
Work for your hoster? I can't believe that.
I believe that using
http://www.yourdomainname.com/smf/index.php?action=login2
Will give no problems.
On your local machine you can use localhost, will on your hosting machine
you can't normally.
willem
-----Oorspronkelijk bericht-----
Van: curl-and-php-bounces_at_cool.haxx.se
[mailto:curl-and-php-bounces_at_cool.haxx.se] Namens Georges EL OJAIMI
Verzonden: donderdag 24 april 2008 23:40
Aan: curl-and-php_at_cool.haxx.se
Onderwerp: libcurl and cookies
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
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-04-25