• Welcome to Valhalla Legends Archive.
 

PHP Counter

Started by CrAz3D, March 09, 2005, 01:32 PM

Previous topic - Next topic

CrAz3D

I'd like to create a simple php counter for my bot.  1 that logs the user's name & how many tiems they've connected.

What I need to know how to do is loop through the database (a .txt file) and see if the username is in it.  If the username IS in the file, it adds to the # that follows their name (increasing the amount of times they've logged on).  If they weren't found, I'd like to add them to the .txt file with a 1 following their name.

Can anyone tell me how to go about this?
Much thanks

EDIT: Something close to this
http://forum.valhallalegends.com/phpbbs/index.php?topic=4780.msg40054#msg40054



This is what I came up with, it seems to work
<?php$user = $_SERVER['REMOTE_ADDR'];//$_REQUEST['user'];$logfile = "list.txt";$file1 = file($logfile);$i = 0;$text="";$found= "false";//LINE 10~!for ($i = 0; $i < count($file1);$i++){list ($var1, $var2) = explode(" ", $file1[$i]);if (strstr(strtolower($var2), strtolower($user))){$var1++;$file1[$i]="$var1 $var2";$text = $text . $file1[$i];$found="true";}else{$text = $text . $file1[$i];}	$ledit = @fopen($logfile, "r+");	@fwrite($ledit, $text);	@fclose($ledit);}if (strstr($found, "false")){	$ledit = @fopen($logfile, "a+");$towrite="1 $user";	@fwrite($ledit,$towrite);	@fclose($ledit);}?>


rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Meh

I found that quite hard to follow and the colors didnt help(Probs cos im tired)/ Maybe it would be easier if you add comments. Seems ok from what I understood.

CrAz3D

The colors won't leave :(
<?php$user = $_SERVER['REMOTE_ADDR'];//$_REQUEST['user'];  //I removed this just for now, may add it in later$logfile = "list.txt";$file1 = file($logfile);//A few predeclared variables$i = 0;$text="";$found= "false";//LINE 10~! --- This is to help me count lines since I am using notepadfor ($i = 0; $i < count($file1);$i++){  //loops through each line of my filelist ($var1, $var2) = explode(" ", $file1[$i]); //seperates the line by a space into 2 variablesif (strstr(strtolower($var2), strtolower($user)))  //checks to see if var2 is the same as user{$var1++; //increases count of the user$file1[$i]="$var1 $var2";$text = $text . $file1[$i];$found="true";}else{$text = $text . $file1[$i];}$ledit = @fopen($logfile, "r+"); //if the user was found, it edits the .txt file@fwrite($ledit, $text);@fclose($ledit);}if (strstr($found, "false")) //if the user wasn't found, it adds them{$ledit = @fopen($logfile, "a+");$towrite="1 $user";@fwrite($ledit,$towrite);@fclose($ledit);}?>
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

R.a.B.B.i.T

<?php$query = mysql_query("UPDATE site_info SET counter=counter+1");?>

CrAz3D

#1 I don't have MySql installed on my computer
#2 I'm too cheap to buy hosting
#3 I'm too lazy to ask someone for hosting & keep uploading stuff
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Banana fanna fo fanna

www.freesql.org

#4 You're too cheap and lazy to have a counter?

Newby

- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Insecure

Craz I have a webserver that I own if you want I can help you out...
PM me
   or
AIM me

Suicidal SnIp3r

Warrior

I wrote one for Networks Craz3d. If you ask him nicely he will like help you :p. Writes to a text file (using mySQL for something as simplistic as this in my opinion is a waste of time) . Stores the file in an two (or three I forget) arrays
file-> name
         channel
         server
         time (or date I forget)

I'm planning on rewriting it (there was a bug causing duplicate entries not to be removed) I think Networks fixed it though.
                                             
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?