Page 1 of 1

PHP reading in a txt, looking after the text, and deleting..

Posted: Mon Feb 28, 2005 6:13 pm
by Vladinator
This gathers the provided key from the registration form:

Code: Select all

$gmkey1  = $_POSTї'gmkey1']; 
$gmkey2  = $_POSTї'gmkey2']; 
$gmkey3  = $_POSTї'gmkey3']; 
$gmkey   = "$gmkey1-$gmkey2-$gmkey3";
Now, I need to make a file, with some keys looking like this:
XXXX-XXXX-XXXX , the list will be something like this:

Code: Select all

1234-1234-1234
3214-3214-3214
4567-4567-4567
6547-6547-6547
And so on. Now I need someway to make the PHP read from the TXT file, and compare the given key, with the once in the list. If the key does not exist, the php wont care, and just continue with the variable: $gm = "0";
If it was true, then the variable becomes: $gm = "6"; and the line with the key is beeing deleted.

Now, I need help making that script, help me! :)

Posted: Mon Feb 28, 2005 6:22 pm
by feyd
what do you have so far for this? We aren't here to do it for you..

Posted: Tue Mar 01, 2005 4:53 am
by Vladinator
So far this is my script:

Code: Select all

<?php

// Getting the configurations.
include("config.php");

// Getting the information typed on the last page.
$accname = $_POST&#1111;'accname']; 
$accpass = $_POST&#1111;'accpass']; 
$accmail = $_POST&#1111;'accmail']; 
$gmkey1  = $_POST&#1111;'gmkey1']; 
$gmkey2  = $_POST&#1111;'gmkey2']; 
$gmkey3  = $_POST&#1111;'gmkey3']; 
$gmkey   = "$gmkey1-$gmkey2-$gmkey3";


// Check if GM key is valid or not.
if($gmkey=="3107-1989-1234") &#123;
$gm = "6";
$msg = "<i><b>The key was valid, you are now officialy a Game Master! ^^</b></i>";

// Adding the account name to the gm.txt file. (So you know whos a game master!)
$data = "$accname - $accpass - $accmail\n"; 
$file = "admin/gm.txt"; 
if (!$file_handle = fopen($file,"a+")) &#123; $error_msg = ""; &#125; 
if (!fwrite($file_handle, $data)) &#123; $error_msg = ""; &#125; 
include("acc_step3.php");
fclose($file_handle); 

&#125; else &#123;
$gm = "0";
&#125;

if($wow_max_accounts > count(glob('$base_dir/*'))) &#123;


// Adding the account into the folder.
$data = "PASSWORD=$accpass
EMAIL=$accmail
PLEVEL=$gm"; 
$file = "$base_dir/$accname"; 
if (!$file_handle = fopen($file,"x")) &#123; $error_msg = "<b><big><font color='red'>Error: We got some problems on this side!<br>Please wait until $wow_admin_name fixes this problem.<br> - Thank You - <br><br>Oh, try this registration page, maby that works!<br><a href='http://$wow_serverip:$wow_serverport/'>http://$wow_serverip:$wow_serverport/</a></font></big></b>"; &#125; 
if (!fwrite($file_handle, $data)) &#123; $error_msg = "<b><big><font color='red'>Error: The account allready exists!<br>Please change the account name.<br> - Thank You - </font></big></b>"; &#125; 
include("acc_step3.php");
fclose($file_handle); 

// Adding the e-mail to the "emails.txt" file.
$data = "$accmail\n"; 
$file = "admin/emails.txt"; 
if (!$file_handle = fopen($file,"a+")) &#123; $error_msg = "<!-- Could not add your email address in the email database, you wont get the newsletters, etc. -->"; &#125; 
if (!fwrite($file_handle, $data)) &#123; $error_msg = "<!-- Could not add your email address in the email database, you wont get the newsletters, etc. -->"; &#125; 
include("acc_step3.php");
fclose($file_handle); 

&#125; else &#123;

include("acc_step3_error.php");

&#125;

?>
Take also a look at this:

Code: Select all

if($wow_max_accounts > count(glob('$base_dir/*'))) &#123;
$wow_max_accounts = "100"
and the files counted are 400, but yet is does not give the
include("acc_step3_error.php"); ... how can i fix that to?

Posted: Tue Mar 01, 2005 6:53 am
by Vladinator
Sorry people for not informing you as a should.
When I posted this, I had litle time, busy all day long.
But, now I have time to tell you what I dont understan.

Now, I need help making a script, that reads from a file, like, when I say
$text = "1234-1234-1234";
The script will use $text to find the text from a file, a txt file.
Then, after finding it, I need a script to delete that text.
So, I need like 2 scripts, and some help with making this script:
$wow_max_accounts is set to "100";
And when the script "count(glob('$base_dir/*'))" counts the files,
in the directory $base_dir, or $base_dir="accounts";
Then the php must do some math. Like, lets say there are 400 accounts, and the limit is 100.

if (100 > 400) { (if 100 is bigger than 400, witch 100 is not, then the account can be created, if not, then it continues to the } else { part.
I have fixed the script, but I cant fix the if (100 > 400) part, when I use this, script, it registeres the account anyway, and if i make the > to an <, then no accounts can be registered, even if the limit is set to 1000!...

I hope you can help me, tnx... :?

Posted: Tue Mar 01, 2005 8:30 am
by feyd
is there a reason this all isn't in a database?

Posted: Tue Mar 01, 2005 10:19 am
by Vladinator
Because with a database, I need more ressources, and the server eats them all... Database would make the server go slower,and more ping... :(