<?PHP
header("Content-type: image/vnd.wap.wbmp");

 mysql_select_db("ianev_org_-_wapcounter", mysql_connect("localhost", "jeko", "jekodb" ) ) ;
 
 
 $query = "SELECT user_id,cnt FROM users WHERE user_name='".$u."'";
 $user_id = mysql_fetch_row(mysql_query($query));
 $cnt = $user_id[1];
 $user_id = $user_id[0];
 if ($user_id)
  {
    if($cnt<50000)
	 {
      $headers = getallheaders();
	  $user_agent = $headers["User-Agent"];
      $query="INSERT INTO wapcount".$user_id." VALUES ('','".gmdate("Y-m-d H:i:s")."','$user_agent')";
      mysql_query($query);
     }
//   $query = "SELECT count(*) FROM wapcount".$user_id;
//   $text = mysql_fetch_row(mysql_query($query));
//   $text = $text[0];
   $text = $cnt+1;
   mysql_query("UPDATE users SET cnt=cnt+1,lcnt=NOW() WHERE user_id='".$user_id."'");
    if (!$height) $height=15;
    if (!$width) $width=strlen($text)*7+10;
    $im = imagecreate($width,$height);
 
    $background = ImageColorAllocate($im, 255,255,255);

    $black=ImageColorAllocate($im, 0,0,0);
    ImageString($im,3,$width-strlen($text)*7-5,0,$text,$black);
    ImageWBMP($im);
    ImageDestroy($im);
  }
 else
  {
   // Blank Image
   echo chr(0).chr(0).chr(1).chr(2).chr(128).chr(128);
  } 
?>