PHP Simple XML Parser,空白回复。
以下代码的主要问题是没有解析器它会正常工作但是只要添加了XML解析器,它就可以从客户端连接到其他服务器,它不会返回结果,只是一个空白页?
这也是一个项目,所以在有人问之前,为什么你没有任何SQLi保护。我还没有实现它。
以下是代码:
客户端XML解析器代码:hinphp.php
<?php
$hin = $_GET["hin"];
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, "http://192.168.0.12/hinbuy.php?hin=");
curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
curl_setopt($connection,CURLOPT_HEADER, 0);
$response = curl_exec($connection);
$xml = simplexml_load_string($response);
for($index=0; $index < count($xml->songs); $index++)
{
echo $xml->songs[$index]->ID . "<br />";
echo $xml->songs[$index]->song . "<br />";
echo $xml->songs[$index]->artist . "<br />";
echo $xml->songs[$index]->year . "<br />";
echo $xml->songs[$index]->genre . "<br />";
echo $xml->songs[$index]->quantity . "<br />";
$ID = $xml->songs[$index]->ID;
echo "<a href='http://192.168.0.12/buyclihin.php?ID=$ID'>buy</a>";
}
curl_close($connection);
?>
服务器端PHP选择代码:hinbuy.php
<?php
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
echo "<hit>";
$hin = $_GET["hin"];
$conn = new PDO("mysql:host=localhost;dbname=xxxxx;","xxxxx","xxxxx");
$results = $conn->query("SELECT * FROM `ghit` WHERE `artist`='$hin'");
while($row=$results->fetch())
{
echo "<songs>";
echo "<id>$row[ID]</id>";
echo "<song>$row[song]</song>";
echo "<artist>$row[artist]</artist>";
echo "<year>$row[year]</year>";
echo "<genre>$row[genre]</genre>";
echo "<quantity>$row[quantity]</quantity>";
echo "</songs>";
}
echo "</hit>"
?>
答案 0 :(得分:1)
可能是因为您没有将$hin
传递给hibbuy.php
吗?
尝试:
$hin = $_GET["hin"];
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, "http://192.168.0.12/hinbuy.php?hin=" . $hin);