Reputation: 1
im bizzare and im new in stackoverflow , i have some problem and that's :
im sending some page directly to a page and page answer to my request correctly , but i when to try send post data using cURL by php , the page do not react anywhere:
<form action="http://remotehost.com/index.aspx" method="post"> -> its work correctly and the index.php show me what i want but when :
<form action ="http://localhost/fetch_data.php" mthod="post"> ->
fetch_data.php:
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<?php
print_r($_POST);
$remotehost_cgi = 'http://remotehost.com/index.aspx';
$ret = post_data($_POST, $remotehost_cgi);
echo $ret;
?>
<?php
function post_data($datatopost,$urltopost){
$crl = curl_init ($urltopost);
curl_setopt ($crl, CURLOPT_POST, true);
curl_setopt ($crl, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($crl);
return $returndata;
}
?>
Upvotes: 0
Views: 961
Reputation: 360562
curl_exec()
returns boolean FALSE if the exec failed for any reasons. Instead of just returning your $returndata
, test it first:
...
$returndata = curl_exec($crl);
if ($returndata === FALSE) {
die('Curl failed: ' . curl_error($crl));
}
return($returndata);
Since you only echo out this value, you'd never see it, as boolean false will output as a null/empty string.
Upvotes: 0