Qui c'è il codice completo:
Qualunque sito o url che inserisco mi dice che non si trova entro la 100 posizione anche se non è vero. perchè? dov'è l'errore?Codice PHP:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Where's it rank at Google?</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
form { width: 500px; margin: 0 auto; }
.error_message { color: #920000; }
label {
display: block;
margin-top: 1em;
}
input[type=submit] {
margin-top: 1em;
}
address { font-size: .75em; text-align: center; }
</style>
<script type="text/javascript" language="javascript">
function init() {
document.url_kw.keyword.focus();
}
</script>
</head>
<?
/*
[url]http://www.seomoz.org[/url]
Author: Matthew Inman <matt@seomoz.org>
File: whererank.php
Description:
This script searches google for a given search term and redirects the user to the
page of search results that contains the target URL.
Installation:
Rename this file have a .php extension and upload it to your web server.
*/
if (isset($_GET['url']) && isset($_GET['keyword'])) {
$gg_url = 'http://www.google.it/search?hl=it&q=' . urlencode($_GET['keyword']) . '&start=';
$url = preg_replace('(^[url]http://[/url]|/$)','',$_GET['url']);
for ($page = 0; $page < 9; $page++) {
$handle = fopen($gg_url . $page . 0 ,'r');
$scraped = '';
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$scraped .= $buffer;
}
fclose($handle);
}
$results = array();
preg_match_all('/a href="([^"]+)" class=l.+?>.+?<\/a>/',$scraped,$results);
foreach ($results[1] as $serp) {
$serp = preg_replace('(^[url]http://[/url]|/$)','',$serp);
if ($serp == $url) {
header('Location: ' . $gg_url. $page . '0');
exit;
}
}
}
$error_message = 'Not in top 100 search results';
}
?>
<body onload="javascript: init();">
<form name="url_kw" action="<?= $_SERVER['PHP_SELF'] ?>" method="get">
<fieldset>
<legend>Where's it rank at Google?</legend>
<? if ($error_message): ?>
<strong class="error_message">Not found in top 100 search results[/b]
<? endif; ?>
<label for="url">URL:</label>
<input type="text" name="url" id="url" size="55" value="<?= isset($_GET['url']) ? $_GET['url'] : 'http://' ?>" />
<label for="keyword">Keyword:</label>
<input type="text" name="keyword" id="keyword" size="35" value="<?= isset($_GET['keyword']) ? $_GET['keyword'] : null ?>" />
<input type="submit" name="submit_button" value="SEARCH" onclick="this.value='Searching...';" />
<input type="button" value="CANCEL" onclick="javascript: window.location='<?= $_SERVER['HTTP_REFERER'] ?>';" />
[b]Browser Button[/b]
Drag this link to your browser toolbar, or right-click it and choose Bookmark This Link:
[url="javascript:location.href='<?= $_SERVER['SCRIPT_URI'] ?>?url='+location.href"]Where's it rank?[/url]
</p>
</fieldset>
</form>
</body>
</html>
</body>
</html>

Rispondi quotando