two questions

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
delhiris
Forum Commoner
Posts: 33
Joined: Sun Sep 06, 2009 3:57 pm

two questions

Post by delhiris »

Hi
I like to make php application for sending data via HTTPS with user-name and password.
this application should be hosted on my PC.
On my PC I installed
php-4.2.1-Win32 and apache_1.3.24-win32-x86-no_src.msi
I have two php files copied below
<?php

$TTX_RPCURL="https://ttx.plusplus.co.yu/rpc";
$TTX_USERNAME="admin";
$TTX_PASSWORD="admin";

function teletext_output( $service, $page, $subpage, $text ) {
global $TTX_RPCURL, $TTX_USERNAME, $TTX_PASSWORD;

$transport = array(
'subpages' => array(
array(
'service_name' => $service,
'rent_page' => $page,
'number' => $subpage,
'dyndata' => $text,
'enable' => 1,
)
)
);

$request = xmlrpc_encode_request("direct", $transport);

$auth = base64_encode($TTX_USERNAME.':'.$TTX_PASSWORD);

$context = stream_context_create(
array(
'http' =>
array(
'method' => "POST",
'header' =>
"Authorization: Basic $auth\r\n".
"Content-Type: text/xml\r\n",
'content' => $request
)
)
);

$file = file_get_contents($TTX_RPCURL, false, $context);

$response = xmlrpc_decode($file);

return $response;
}

$response = teletext_output( "rtrs", 810, 0,
'prvi red
drugi red
treci red'
);

if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
echo "OK";
}

?>


and the second

<?php

function xencode_struct($arr) {
$enc_struct = '<struct>';
foreach ($arr as $name => $value) {
$enc_struct .= '<member><name>'.$name.'</name><value>'. xencode( $value ) .'</value></member>';
}
$enc_struct .= '</struct>';
return $enc_struct;
}

function xencode_array($arr) {
$enc_array = '<array>';
foreach ($arr as $element) {
$enc_array .= '<data>' . xencode( $element ) . '</data>';
}
$enc_array .= '</array>';
return $enc_array;
}

function xencode($val) {
if(is_array($val)) {
if($val == array_values($val)) {
return xencode_array($val);
} else {
return xencode_struct($val);
}
} elseif(is_bool($val)) {
return '<boolean>'. ($val?'1':'0') . '</boolean>';
} elseif(is_int($val)) {
return '<int>'. $val . '</int>';
} elseif(is_float($val)) {
return '<double>'. $val . '</double>';
} elseif(is_string($val)) {
return '<string>'. htmlspecialchars($val, ENT_QUOTES) . '</string>';
} else {
trigger_error("xencode: cannot encode variable of type: " . gettype($val));
}
}

function xencode_request($method_name, $transport) {

$enc_param = xencode($transport);

$enc_call = "<methodCall>" .
"<methodName>" .$method_name."</methodName>".
"<params><param>" . $enc_param . "</param></params>".
"</methodCall>";

return $enc_call;
}

$TTX_RPCURL="https://ttx.plusplus.co.yu/rpc";
$TTX_USERNAME="admin";
$TTX_PASSWORD="admin";

function teletext_output( $service, $page, $subpage, $text ) {
global $TTX_RPCURL, $TTX_USERNAME, $TTX_PASSWORD;

$transport = array(
'subpages' => array(
array(
'service_name' => $service,
'rent_page' => $page,
'number' => $subpage,
'dyndata' => $text,
'enable' => 1,
)
)
);

$request = xencode_request("direct", $transport);

$auth = base64_encode($TTX_USERNAME.':'.$TTX_PASSWORD);

$context = stream_context_create(
array(
'http' =>
array(
'method' => "POST",
'header' =>
"Authorization: Basic $auth\r\n".
"Content-Type: text/xml\r\n",
'content' => $request
)
)
);

$file = file($TTX_RPCURL, false, $context);

$contents = '';
foreach($file as $line)
$contents .= $line;

eregi( '<methodResponse>(.*)</methodResponse>', $contents, $matches );

$res = $matches[1];
$res2 = strtr( $res, array("\r" => '', "\n" => '', "\t"=>'', ' '=>'') );

if($res2 == '<params><param><value><struct></struct></value></param></params>') {
return '';
}

return $res;
}

$response = teletext_output( "rtrs", 809, 0,
"1. prvi red\n".
"2. drugi red\n".
"3. treci red\n");

if ($response != '') {
trigger_error("xmlrpc response: $response");
} else {
echo "OK";
}

?>

Can I perform these two files on my web server?
Can I perform php application on my web server what will attach to web service?
Post Reply