Hi,
I tried a auto-comment bot for wordpress(in my website) and coded it. My plan is that I write names in names.txt file and sample comments in comments.txt file(a name or comment per line) and it will add a random comment with a random name into Wordpress's database in wp_comments table. I also planned to increase comment_count value in wp_posts table, however my code is not working. Here is the code:

<?php

include "wp-config.php";

$asama1=@mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("<h1>Something was wrong.</h1>");
$asama2=@mysql_select_db(DB_NAME,$asama1) or die("<h1>Database could not be found.</h1>");



$isim=file(names.txt);
$yorum=file(comments.txt);
$id="1";
$idarray=explode(",",$id);
$kactaneidvar=count($idarray);
$kactaneidvar--;
$rastgeleidal=rand(0,$kactaneidvar);
$id=$idarray[$rastgeleidal];
$x=$_GET["kactane"];
$kactane=(integer) $x;

$sayilari=count($isim);
$sayilari2=count($yorum);
$sayilari--;
$sayilari2--;

$rastisim=rand(0,$sayilari);
$rastyorum=rand(0,$sayilari2);
$yorumsayi=1;
while($yorumsayi<=$kactane){
// ------------------- random names and comments adding to db is starting.------------
$ekleisim=$isim[$rastisim];
$ekleyorum=$yorum[$rastyorum];

$yorumla=@mysql_query("INSERT INTO wp_comments(comment_post_ID,comment_author,comment_content,comment_approved,comment_parent,user_id) VALUES($id,$ekleisim,$ekleyorum,'1','0','0')");
$yorumsayal=@mysql_query("SELECT comment_count FROM wp_posts WHERE id=$id");
$yorumsayal++;
$sayiart=@mysql_query("INSERT INTO wp_posts(comment_count) VALUES($yorumsayal)");
if($yorumla){
echo $yorumsayi.". yorum eklendi.</br>";
$yorumsayi++;
}
}
// -------------------end of random names and comments adding to db.--------------
?>
serrion9 commented: Hey, I've just received a free Minecraft Giftcode! You can get one too! >> minecraftcodes.me << +0

Recommended Answers

All 3 Replies

Just use a mysql database to store the names, then you can connect to the database, and select a random name.. here is an example of a random i made for a simple video game lotery

<?php
// Echo random

$username="db_user"; //enter your database username
$password="password"; //enter your db password
$database="db_name"; //enter the name of your database

mysql_connect(localhost,$username,$password); 
@mysql_select_db($database) or die( "Unable to select database"); 
$query=	"SELECT * FROM pins WHERE used > 0 ORDER BY RAND() LIMIT 1"; 
$result=mysql_query($query);
$num=mysql_num_rows($result);

mysql_close(); 

$i=0; 
while ($i < $num) {
$Pin=mysql_result($result,$i,"pin");
echo"$Pin"; 
$i++;
};

?>

It selects a random row from a mysql database that has the column value greater that 0. Then it echos it out...

Go check it out - http://ggdesigning.com/test_random.php

commented: thank you for your answer:) +0

thank you for answer. I haven't used mysql_result() function but I'm going to try it. I thought that using txt files are easy to use and edit, besides couldn't I use txt files as arrays using file() function?

You could but with a mysql database, you can setup an easy access form to add stuff, delete stuff, edit stuff, ect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.