Hey,
Haven't been here for a while but I'm confused on something related to PHP. I've been out of the internet world for about 6-8 months really which means im mentally fucked when it comes to PHP.
code:
<?
function fetch($url,$post=false,$cookie=true,$timeout=1) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
}
if ($post) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, TRUE);
}
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
//curl_setopt($ch, CURLOPT_HEADER, TRUE); //debug
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$cookie=tempnam('','');
$url='http://www.website.com/fsock.php';
$post='username=Nathan1&password=test';
fetch($url,$post,$cookie);
$url='http://www.website.com/vote.php?account=nathan1&site=2';
echo fetch($url,$post,$cookie);
#$url='http://www.website.com/vote/vote.php';
#echo fetch($url,false,$cookie);
?>
Basically it logs in okay, but then when it comes to clicking the link it doesn't work, it redirects to the home page (which after some investigation = not logged in) which makes me think the cookie isn't being stored.
Anyone got any ideas on how to make the cookie last longer or be stored so it'll work?
Thanks