";
$array_tmp = split("/", $_SERVER['HTTP_REFERER']);
//print_r($array_tmp);
if($array_tmp[2] != "blogs.yahoo.co.jp"){
die("This access is not proper.");
}
$user = $array_tmp[3];
$_GET['user'] = $user;
//20080720 Added.
define(ARTICLE_SQL_BUFFER, 10);
$sql_buffer_path = "sql_buffer/".$user.".txt";
if(!file_exists($sql_buffer_path)){
touch($sql_buffer_path);
}
$article_sql_buffer = file($sql_buffer_path);
if(count($article_sql_buffer) <= ARTICLE_SQL_BUFFER) {
$sql = "('".date("Y-m-d H:i:s")."', '".$_SERVER['HTTP_REFERER']."', '".$_SERVER['HTTP_ACCEPT_LANGUAGE']."', '".$_SERVER['HTTP_USER_AGENT']."', '".$_COOKIE['article']."', '".$_SERVER['REMOTE_ADDR']."'),\n";
echo "sql: ".$sql."
\n";
$fp = fopen($sql_buffer_path, "a");
fwrite($fp, $sql);
die ("Added SQL to bulk.");
} else {
foreach($article_sql_buffer as $key => $value){
$sql_bulk .= rtrim($value);
}
$sql_bulk = rtrim($sql_bulk, ",");
$sql_bulk = "insert into ".$user." (datetime, HTTP_REFERER, HTTP_ACCEPT_LANGUAGE, HTTP_USER_AGENT, COOKIE, ip_address) values ".$sql_bulk.";";
//20080720 Commented out.
//$sql = "insert into ".$user." (datetime, HTTP_REFERER, HTTP_ACCEPT_LANGUAGE, HTTP_USER_AGENT, COOKIE, ip_address) values (NOW(), '".$_SERVER['HTTP_REFERER']."', '".$_SERVER['HTTP_ACCEPT_LANGUAGE']."', '".$_SERVER['HTTP_USER_AGENT']."', '".$_COOKIE['article']."', '".$_SERVER['REMOTE_ADDR']."');";
echo "\$sql_bulk: ".$sql_bulk."
\n";
//$rs = mysql_db_query($db,"set names ujis");
//echo "\$_SERVER['REMOTE_ADDR'] : ".$_SERVER['REMOTE_ADDR']."
";
$fp = fopen($sql_buffer_path, "w");
fwrite($fp, "");
echo "Deleted the content of the file.";
}
#$link = get_link("yahoo_articles");
$link = get_link_host("yahoo_articles", 'yahoo_articles.tokyovalley.com');
if ($rs = get_rs($sql_bulk, $link)){
echo "success
";
} else {
echo "failed
";
}
$row = mysql_fetch_assoc($rs);
print_r($row);
echo "
";
print_r( mysql_error($rs) );
echo "
";
//echo "
";
mysql_close($link);
function get_rs($sql, $link){
//print_r($link);
$result = mysql_query($sql, $link);
//print_r($result);
if (!$result) {
echo "DB Error, could not query the database
\n";
$error = mysql_error();
echo "MySQL Error: " . $error;
//continue;
echo strpos($error, "doesn't exist");
if( strpos($error, "doesn't exist")!=0 && strpos(" ".$error, "Table")!=0){
create_table($_GET['user']);
}
exit;
}
}
function create_table($table_name){
echo "\$table_name : ".$table_name;
//$_GET['user'] = $table_name;
#$link = get_link("yahoo_articles");
$link = get_link_host("yahoo_articles", 'yahoo_articles.tokyovalley.com');
$sql = "CREATE TABLE `".$_GET['user']."` ("
."`id` int(11) NOT NULL auto_increment,"
."`datetime` datetime default NULL,"
."`ip_address` varchar(100),"
."`HTTP_REFERER` text,"
."`HTTP_ACCEPT_LANGUAGE` text,"
."`HTTP_USER_AGENT` text,"
."`COOKIE` text,"
."PRIMARY KEY (`id`),"
."KEY `index_HTTP_REFERER` (`HTTP_REFERER`(40))"
.") ENGINE=MyISAM DEFAULT CHARSET=latin1;";
echo $sql."\n";
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
continue;
//exit;
}
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}
mysql_free_result($result);
}
?>