Page 1 of 1

CURL with Cookie problem

Posted: Wed Nov 23, 2005 4:35 pm
by jwalsh
Hi,

Trying to do a simple login, where the external site sets a session cookie. I think maybe I have the cookie file path wrong.

I'm on a shared host, linux, do I need to put the full path to the cookie file?

I get a login error page each time,

Thanks,

Josh

Code: Select all

$url = "http://www.example.com/checklogin.php";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url); 				// SET URL
		curl_setopt($ch, CURLOPT_REFERRER, "http://example.com/login.php");
		curl_setopt($ch, CURLOPT_FAILONERROR, 1);			// FAIL ON ERROR
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 		// ALLOW REDIRECTS
		curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/selltra/public_html/admin/cook");	// COOKIES
		curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/selltra/public_html/admin/cook");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);		// RETURN TO VARIABLE
		curl_setopt($ch, CURLOPT_TIMEOUT, 3);				// TIMES OUT AFTER 4 SEC
		curl_setopt($ch, CURLOPT_POST, 1);					// SET POST METHOD
		curl_setopt($ch, CURLOPT_POSTFIELDS, "username={$config['username']}&password={$config['password']}&Submit2=Submit"); 	// POST VALUES
		$result = curl_exec($ch);
		
		if (! $result) {
			echo "Server Connection Problem";
		} else {
			echo $result;
		}

Posted: Wed Nov 23, 2005 4:49 pm
by onion2k
I had a problem with cookies and curl a long time ago .. I *think* the problem was needing permission to create a file in the particular directory it was trying to save the cookie to. Make sure Apache/PHP has the correct permissions (chmod 755 usually does the trick).

Posted: Wed Nov 23, 2005 6:01 pm
by jwalsh
Tried that, no avail. Both the directory and file are already 755.

Any other suggestions? Are sessions treated different than cookies through cURL?

Josh