Jump to content

sending a string as $_POST to another script


Confidence

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.