What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP help - Curl

PHP help - Curl
Author: Message:
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
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 :D

This post was edited on 06-17-2009 at 04:43 PM by Nathan.
Touch Innovation - touch friendly programs/applications for the windows mobile!


06-17-2009 04:42 PM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
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
Profile PM Web Find Quote Report
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
Joined: Apr 2005
O.P. RE: PHP help - Curl
Okay I tried that, and still no joy
Touch Innovation - touch friendly programs/applications for the windows mobile!


06-17-2009 06:38 PM
Profile E-Mail PM Web Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
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.
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
06-18-2009 02:45 AM
Profile PM Web Find Quote Report
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
Joined: Apr 2005
O.P. RE: PHP help - Curl
Can I have an example please?
Touch Innovation - touch friendly programs/applications for the windows mobile!


06-18-2009 09:43 AM
Profile E-Mail PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: PHP help - Curl
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
[Image: 1-0.png]
             
06-18-2009 12:01 PM
Profile PM Web Find Quote Report
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
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 :D

This post was edited on 06-18-2009 at 12:24 PM by Nathan.
Touch Innovation - touch friendly programs/applications for the windows mobile!


06-18-2009 12:19 PM
Profile E-Mail PM Web Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
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. :)
[Image: AndrewsStyle.png]
06-18-2009 09:59 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On