topical media & game development

talk show tell print

professional-search-14-seophp-robots.php / php



  <?php
  // set propert content type
  header('Content-type: text/plain');
  
  // include config file
  require_once 'include/config.inc.php';
  // load database tools
  require_once('include/database_tools.inc.php');
  // load the URL factory
  require_once 'include/url_factory.inc.php';
  
  // this query returns product_id and secondary_category_id data which needs to be
  // excluded using robots.txt
  q = 'SELECT products.*, ' . 
       'product_categories.category_id AS secondary_category_id, ' . 
       'categories.name AS secondary_category_name ' .
       'FROM products LEFT JOIN product_categories ' .
       'ON (product_categories.product_id = products.id) ' .
       'LEFT JOIN categories ' .
       'ON (product_categories.category_id = categories.id) ' .
       'WHERE products.primary_category_id <> product_categories.category_id'; 
  
  // get a database connection
  db_link = DatabaseTools::getConnection();
   
  // execute the query
  query_results = mysql_query(q);
  
  // close database connection 
  DatabaseTools::closeConnection(db_link);     
  
  // create an associative array with the results
  rows = array();
  while (result = mysql_fetch_assoc(query_results)) {
    rows[] = result;
  }
  
  // User agent
  echo "User-agent: * \r\n";
  
  // display the links that need to be excluded
  foreach (rows as row)
  {
    // get the category and product IDs
    product_id = row['id'];
    category_id = row['secondary_category_id'];
    product_name = row['name'];
    category_name = row['secondary_category_name'];
    
    // create disallow definition
    url = make_category_product_url(category_name, category_id, 
                                     product_name, product_id);
                                     
    disallow = str_replace(SITE_DOMAIN, '', url);                                   
    echo "Disallow: " . disallow . "\r\n";
  } 
  
  ?>
  Disallow: /cart.php
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.