Hi,
I am new here, I am trying to achieve posting using php by writing http headers then send it to another server. I am posting in send.php and get the result by receive.php. I did get an email by this code, but it seems it cannot get the value of $sk. I get the email of content: "sk is " which is incorrect. Anyone can show me any errors inside??? i got my head cracking for several weeks now... THANK IN ADVANCE
p.s: do i need to use urldecode()??
==============================send.php============================================
<?php
echo "here....";
$sk = '5464564654';
$sk= urlencode(stripslashes($sk));
$req = "sk=".$hid;
$header .= "POST /receive.php HTTP/1.0\r\n";
$header .= "Host: http://www.host.info:80\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.host.info', 80, $errno, $errstr, 30);
if (!$fp) {
echo "error occured!!";
exit;
}
else {
fputs ($fp, $header . $req);
echo $header . $req ;
}
fclose ($fp);
?>
==============================send.php============================================
==============================receive.php===========================================
<?php
$sk = $_POST['sk'];
$mail_From = "tech@host.info";
$mail_to = "admin@gmail.com";
$mail_Subject = "confirmation";
$mail_Body = "sk is $sk" ;
mail($mail_to, $mail_Subject, $mail_Body, $mail_From);
?>
==============================receive.php===========================================
problem posting by PHP
Moderator: General Moderators
Re: problem posting by PHP
Even though your receive.php is not getting the POST values it send the mail.
And with the use of "http_build_query" [ PHP 5 ] instead of "urldecode" you can specify the parameters in a array ( much easy ).
So can you change your send.php to following and try
And with the use of "http_build_query" [ PHP 5 ] instead of "urldecode" you can specify the parameters in a array ( much easy ).
So can you change your send.php to following and try
Code: Select all
$data = array ('sk' => '5464564654');
$data = http_build_query($data);
$opts = array(
'http'=>array(
'method' => "POST",
'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: " . strlen( $data ),
'content' => $data
)
);
$context = stream_context_create( $opts );
$fp = fopen( 'http://www.host.info/receive.php', 'r', false, $context );
fpassthru( $fp );
fclose( $fp );