/    Sign up×
Community /Pin to ProfileBookmark

flatfile/text databases

Hi guys. I know this is an easy thing to achieve, but I have absolutely no idea which of the many file and db functions I need to use to perform the task.

All I need to be able to do is get the username (who is already logged in and the $_SERVER[PHP_AUTH_USER] variable works fine).

Once I’ve got the username, I want to open a text database file (file.db), locate the row that contains the username in the third column/field and return that row’s email address in field 2 to be saved to a variable.

The database file is actually generated by a cgi member’s script and it uses the pipe | character as the separator and physical line breaks as the line end.

A nice simple solution would really make my day ? or night ?

Thanks.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@simpson97Mar 20.2004 — Maybe this might help:

It is untested but should work

PHP:

<?php

$username = 'john doe';

$db_array = file('your_db_name.ext');

for($i = 0; $i < count($db_array); $i++)

{

$line = $db_array[$i];

$lineArr = explode("|", $line);

if($username == $lineArr[3])

{

$email = $lineArr[2];

break;

}

}

?>

Bob
Copy linkTweet thisAlerts:
@tiggerificauthorMar 20.2004 — a little bit of code reshuffling and I got it working ?

Thanks very much for your help.
×

Success!

Help @tiggerific spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...