0

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;
}
?>

2 Answers 2

1

mthod="post" to method="post" ?

Sign up to request clarification or add additional context in comments.

3 Comments

hey man r u kidding ? if you can answer my Q please do that , and if you can't please get out of my question page :D okay ?
I don't get it, POST variable was empty because you made a mistake with method. Have you tried it again? And... no one can answer you question because there isn't any :)
it just a mistake of spelling ok ? in my original source there is no spelling error ! thanks.
0

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.

2 Comments

hey marc thanks for your note ! but there siomething wrong here !!!! the $returndata returned as true ! but the form and the index.aspx do not act to my requrest !!!! :-?
Try a few curl_getinfo() calls on the $crl handle after you do the exec(), details on the options here: php.net/curl_getinfo. See what state the handle is in after it finishes off. Maybe something hinky with the script or the server.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.