Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
GUH! Help messed up script not working :(
Old 01-17-2008, 04:08 PM GUH! Help messed up script not working :(
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hey i was playing with my counter script and now it dont work and i cant figure out why the hell it aint working!

PHP Code:
<?php
function count_rows_where($type)
{
$row_count_res mysql_query("SELECT * FROM counter WHERE type='$type'");
$num_of_rows mysql_num_rows($row_count_res);
  if(
$type=='bot')
  {
  
mysql_query("UPDATE counter_total SET bot_total='$num_of_rows' WHERE id='2'");
  }
  else 
  {
  
mysql_query("UPDATE counter_total SET total='$num_of_rows' WHERE id='2'");  
  }
}
$ip $_SERVER['REMOTE_ADDR'];
$user_agent $_SERVER['HTTP_USER_AGENT'];
$datetime date('Y-m-d H:i:s');
$result mysql_query("SELECT * FROM counter WHERE ip='$ip' ORDER BY visit_time DESC LIMIT 1"
or die(
"ERROR select check if exist".mysql_error());
$user_count mysql_fetch_array($result);
$row_num mysql_num_rows($result);
$yesturday date('U') - 60*60*24;
if(
$row_num == && strtotime($user_count['visit_time']) > $yesturday)
{
$result_2 mysql_query("SELECT total FROM counter_total WHERE id='1'");
$count mysql_fetch_array($result_2);
echo 
$count['total'];
$result_id mysql_query("SELECT * FROM counter WHERE ip='$ip' AND user_agent='$user_agent' ORDER BY visit_time DESC LIMIT 1") or die("Error retriveing ID".mysql_error());
$counter_id mysql_fetch_array($result_id);
echo 
'<!-- COUNTER ID: '.$counter_id['id'].'-->';
     
count_rows_where('bot');
      
count_rows_where('user');
}
else {
  
$user_agent strtolower($_SERVER['HTTP_USER_AGENT']);
  
$spider_flag false;
  
  
/* if (!empty($user_agent))
   {*/
     
$spiders file('includes/spiders.txt');
     for (
$i 0$i count($spiders); $i++)
     {
       if (!empty(
$spiders[$i]))
       {
         if (
is_integer(strpos($user_agenttrim($spiders[$i]))))
         {
           
$spider_flag true;
           break;
         }
   else 
   {
           
$spider_flag false;
     break;
   }
   
   if(
$spider_flag == false)
   {
      
//is normal user
         
mysql_query("INSERT INTO counter SET ip='$ip',visit_time='$datetime',user_id='0',user_agent='$user_agent',type='user'"
     or die(
"ERROR inserting".mysql_error());
     
         
mysql_query("UPDATE counter_total SET total=total + 1 WHERE id='1'"
     or die(
"ERROR adding to counter total".mysql_error());
   
   
count_rows_where('bot');
    
count_rows_where('user');
   }
   else {
              
// Is Spider/Bot
           
mysql_query("INSERT INTO counter SET ip='$ip',visit_time='$datetime',user_id='0',user_agent='$user_agent',type='bot'")
       or die(
"ERROR inserting".mysql_error());
    
           
mysql_query("UPDATE counter_total SET bot_total=bot_total + 1 WHERE id='1'"
       or die(
"ERROR adding to counter total".mysql_error());
    
     
count_rows_where('bot');
      
count_rows_where('user');
   } 
// End ELSE spider flag false
       
}// End if not empty spider
     
}// End FOR()
 #  }//End if user_agent empty
   
   
   
$ip $_SERVER['REMOTE_ADDR'];
$user_agent $_SERVER['HTTP_USER_AGENT'];
$result_2 mysql_query("SELECT total FROM counter_total WHERE id='1'");
$count mysql_fetch_array($result_2);
echo 
$count['total'];
$result_id mysql_query("SELECT id FROM counter WHERE ip='$ip' ORDER BY visit_time DESC LIMIT 1");
$counter_id mysql_fetch_array($result_id);
echo 
'<!-- COUNTER ID: '.$counter_id['id'].'-->';
}

?>
Also im trying to make this script work which is SUPOSED to go through and change the type to bot if it appears to be a bot (its name is on my bot list)

PHP Code:
<?php
include "includes/includes.php";
$resmysql_query("SELECT * FROM counter");
while(
$row=mysql_fetch_array($res))
{
$user_agent $row['user_agent'];
  
$user_agent strtolower($user_agent);
  
$spider_flag false;
  
     
$spiders file('includes/spiders.txt');
     for (
$i 0$i count($spiders); $i++)
     {
       if (!empty(
$spiders[$i]))
       {
         if (
is_integer(strpos($user_agenttrim($spiders[$i]))))
         {
           
$spider_flag true;
         }
   else 
   {
           
$spider_flag false;
   }
   
   if(
$spider_flag == true)
   {
           
// Is Spider/Bot
           
mysql_query("UPDATE counter SET type='bot' WHERE user_agent='".$spiders[$i]."'") or die("Error 1:".mysql_error());
         }
   else 
   {
   
//is normal user
           
mysql_query("UPDATE counter SET type='user' WHERE type=''") or die("Error 2:".mysql_error());   
   }
     }
   }
#   mysql_query("UPDATE counter SET type=''") or die("Error 3:".mysql_error());
}
?>
SOMEONE PLEASE HELP!!!
this is doing my head in i need to get it done.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Reply     « Reply to GUH! Help messed up script not working :(
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.08615 seconds with 12 queries