Im trying to login a site with a class and get the cookies to be used later
I use curlopt_cookiejar and set it to $this->cookie, but $this->cookie is always false even when the http headers show the cookie is set when the script does the requests
My CODE:
$this->cookie is blank but when I run the script it returns:
how can i store the cookies from a request and easily use them later in a way that works?
I use curlopt_cookiejar and set it to $this->cookie, but $this->cookie is always false even when the http headers show the cookie is set when the script does the requests
My CODE:
PHP:
<?php
class XFS {
var $filesystem;
var $cookie;
var $login;
var $site;
function login($user, $pass, $url){
if (!$user || !$pass || !$url){
return false;
}
else{
$headers=array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-us,en;q=0.5',
'Accept-Encoding: gzip,deflate',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive: 115',
'Connection: keep-alive');
$post = array(
'op' => 'login',
'login' => $user,
'password' => $pass
);
$curl = curl_init($url);
curl_setopt_array($curl, ARRAY(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEJAR => $this->cookie,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12',
//CURLOPT_FOLLOWLOCATION => true
CURLOPT_HEADER => true
));
$check = curl_exec($curl);
echo $this->cookie;
echo $check;
}
}
}
$test = new XFS;
$test->login('username', 'password', 'www.cloudvidz.net');
?>
you can see cookies are set but nothing is echoed for $this->cookieHTTP/1.1 100 Continue HTTP/1.1 302 Moved Date: Sun, 06 Oct 2013 10:28:28 GMT Server: Apache/2.2.23 (CentOS) Set-Cookie: lang=english; domain=.cloudvidz.net; path=/ Set-Cookie: login=xxxxxxx; domain=.cloudvidz.net; path=/; expires=Fri, 04-Apr-2014 10:28:28 GMT Set-Cookie: xfss=cookiecookiecookie; domain=.cloudvidz.net; path=/; expires=Tue, 05-Nov-2013 10:28:28 GMT Location: CloudVidz.Net - Easy way to share your files Content-Length: 0 Connection: close Content-Type: text/plain; charset=utf-8
how can i store the cookies from a request and easily use them later in a way that works?