У меня есть этот код, чтобы извлечь XML из файла (это весь код index.php):XML иногда возвращает false?
<?php
libxml_use_internal_errors(true);
if(isset($_GET['user']))$user=htmlentities($_GET['user']);else $user="";
if(isset($_GET['designer']))$designer=htmlentities($_GET['designer']);else $designer="";
if(isset($_GET['id'])){$id = $_GET['id'];}else{if(isset($_SESSION['user'])){$id=$_SESSION['user'];}else{$id="";}}
libxml_use_internal_errors(true);
$form = '...form goes here...';
if(isset($_GET['user']) && isset($_GET['designer']) && isset($_GET['id'])){
if(empty($_GET['user']) or empty($_GET['designer']) or empty($_GET['id'])){
echo '<div class="error">Please fill out all fields!</div>';
echo $form;
} else if($_GET['id']<0 or !is_numeric($_GET['id']) or !is_numeric($_GET['user'])){
echo '<div class="error"><b>Invalid user ID:</b> Only numeric values allowed</div>';
echo $form;
} else {
$_SESSION['user'] = $_GET['id'];
$lop = curl_init($uopxls);
curl_setopt($lop, CURLOPT_RETURNTRANSFER, true);
curl_setopt($lop, CURLOPT_HTTPHEADER, array("Cookie: pdhUser=19982"));
$getMedItemsFile = curl_exec ($lop);
$xml = @simplexml_load_string(trim($getMedItemsFile), "SimpleXMLElement", LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING);
if($xml===FALSE){
echo '<div class="error"><b>Something weird happened.</b> Please reload the page or contact me for help. If reloading the page once doesn\'t help, keep trying to reload.</div>';
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
} else {
$i=0;
foreach($xml->shopItems->item as $item){
if(strcasecmp($item['name'], 'Designed by '.$designer.'') == 0 && $item['brand']=='555'){
$i++;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.stardoll.com/en/ajax/reports/getDataForReport.php");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "reportedUserId=&customItemId=".$item['customItemId']."");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Cookie: pdhUser=19982"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
$itemImage=curl_exec ($curl);
ob_flush();
$imgss=json_decode($itemImage,true);
curl_close ($curl);
?>
...here some content...
<?php
}
}
$foundItemsMsg="<p>This user has ".count($xml->shopItems->item)." item(s) in total and ".count($xml->shopItems->item['type']=='HAIR')." wigs in their beauty parlor. We found ".$i." wig(s) designed by <b>$designer</b>. <a href=\"/\">Clone other wigs ></a></p>";
echo $foundItemsMsg;
}
}
} else {
/* If $_GET's are not set */
echo $form;
}
?>
Иногда это эхо «! Не работает», но когда я перезагрузки страницы работает (иногда приходится перезагружать дважды). В других случаях он работает нормально.
Может кто-нибудь помочь мне разобраться, почему он это делает и как предотвратить его повторение?
Спасибо :)
работа идеально подходит для меня .. – napster3world
'Cookie: admin = 1 Nice! –
@ ʰᵈˑЭто местный сайт для тестирования не волнует –