problem getting the response header after posting data using cURL

Here’s what I’m trying to do. Using cURL I posted information to a form to login to a website. When a user logs in (and there credentials are authenticated) they are redirected to a site through the Location header. My problem is after logging in through cURL I can’t access the response header.

I’ve tried

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://some.website.com/dirlogin.php'); //login URL $postData = 'userName=charlie&password=abc&etc....'; curl_setopt ($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); $store = curl_exec($ch); $info = curl_getinfo($ch); print_r($info);
The following is printed out
Array ( [url] => http://some.website.com/dirlogin.php [content_type] => text/html [http_code] => 200 [header_size] => 424 [request_size] => 257 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.004379 [namelookup_time] => 0.001107 [connect_time] => 0.001655 [pretransfer_time] => 0.001659 [size_upload] => 72 [size_download] => 1712 [speed_download] => 390956 [speed_upload] => 16442 [download_content_length] => 1712 [upload_content_length] => 0 [starttransfer_time] => 0.004213 [redirect_time] => 0 [certinfo] => Array ( ) )

Where’s the Location header? I know there is one because I used Fiddler to view it. I think what’s happening is curl_getinfo($ch) is getting the info of the request I just sent but how to I get the info of the servers response?

See the manual for (http://us3.php.net/manual/en/function.curl-setopt.php) curl_setopt(). Look at the options: [tt]CURLOPT_FOLLOWLOCATION[/tt], [tt]CURLOPT_HEADER[/tt], [tt]CURLINFO_HEADER_OUT[/tt], and [tt]CURLOPT_RETURNTRANSFER[/tt]

I think CURLINFO_HEADER_OUT will make the headers available to [tt]curl_getinfo()[/tt]. The FOLLOWLOCATION option will follow the Location redirect so you don’t have to manually do it. The HEADER and RETURNTRANSFER options (together) will return the content WITH the headers from the [tt]curl_exec()[/tt] call.

Actually authentication seems to be failing. It’s as if the last field isn’t getting posted. The forms action is “” and when the submit button is clicked the following javascript is executed

[code]function f_finish()
{
if (document.form.userName.value == “”)
{

alert('Enter your User Name.')
document.form.userName.focus();
return

}
if (document.form.password.value == “”)
{

alert('Enter your Password.')
document.form.password.focus();
return

}
if (document.form.chatName.value == “”)
{

alert('Enter a chat name for the instant messenger.')
document.form.chatName.focus();
return

}
var loginVal = “”
for (var i=0; i < document.form.whereToLogin.length; i++)
{
if (document.form.whereToLogin[i].checked)
{
loginVal = document.form.whereToLogin[i].value;
}
}
if (loginVal == “”)
{

alert('Select the Application to Login.')
document.form.pwd.focus();
return

}
else if (loginVal == “directorControlPanel”)
{
document.form.action = “loginDirControlPanel.php?PROCESS=YES&orderID=&selDirPanel=”;
}
else if (loginVal == “tourneyDirector”)
{
document.form.action = “dirlogincheck.php?BYPASS=”;
}

document.form.target = "_top";
document.form.submit();

}[/code]

The “Enter a chat name for the instant messenger.” is always displayed after I try logging in through curl.

I found the problems.
1)I was posting the data to the wrong page
2)get_header and curl_getinfo() and get_headers() were not behaving as I expected.

It sure is a lot harder when there’s two problems.
btw is there a way I can modify the first post so it appears as closed?

Sponsor our Newsletter | Privacy Policy | Terms of Service