curlOptions = $options; } private $curlOptions = array(); /** * Send the request and store the results. * * @return boolean TRUE on success, FALSE on failure. */ protected function _sendRequest () { phpCAS::traceBegin(); /********************************************************* * initialize the CURL session *********************************************************/ $ch = curl_init($this->url); if (version_compare(PHP_VERSION,'5.1.3','>=')) { //only avaible in php5 curl_setopt_array($ch, $this->curlOptions); } else { foreach ($this->curlOptions as $key => $value) { curl_setopt($ch, $key, $value); } } /********************************************************* * Set SSL configuration *********************************************************/ if ($this->caCertPath) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_CAINFO, $this->caCertPath); phpCAS::trace('CURL: Set CURLOPT_CAINFO'); } else { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); } /********************************************************* * Configure curl to capture our output. *********************************************************/ // return the CURL output into a variable curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get the HTTP header with a callback curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, '_curlReadHeaders')); /********************************************************* * Add cookie headers to our request. *********************************************************/ if (count($this->cookies)) { $cookieStrings = array(); foreach ($this->cookies as $name => $val) { $cookieStrings[] = $name.'='.$val; } curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookieStrings)); } /********************************************************* * Add any additional headers *********************************************************/ if (count($this->headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); } /********************************************************* * Flag and Body for POST requests *********************************************************/ if ($this->isPost) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postBody); } /********************************************************* * Perform the query *********************************************************/ $buf = curl_exec ($ch); if ( $buf === FALSE ) { phpCAS::trace('curl_exec() failed'); $this->storeErrorMessage('CURL error #'.curl_errno($ch).': '.curl_error($ch)); $res = FALSE; } else { $this->storeResponseBody($buf); phpCAS::trace("Response Body: \n".$buf."\n"); $res = TRUE; } // close the CURL session curl_close ($ch); phpCAS::traceEnd($res); return $res; } /** * Internal method for capturing the headers from a curl request. * * @param handle $ch * @param string $header * @return void */ public function _curlReadHeaders ($ch, $header) { $this->storeResponseHeader($header); return strlen($header); } }