Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-28-2005, 01:22 AM   PM User | #1
simmax
New Coder

 
Join Date: Jun 2003
Location: Greece
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
simmax is an unknown quantity at this point
Question Help with PHP script that would read & delete a row from txt or csv file

Hello,

I would need some help with a small problem.
I need to have a php script that would read a row from a txt file or csv file then display in an html file a random string and after it display this, it would delete it from the txt or csv file. I would like to use it to deliver pre-selected serial numbers and or usernames and passwords. i.e:

username,password,serial
nick,12345,12345678
john,45678,12347890
jack,1211212,1811212

after the script deliver the first row
nick,12345,12345678

it will delete it from the file so that it won't show up again to someone else.

Thanks for your time in advance
James
__________________
Software is like sex. It's better when it's FREE!!!
simmax is offline   Reply With Quote
Old 05-28-2005, 10:34 AM   PM User | #2
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
I don't know if there's a specific function within PHP to do what you want, I never found one but here's part of a little script I wrote to handle something similar. I've modified it so it should work with your text file (it would need changing to work with a csv file but for text files in the format name,password,serial<newline>name,password,serial<newline> etc it should work fine).

Instead of phsyically deleting a line from the file it reads the whole file into an array, breaks that array down into separate user details, displays and deletes the first user's details then puts the remaining details back into the file. Not the most efficient method, but it works

names.txt
Code:
nick,12345,12345678
john,45678,12347890
jack,1211212,1811212
script
PHP Code:
<?php

$handle 
= @fopen("names.txt""r") or die('File does not exist or could not be opened.');

while (!
feof($handle)) {
   
$names[] = fgets($handle); 
}

fclose($handle);

for(
$i=0$i count($names); $i++) {
    
$tmp explode(','$names[$i]);
    
$details[$i]['name'] = $tmp[0];
    
$details[$i]['password'] = $tmp[1];
    
$details[$i]['serial'] = $tmp[2];
}

echo 
'Username: ' $details[0]['name'] . "<br />\n";
echo 
'Password: ' $details[0]['password'] . "<br />\n";
echo 
'Serial: ' $details[0]['serial'] . "<br />\n";

array_shift($details);

unset(
$names);
for(
$i=0$i count($details); $i++) {
    
$names[$i] = implode(','$details[$i]);
}

$handle = @fopen("names.txt""w");
for(
$i=0$i count($names); $i++) {
    
fwrite($handle$names[$i]);
}
fclose($handle);

?>
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 05-28-2005, 10:45 AM   PM User | #3
simmax
New Coder

 
Join Date: Jun 2003
Location: Greece
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
simmax is an unknown quantity at this point
Thanks a lot. I have come up to this as well:

<?php
$file = file("serials.txt");

list($user, $pass, $serial) = explode(",", $file[0]);

$fp = fopen("serials.txt", "w+");
for($i = 1; $i < sizeof($file); ++$i) {
fwrite($fp, trim($file[$i]) . "\n");
}
fclose($fp);

echo "Your username is: $user. Your password is: $pass. Your serial is: $serial";
?>

This works fine also.

Thanks for your time. I appreciate your help.
Regards
James
__________________
Software is like sex. It's better when it's FREE!!!
simmax is offline   Reply With Quote
Old 05-28-2005, 10:48 AM   PM User | #4
simmax
New Coder

 
Join Date: Jun 2003
Location: Greece
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
simmax is an unknown quantity at this point
If I'm not giving too much trouble I would like to ask some more help about something else:

I would like to have a php script to run only if someone have the serial username and password. But this I would like to include them in a config.php file. So if the user insert these values in the config.php file then the script will run. But I don't want to use MySQL.

So let's say I have the script horoscope.php and the database.php file with the pre defined serials and usernames on another server or the same server in order for the horoscope.php file to run it must find the config.php file and the username,password, serial, must be correct against the database.php file. If not then the horoscope.php file must not run.
It has to be as simple as possible. Security is not an issue.

(the scripts will all be locked by codelock software that I have so the usernames will not show by users, or the database.php will be on an other server).

If the above is easy please help. If it takes to much time, I'll understand.

Any way thanks again in advance for your time and help.

James
__________________
Software is like sex. It's better when it's FREE!!!
simmax is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:37 AM.


Advertisement
Log in to turn off these ads.