Basically, there is a secured site, which I can log into and then add data via a form once I'm logged in. I can pass the login information in the URL, and I can get it to work if, for example, I type the address into my browser bar, like so:

This will bring me to the page I want to post form data to. Which is great, except that if I use this url in my code, it doesn't work. It just brings me back to the initial login page. I should also say that if I use:


I will be brought to the form that I want to post data to. The problem is that I don't want to actually redirect to the page, I just want to get to the form that I need to post information to.

If I attempt to call this URL in my code, it doesn't work. There are multiple redirects that occur if I type it in the address bar, and I've used FOLLOWLOCATION, 1, but that doesn't seem to help.

The latest iteration of code attempts to request the page that sets the cookies, and then make subsequent requests that include the cookies, but it still winds up kicking me back to the first page.

$cookie_jar = tempnam('/tmp','cookie');

$c = curl_init('');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$page = curl_exec($c);

$c = curl_init('');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'field=value');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
$page = curl_exec($c);

Can anyone help?

the site is probibly using sessions to store login information. Did you try to post the variables using:

$vars = 'user=Username&pass=PW'
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);

It might help..

Thanks for the reply.

I think it actually had to do with the SSL certificate of the server I was posting to.

In any case, I was able to figure out the first part... I am now able to retrieve the form I want to post to, but now, I can't figure out how to actually *post* to that form....

Here's the code thus far:

$cookie_jar = tempnam('tmp/','cookie');

$url = "";
$POSTFIELDS = 'username=UNAME&password=PW&destination=
$reffer = "";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$cookie_file_path = "tmp/"; 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch);


Now, I can pass the username and password, and it will redirect me to the form (, but I can't figure out how to post to that form.

Any ideas?

Dear U Got Thsi Solution For The Curl Undefined Function Error

Bco Am Facing The Problem...
Curl Undefined

I Tried All The Step..

hi friends..

i am using cURL function for my project and its run great to pass username and password to re-directly on inner page of site by sending url like "".
but there is one problem when i pass Url having value to $_get as ""

please anyone suggest me to solve this probleme to send Url with value using cURL funtion.

thank u....