I've made a little script that checks for last wordpress version of a site, for some its ok if the website shows the info about version, but there is a problem where if there are more name="generator" it gets the last line.
Any ideas guys? Thanks.
<?php
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$link = mysqli_connect("localhost", "", "", "");
if($link === false) { die('No connection!' . mysqli_connect_error()); }
$sql = "SELECT * FROM My_Websites ORDER BY date";
if($result = mysqli_query($link, $sql)) {
if(mysqli_num_rows($result) > 0) {
echo '<table class="table table-striped table-hover">';
echo '<thead>';
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Adaugat</th>";
echo "<th>Domeniu</th>";
echo "<th>Versiune WP.</th>";
echo "<th>Admin</th>";
echo "</tr>";
echo "</thead>";
while($row = mysqli_fetch_array($result)){
$domeniu = $row['website'];
$html = file_get_contents_curl($domeniu);
//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$title = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
if($meta->getAttribute('name') == 'generator')
$generator = $meta->getAttribute('content');
}
echo "<tr>";
echo "<td> " . $row['id'] . " </td>";
echo "<td> " . $row['date'] . " </td>";
echo '<td> <a href="http://' . $domeniu . '" target="_blank">' . $domeniu . '</a></td>';
echo "<td> " . $generator . " </td>";
echo '<td> <a href="http://' . $domeniu . '/wp-admin" type="button" class="btn btn-default btn-sm"> <span class="glyphicon glyphicon-link" style="color:blue;"></span> acceseaza </a></td>';
echo "</tr>";
}
echo "</table>";
mysqli_free_result($result);
} else { print ('Error!'); }
} else { print 'Error!' . mysqli_error($link); print '.'; }
mysqli_close($link);
?>