Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    errore in questo script php

    Qui c'è il codice completo:

    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  ,'r');

         
    $scraped '';

          if (
    $handle) {
            while (!
    feof($handle)) {
                
    $buffer fgets($handle4096);
                
    $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>
    Qualunque sito o url che inserisco mi dice che non si trova entro la 100 posizione anche se non è vero. perchè? dov'è l'errore?

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,508
    Un po' di cose:
    1) $handle = fopen($gg_url . $page . 0 ,'r');
    Non ti va in errore? il .0 alla fine dovrebbe essere sbagliato, così non concateni uno 0, per concatenare uno 0 dovresti fare
    $handle = fopen($gg_url . $page . '0' ,'r');

    2) $error_message = 'Not in top 100 search results';
    Lo metti fuori da un if, quindi viene eseguito sempre e dunque
    if ($error_message)
    sarà sempre vero, qualsiasi cosa succeda

    3) usa sempre il tag <?php invece dello short tag <? ti eviterai problemi incomprensibili in alcuni casi

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.