Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Need help dealing with an http response in CURL


Demaestro - 11:19 pm on Jan 24, 2012 (gmt 0)


So I have this really weird thing going on and I think my limited knowledge of PHP is making it worse.

I am changing an integrated login function to use POST instead of GET.

So what would happen is it would send off a hit to the 3rd party site. I tell it where I want it I want it to return to and check it's response and it posts back with a result

$redirectURL = "https://login.membee.com/login.aspx?clientID=" . $cm_client_id . "&appID=" . $cm_app_id . "&username=" . $_POST["username"] . "&password=" . urlencode($_POST["passwd"]) ."&replyURL=" . $sReplyURL . "&destURL=" . $sDestURL . "&txn=" . $stxn . "&integrated=Y" . "&remember=" . $sRememberMe;

Then later I check for the post back and check the response

if (isset($_POST["authResp"]) && $_POST["authResp"] != "") {
//check response codes for success
}

But now I am using CURL to post and since CURL sets up a new request I have to render the response into a POST.

Here is the new code the replaces the redirectURL above
************************
$curl_connection = curl_init("https://login.membee.com/login.aspx");
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

$post_data['clientID'] = $cm_client_id;
$post_data['appID'] = $cm_app_id;
$post_data['username'] = $_POST["username"];
$post_data['password'] = $_POST["passwd"];
$post_data['replyURL'] = $sReplyURL;
$post_data['destURL'] = $sDestURL;
$post_data['txn'] = $stxn;
$post_data['integrated'] = 'Y';
$post_data['remember'] = $sRememberMe;



foreach ( $post_data as $key => $value)
{
$post_items[] = $key . '=' . $value;
}

$post_string = implode ('&', $post_items);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

$result = curl_exec($curl_connection);

curl_close($curl_connection);
************************


So far the only way I have found to get the check method which is this

************************
if (isset($_POST["authResp"]) && $_POST["authResp"] != "") {
//check response codes for success
}
************************

Is to add in a die($result);

Once I die and output $result to the screen, it does the POST and the above code rturns true and runs... the problems are:

1) Using die() results in a blank screen for 1-2 seconds... I did this as a workaround so there is text on screen:

die('logging in, please wait to be redirect....' . $result);

2) This is a serious hack and there has to be a better way. (I stumbled on it debugging while trying to output $result to the screen and it worked)

This also works
var_dump($result);
die();

var_dump returns:

STRING(800) "

"

Does anyone have any ideas on a better way to take the $result and render it another way?


Thread source:: http://www.webmasterworld.com/php/4410462.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com