Jump to content

help with stream_context_create($params)


otuatail

Recommended Posts

Hi I don't understand this stuff and am trying to debug it to see.

This function seems to return Resource id #1. I have added an echo at line 33.

Not a big file but would like to understand what is happening behind.

 

http://www.des-otoole.co.uk/streetangels/eapi.php

 

<?php
//==================================== Simple PHP code sample ==========================================//

/*
* We recommend that you use port 5567 instead of port 80, but your
* firewall will probably block access to this port (see FAQ for more
* details):
* $url = 'http://www.bulksms.co.uk:5567/eapi/submission/send_sms/2/2.0';
* 
* Please note that this is only for illustrative purposes, we strongly recommend that you use our comprehensive example
*/
$url = 'http://www.bulksms.co.uk/eapi/submission/send_sms/2/2.0';
$data = 'username=your_username&password=your_password&message='.urlencode('Testing SMS').'&msisdn=44123123123';

$response = do_post_request($url, $data);

print $response;

function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => 
array
(
	'method'  => 'POST',
	'content' => $data,
));

if ($optional_headers !== null) 
{
	$params['http']['header'] = $optional_headers;
}

$ctx = stream_context_create($params);
echo "$ctx, $url, $data";
exit;
$fp = fopen($url, 'rb', false, $ctx);

if (!$fp) {
	print "Problem with $url, Cannot connect\n";
}
$response = @stream_get_contents($fp);
if ($response === false) {
	print "Problem reading data from $url, No status returned\n";
}

return $response;
}
?>
<html>
<body>
<? echo $ctx ?>
</body>
</html>

 

Ta

 

Desmond.

 

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.