Bonjour,
Je dois ecrire un prog pour recevoir des donnees via http.
tout fonctionne bien, sauf si les donnees contiennent des caracteres du genre & # 3 9 ; (tout colle, sans les espaces - ce qui represente l'apostrophe en code UTF8.
Le premier prog est un prog d'envoie qui utilise curl
Le second (qui 'merde' !!) est le programme de réception.
Si quelqu'un avait l'idée de génie qui me decoincerait !!!!
Merci d'avance
==========================================
<?php
// sender.php
//1) PROGRAM USE TO SEND DATA TO THE SERVER (CLIENT)
$fic=$argv[1];
$fp = fopen($fic,"r");
$data="";
$data=fread($fp,filesize($fic));
fclose($fp);
$postvars="AUTH_USER=username&AUTH_PASS=password&AUTH_XML=".$data;
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "[
myurl]
;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
?>
==========================================
2) THE DATA (passed as argv[1] to sender.php)
<?xml version="1.0"?>
<ImportantRemarks>
<Line1>L'ASSURANCE DE TRANSPORT N'EST PAS A COUVRIR </Line1>
</ImportantRemarks>
==========================================
3) PROGRAM USE TO RECEIVE DATA
<?php
// index.php
// is username ok ?
if (!isset($HTTP_POST_VARS['AUTH_USER']))
{
$buffaux="*NOK* USER ABSENT <br>\n";
print $buffaux;
exit(1);
}
else
{
$zuser = $HTTP_POST_VARS['AUTH_USER'];
if ($zuser <> "userrname")
{
$buffaux="*NOK* USER INVALIDE ".$zuser."<br>\n";
print $buffaux;
exit(1);
}
}
// is password ok ?
if (!isset($HTTP_POST_VARS['AUTH_PASS']))
{
$buffaux="*NOK* PASSWORD ABSENT <br>\n";
print $buffaux;
exit(1);
}
else
{
$zpass = $HTTP_POST_VARS['AUTH_PASS'];
if ($zpass <> "password")
{
$buffaux="*NOK* PASSWORD INVALIDE ".$zpass."<br>\n";
print $buffaux;
exit(1);
}
}
// Controle si presence du fichier xml
if (!isset($HTTP_POST_VARS['AUTH_XML']))
{
$buffaux="*NOK* FICHIER ABSENT <br>\n";
print $buffaux;
exit(1);
}
else
{
$zfic = $HTTP_POST_VARS['AUTH_XML'];
$zfic = str_replace('\"', '"', $zfic);
}
$today=date("YmdHis");
$file = "xml.".$today.".tmp";
// All is ok, now we can parse the file
$fp = fopen($file, "w");
fputs($fp, $zfic);
fclose($fp);
// call the parser (when the data is received, the parser work fine)
// but if the data contain characters like & # 3 9 ; the data is not received correctly
?>