|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
displaying info in text file after user login ?
hello all,
i was wondering if anyone can show me how to display the specific info in a text file after a user login ? the text file keeps the data of all users of my website the text file contains :- username|password|email|address|phone ps : i need a working example. Thanks |
|
#2
|
||||
|
||||
|
do u want do display info pertaining to the user who has logged in ??
or what ?? btw newuser, i think asking directly for example is not a good idea, i can give u the code but that way u will never learn. so rather try to do things urself, if u face problem we are ready to help . but not trying at all and asking solution from someone else is not a good idea. ![]() and if u still want code, reply back i post it in next reply, but that wouldnt be cool u know,best of luck, jd
__________________
_____________________________ d.k.jariwala (JD) ~ simple thought, simple act ~ I blog @ http://jdk.phpkid.org |
|
#3
|
|||
|
|||
|
please help with examples...
please help with examples...
i have been trying long to learn from book, etc. but please help. i am sure i can learn a little with examples with description of the code. THANKS |
|
#4
|
||||
|
||||
|
this is a perl code which is used to manipulate flat file database where record are | separated..
i use this for flat file manipulation. can u get some idea from this ?? see as u r willing to learn i am just putting up the code, there are lots of comments i think u should be able to grasp it, best of luck, jd Code:
#$database_file = "C:\\Program Files\\AbriaSoft\\Abria SQL\\Apache\\cgi-bin\\homepage\\database.db";
################################################################################
#
# Subroutine Used To Edit A Record In The Datafile
#
sub EditRecord
{
# Check To See If We Have A Database File To Work With
&CheckDataFile($database_file);
# Get The Record Key And Field Values
my ($key, @values) = @_;
# Create A Temporary Filename
my $tempfile_path = $database_file.".TMP";
# Initialize The Record Found Variable
my $found = 0;
# Setup The Record String With The Key As The Primary Value
my $record_string = $key;
# Add Each Of The Values To The Record String
foreach $value (@values) { $record_string .= "|$value"; }
# And Finish It Off With An End Of Line Character
$record_string .= "\n";
# Open The Current Database File And The Temporary One
open(OLD_DATA, "<$database_file") or die "Error";
open(NEW_DATA, ">$tempfile_path") or die "Error";
# Process Each Line Of The Current Database
while(<OLD_DATA>)
{
# Get The Key Of The Current Record
my ($temp_key, @temp_values) = split(/\|/, $_);
# If It Is The One We Want To Edit Then Write Out The
# New Record Otherwise Write Out The Current One
if($key == $temp_key) { print NEW_DATA $record_string; $found = 1; }
else { print NEW_DATA $_; }
}
# If We Didn't Find The Record Then Add It In
if(!$found) { print NEW_DATA $record_string; }
# Close The Files
close(OLD_DATA);
close(NEW_DATA);
# And Copy The Temporary One Over The Top Of The Old One
rename($tempfile_path, $database_file);
}
#
################################################################################
#
# Subroutine Used To Delete A Record In The Datafile
#
sub DeleteRecord
{
# Check To See If We Have A Database File To Work With
&CheckDataFile($database_file);
# Get The Record Key And Field Values
my ($key, @values) = @_;
# Create A Temporary Filename
my $tempfile_path = $database_file.".TMP";
# Open The Current Database File And The Temporary One
open(OLD_DATA, "<$database_file") or die "Error";
open(NEW_DATA, ">$tempfile_path") or die "Error";
# Process Each Line Of The Current Database
while(<OLD_DATA>)
{
# Get The Key Of The Current Record
my ($temp_key, @temp_values) = split(/\|/, $_);
# If It Is Not The One We Want To Delete Then Write It Out
if($key != $temp_key)
{
print NEW_DATA $_;
}
}
# Close The Files
close(OLD_DATA);
close(NEW_DATA);
# And Copy The Temporary One Over The Top Of The Old One
rename($tempfile_path, $database_file);
}
#
################################################################################
#
# Subroutine Used To Read A Record In The Datafile
#
sub ReadRecord
{
# Check To See If We Have A Database File To Work With
&CheckDataFile($database_file);
# Get The Record Key To Read
my ($key) = @_;
# Initialize The Record String Variable
my $record_string = "";
# Open The Current Database File
open(DATA, "<$database_file") or die "Error";
# Process Each Line Of The Current Database
while(<DATA>)
{
# Get Rid of Any Newline Characters
chomp($_);
# Get The Key Of The Current Record
my ($temp_key, @temp_values) = split(/\|/, $_);
# If It Is The One We Want Then Store The Record String And Leave
if($key == $temp_key)
{
$record_string = join("\|", $temp_key,@temp_values);
last;
}
}
# Close The File
close(DATA);
# Return The Record String
return $record_string;
}
################################################################################
################################################################################
#
# Subroutine Used To Check If A Datafile Exists And Create It If Necessary
#
sub CheckDataFile
{
# Get The Data File Name
chdir($scriptroot) or HandleError("Can not change to #scriptroot.",$!,"Make sure $scriptroot exits !!");
my ($data_file) = @_;
# Check To See If The File Exists
if(! -e $data_file)
{
# And If Not Then Create It
open(TEMP, ">$data_file") or HandleError("Can not open $data_file for writing.",$!,"Make sure enough permissions are there to create one.");;
close(TEMP);
}
}
#
#################################################################################
#################################################################################
# Stop The 'require' Complaining
1;
|
|
#5
|
||||
|
||||
|
hmm. No file locking? I wouldn't use that code on anything you care about. As soon as you got concurrent users, you're at a major risk if data corruption / destruction.
You didn't write that, did you jdk? |
|
#6
|
||||
|
||||
|
hi hero,
yeah no file locking.. btw i found this code from net and it is working for me satisfactorily... actually my application is such that it allows only one user to access it at a time, so i never needed it. btw i think i never considered this too, thx for pointing out, jd |
|
#7
|
|||
|
|||
|
thanks.
thanks.
haven't tried it yet. what about file locking. if my users are the surfers, i guess i need file locking. is it hard to implement file locking. would appreciate with example code. THANKS AGAIN ! |
|
#8
|
||||
|
||||
|
flock function is same as unix system command flock.
i think u would like to read man page for flock. its detailed and it should get u goin. in perl flock function is same as wat u can find flock on unix. hope it helps, jd |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > displaying info in text file after user login ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|