PHP help - Curl |
Author: |
Message: |
Nathan
Veteran Member
Yeah, "large dimensions" ;)
Posts: 2984 Reputation: 76
– / /
Joined: Apr 2005
|
O.P. PHP help - Curl
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
This post was edited on 06-17-2009 at 04:43 PM by Nathan.
|
|
06-17-2009 04:42 PM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
RE: PHP help - Curl
quote: Originally posted by Nathan
... which makes me think the cookie isn't being stored.
Have you looked at the request headers to make sure you're sending the cookie?
PHP code:
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
|
06-17-2009 06:30 PM |
|
|
Nathan
Veteran Member
Yeah, "large dimensions" ;)
Posts: 2984 Reputation: 76
– / /
Joined: Apr 2005
|
O.P. RE: PHP help - Curl
Okay I tried that, and still no joy
|
|
06-17-2009 06:38 PM |
|
|
MeEtc
Patchou's look-alike
In the Shadow Gallery once again
Posts: 2200 Reputation: 60
38 / /
Joined: Nov 2004
Status: Away
|
RE: PHP help - Curl
set the value of $cookie to a valid filename as a string.
This post was edited on 06-18-2009 at 02:46 AM by MeEtc.
I cannot hear you. There is a banana in my ear.
|
|
06-18-2009 02:45 AM |
|
|
Nathan
Veteran Member
Yeah, "large dimensions" ;)
Posts: 2984 Reputation: 76
– / /
Joined: Apr 2005
|
O.P. RE: PHP help - Curl
Can I have an example please?
|
|
06-18-2009 09:43 AM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
|
06-18-2009 12:01 PM |
|
|
Nathan
Veteran Member
Yeah, "large dimensions" ;)
Posts: 2984 Reputation: 76
– / /
Joined: Apr 2005
|
O.P. RE: PHP help - Curl
No worries guys, I got it working
My code was perfectly fine, it was I was missing a variable that the site needed to allow the vote
This post was edited on 06-18-2009 at 12:24 PM by Nathan.
|
|
06-18-2009 12:19 PM |
|
|
andrewdodd13
Senior Member
Oh so retro
Posts: 870 Reputation: 16
34 / /
Joined: Jan 2005
|
RE: PHP help - Curl
quote: Originally posted by Ezra
Like I already said, don't you have to fopen that file?
I don't think you can just put the filename in curl_setopt...
See: http://nl2.php.net/manual/en/curl.examples-basic.php
Yeah, you can do this. I found it out earlier.
|
|
06-18-2009 09:59 PM |
|
|
|