: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$headerfile = tempnam( $this->temp_dir, "sno" );
$cmdline_params = '-k -D ' . escapeshellarg( $headerfile );
foreach ( $headers as $header ) {
$cmdline_params .= ' -H ' . escapeshellarg( $header );
if ( ! empty( $body ) ) {
$cmdline_params .= ' -d ' . escapeshellarg( $body );
if ( $this->read_timeout > 0 ) {
$cmdline_params .= ' -m ' . escapeshellarg( $this->read_timeout );
exec( $this->curl_path . ' ' . $cmdline_params . ' ' . escapeshellarg( $URI ), $results, $return );
$this->error = "Error: cURL could not retrieve the document, error $return.";
$results = implode("\r\n",$results);
$result_headers = file("$headerfile");
$this->_redirectaddr = false;
for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
// if a header begins with Location: or URI:, set the redirect
if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
// get URL portion of the redirect
preg_match("/^(Location: |URI:)\s+(.*)/",chop($result_headers[$currentHeader]),$matches);
// look for :// in the Location header to see if hostname is included
if(!preg_match("|\:\/\/|",$matches[2]))
// no host in the path, so prepend
$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
// eliminate double slash
if(!preg_match("|^/|",$matches[2]))
$this->_redirectaddr .= "/".$matches[2];
$this->_redirectaddr .= $matches[2];
$this->_redirectaddr = $matches[2];
if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
$this->response_code = $result_headers[$currentHeader];
$this->headers[] = $result_headers[$currentHeader];
// check if there is a redirect meta tag
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
// have we hit our frame depth and is there frame src to fetch?
if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
$this->results[] = $results;
for($x=0; $x<count($match[1]); $x++)
$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
// have we already fetched framed content?
elseif(is_array($this->results))
$this->results[] = $results;
$this->results = $results;
/*======================================================================*\
Purpose: set cookies for a redirection
\*======================================================================*/
for($x=0; $x<count($this->headers); $x++)
if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match))
$this->cookies[$match[1]] = urldecode($match[2]);
/*======================================================================*\
Purpose: checks whether timeout has occurred
\*======================================================================*/
function _check_timeout($fp)
if ($this->read_timeout > 0) {
$fp_status = socket_get_status($fp);
if ($fp_status["timed_out"]) {
/*======================================================================*\
Purpose: make a socket connection
\*======================================================================*/
if(!empty($this->proxy_host) && !empty($this->proxy_port))
$host = $this->proxy_host;
$port = $this->proxy_port;
// socket connection succeeded
// socket connection failed
$this->error="socket creation failed (-3)";
$this->error="dns lookup failure (-4)";
$this->error="connection refused or timed out (-5)";
$this->error="connection failed (".$errno.")";
/*======================================================================*\
Purpose: disconnect a socket connection
\*======================================================================*/
function _disconnect($fp)
/*======================================================================*\
Function: _prepare_post_body
Purpose: Prepare post body according to encoding type
Input: $formvars - form variables
$formfiles - form upload files
\*======================================================================*/
function _prepare_post_body($formvars, $formfiles)
settype($formvars, "array");
settype($formfiles, "array");
if (count($formvars) == 0 && count($formfiles) == 0)
switch ($this->_submit_type) {
case "application/x-www-form-urlencoded":
foreach ( $formvars as $key => $val ) {
if (is_array($val) || is_object($val)) {
foreach ( $val as $cur_key => $cur_val ) {
$postdata .= urlencode($key)."[]=".urlencode($cur_val)."&";
$postdata .= urlencode($key)."=".urlencode($val)."&";
case "multipart/form-data":
$this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
foreach ( $formvars as $key => $val ) {
if (is_array($val) || is_object($val)) {
foreach ( $val as $cur_key => $cur_val ) {
$postdata .= "--".$this->_mime_boundary."\r\n";
$postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n";
$postdata .= "$cur_val\r\n";
$postdata .= "--".$this->_mime_boundary."\r\n";
$postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n";
foreach ( $formfiles as $field_name => $file_names ) {
settype($file_names, "array");
foreach ( $file_names as $file_name ) {
if (!is_readable($file_name)) continue;
$fp = fopen($file_name, "r");
$file_content = fread($fp, filesize($file_name));
$base_name = basename($file_name);
$postdata .= "--".$this->_mime_boundary."\r\n";
$postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n";
$postdata .= "$file_content\r\n";
$postdata .= "--".$this->_mime_boundary."--\r\n";