So ich bin jetzt ganz am ende mit meinem Latein, leider komme ich nicht mehr weiter, der Script wie er unten steht funktioniert vollständig, das heisst er antwortet mir auf meine SMS nur komme ich vorne und hinten nicht nach wie ich das ganze umschreiben kann damit er mir anstelle des oberen standarttextes meinen Text sendet dehn ich will. Meine Fachliteratur gibt mir keinen Rat und sonst finde ich leider auch nichts, habe es mit variablen versucht jedoch verliert er beim befehl data = implodet alle variablen die ich ihm oben gefüttert habe.
Vieleicht weiss wer von euch mir einen Rat.
<?php
// Copyright (c) 2005 MNC S.A.
// This simple test program is an HTTP POST receiver that receives a
// notification, replies, then send an XML API command as well.
// Ask PHP to keep track of last error in $php_errormsg.
ini_set("track_errors", 1);
// Helper function for fatal errors
function fatal($msg) {
error_log("Error: $msg");
exit;
}
// Get received document. Most portable way seems to use
// the php://input stream, as $_POST does key=value parsing
// and $HTTP_RAW_POST_DATA can be configured out.
$data = implode('', file('php://input'));
if (!$data) {
fatal("Received no data!");
}
// output the header to indicate the receiver we're sending xml in
// UTF-8 IMPORTANT NOTE: this merely is an indication for the
// receiver, this will in no way magically send UTF-8! The actual data
// send later must be encoded in UTF-8. Several solutions:
//
// - read a file on disk which is already encoded in UTF-8, and send
// it as-is
//
// - read a file on disk with another encoding you know, and transcode
// it to UTF-8; you can use iconv, see http://www.php.net/iconv
//
// - read a file from a database, and make sure that either the database
// will send us data in UTF-8, or transcode its output from the encoding
// it's using, to UTF-8, using for example iconv
header("Content-type: text/xml; charset=UTF-8");
// send the first part of the XML document
echo '<?xml version="1.0" encoding="UTF-8" ?>
<NotificationReply>
<message>
<text>response from the notification</text>
<cost>20</cost>
</message>
</NotificationReply>';
// This function will send specified data as an HTTP POST request
// to the specified URL. It assumes the data is an UTF-8 encoded
// XML document.
//
// Note: we implement here a simple HTTP POST request at the
// socket level, because there is no default library available in
// PHP to do that, and we don't want to force you to compile PHP
// with the CURL extension if it's not already. Code would be
// shorter and simpler using the CURL extension, you might prefer
// using it if it is available at your site.
//
// Returns what parse_answer itself returns, which is an array
// containing: response code, headers, body, raw headers.
function send($url, $data) {
// We'll send data by hand, therefore we need to know to
// which host, which port and which location data is to be
// sent, by parsing the specified URL.
if (ereg("^http://([^:/]+)(:([0-9]+))?(/.*)", $url, $regs)) {
$host = $regs[1];
$port = $regs[3];
// If no port was specified, we fallback on default HTTP
// port value.
if ($port == '')
$port = 80;
$path = $regs[4];
} else {
fatal("send: unable to parse URL: $url");
}
// Open the connection using Internet socket connection
$fp = @fsockopen($host, $port, $errno, $errstr);
if (!$fp) {
fatal("send: unable to open connection to $url");
}
// First, send necessary HTTP headers
fwrite($fp, "POST $path HTTP/1.0\r\n");
fwrite($fp, "Host: $host:$port\r\n");
fwrite($fp, "Content-Type: text/xml; charset=UTF-8\r\n");
fwrite($fp, "Content-Length: " . strlen_b($data) . "\r\n");
fwrite($fp, "\r\n");
// Second, send data
fwrite($fp, $data);
// Now, read response from the server
while (!feof($fp)) {
$buf .= fread($fp, 8192);
// Parse the HTTP answer and try to extract response code,
// headers and body
$answer = parse_answer($buf);
// We need to discover Content-Length, to know when server
// finishes sending data
if (!$length) {
if ($answer[0] == 200)
$length = $answer[1]['content-length'];
}
// When length is available, we can check if response has
// been fully transmitted; this is the case when all what
// we received equals the headers plus the full contents.
if ($length) {
if (strlen_b($buf) == strlen_b($answer[3]) + $length)
break;
}
}
fclose($fp);
return $answer;
}
// PHP's strlen should return the length of a string in bytes,
// except when using multibyte strings, in which case
// mb_orig_strlen must be used (in case strlen was overloaded
// with mb_strlen).
function strlen_b($str) {
if (function_exists('mb_orig_strlen')) {
return mb_orig_strlen($str);
} else {
return strlen($str);
}
}
// Parse an HTTP answer to extract response code, headers and body
// Returns an array containing: response code, headers, body, raw headers
function parse_answer($answer) {
// This first pattern matching allows to separate first line
// (server response status), headers, and data contents
if (ereg("^(([^\n]+)\r\n(.*)\r\n\r\n)(.*)", $answer, $regs)) {
$full_headers = $regs[1];
$response = $regs[2];
$headers_string = $regs[3];
$body = $regs[4];
// Parse first line (server response status)
if (ereg("^HTTP/[0-9\.]+ ([0-9]+)", $response, $regs)) {
$response_code = $regs[1];
} else {
fatal("parse_answer: unable to parse response line: $response");
}
// Parse headers and build a hash with them
foreach (split("\r\n", $headers_string) as $line) {
if (ereg("^([^:]+): (.*)", $line, $regs)) {
$headers[strtolower($regs[1])] = $regs[2];
} else {
fatal("parse_answer: unable to parse header line: $line");
}
}
} else {
// Return -1 as response code if parsing was not possible
return array(-1);
}
return array($response_code, $headers, $body, $full_headers);
}
$xml_request = '<?xml version="1.0" encoding="UTF-8" ?>
<SMSBoxXMLRequest>
<username>user</username>
<password>pass</password>
<command>WEBSEND</command>
<parameters>
<receiver>+41761234567</receiver>
<operator>sunrise</operator>
<service>DUDE</service>
<text>message from WEBSEND</text>
<cost>20</cost>
</parameters>
</SMSBoxXMLRequest>';
// Execute the post request using our helper function.
$answer = send('http://pro.smsbox.ch:8047/Pro/sms/xml', $xml_request);
$response_code = $answer[0];
$body = $answer[2];
// Do anything with $response_code and htmlspecialchars($body)
?>