-1

I'm hoping someone can help me out. I inherited some code that I have no idea how it works and now that it broke I have to fix it.

I am running PHP 5.5.38 on Windows server 2012 and IIS 8.5. I have finally discovered that the php code is using httprequest which doesn't exist anymore in my version of php and with windows. How would I convert the following to use curl code, if it is even possible?

$http = new HttpRequest('https://my.securelink.com/external/readi/ssoRequest', HttpRequest::METH_POST);

$http->addHeaders(
    array(
        'READI_AccessKey' => $accesskey, 
        'READI_Timestamp' => $timestamp,
        'READI_RequestSignature' => $mac
    )
);

$http->addPostFields(
    array(
        'READIUsername' => 'myusername',
        'LastName' => $_GET["lastn"],
        'FirstName' => $_GET["firstn"],
        'Email' => $_GET["em"],
        'ForceNewAssessment' => false,
        'InternalID' => $_GET["userid"],
        'IncludeSettings' => ''
    )
);
//Optional Post Field:  'READIUserID' => 'xxxxxx'


$response = $http->send()->getBody();

echo "<h3>===== Response ===== </h3>";
echo "<pre>";
echo $response;
echo "</pre>";

$arr = xml2array($response);

$rtn_status = getvaluebypath($arr,'sso/status');
$rtn_timestamp = getvaluebypath($arr,'sso/timestamp');

if($rtn_status == "success") {

    $redirectURL = getvaluebypath($arr,'sso/redirectUrl');

    echo "<h3>===== Access Link ===== </h3>";
    echo "<a href=\"" . $redirectURL . "\" target=\"_blank\">" . $redirectURL . "</a>";
    header( "Location: $redirectURL");
}
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • 2
    Possible duplicate of [HttpRequest not found in php](https://stackoverflow.com/questions/18579407/httprequest-not-found-in-php) – Jirka Hrazdil Mar 20 '18 at 22:19

1 Answers1

0

You can try adding the HttpRequest class as guyver4mk suggested (the link from Jiri Hrazdil's comment) if you don't want to change the whole code.

But since you asked how to convert the existing to cURL, try this:

$header = [
    'READI_AccessKey: '.$accesskey,
    'READI_Timestamp: '.$timestamp,
    'READI_RequestSignature: '.$mac
];


$post = [
    'READIUsername' => 'myusername',
    'LastName' => $_GET["lastn"],
    'FirstName' => $_GET["firstn"],
    'Email' => $_GET["em"],
    'ForceNewAssessment' => false,
    'InternalID' => $_GET["userid"],
    'IncludeSettings' => ''
];

$ch = curl_init();

$options = [
    CURLOPT_URL => 'https://my.securelink.com/external/readi/ssoRequest',
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $post,
    CURLOPT_RETURNTRANSFER => 1
];

curl_setopt_array($ch, $options);

$response = curl_exec($ch);

if (!$response)
    print_r(curl_error($ch));

curl_close($ch);
sykez
  • 2,015
  • 15
  • 14