Confidence Posted May 25, 2010 Share Posted May 25, 2010 Hi guys, my goal is to send a string from one page (htmlsend.php) to another (htmlreceive.php)....the data should be sent as $_POST['nc']....... if you wonder why, it a proof of concenpt, for more complex functionality as soon as this works. i made some code, but it is not working properly....would be cool if someone helps me point out the error cause. htmlsend.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $data='this is my data to send'; function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'nc' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url"); } return $response; } echo do_post_request("http://localhost/jquery/htmlreceive.php", $data); ?> htmlreceive.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); echo '<pre>'; print_r($_POST); echo '</pre>'; $receive=$_POST['nc']; echo 'incoming message '.$receive; and this is the error i get when calling htmlsend.php Array ( ) Notice: Undefined index: nc in D:\Apache2\htdocs\jquery\htmlreceive.php on line 7 incoming message Link to comment https://forums.phpfreaks.com/topic/202845-sending-a-string-as-_post-to-another-script/ Share on other sites More sharing options...
mga_ka_php Posted May 26, 2010 Share Posted May 26, 2010 why not use <form>? Link to comment https://forums.phpfreaks.com/topic/202845-sending-a-string-as-_post-to-another-script/#findComment-1063432 Share on other sites More sharing options...
kalivos Posted May 26, 2010 Share Posted May 26, 2010 You might have to send out the request headers 'header'=> "Accept-language: en\r\n". "Content-type: application/x-www-form-urlencoded\r\n", For another implementation, you can visit http://www.jonasjohn.de/snippets/php/post-request.htm -Kalivos Link to comment https://forums.phpfreaks.com/topic/202845-sending-a-string-as-_post-to-another-script/#findComment-1063455 Share on other sites More sharing options...
kenrbnsn Posted May 26, 2010 Share Posted May 26, 2010 You probably should look at curl. Ken Link to comment https://forums.phpfreaks.com/topic/202845-sending-a-string-as-_post-to-another-script/#findComment-1063480 Share on other sites More sharing options...
fja3omega Posted May 26, 2010 Share Posted May 26, 2010 try this website. http://www.plus2net.com/php_tutorial/variables.php Link to comment https://forums.phpfreaks.com/topic/202845-sending-a-string-as-_post-to-another-script/#findComment-1063549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.