/    Sign up×
Community /Pin to ProfileBookmark

Login script/ arrays for names and pswords

Would it be possible to make 2 arrays so that i could check if a name and password match?

By this i mean having one array holding the names, for example foo and bar

and then the second array holding ex1 example2

and then sum1 puts foo as the name and ex1 as the password, id check to see if the they matched each other then what i wanted to happen could happen?

also, could it draw the names from a .txt file?

sorry if i was unclear. if this requires excessive work, nevermind, im just making the script for sumtin i may or may not do.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 08.2004 — [font=arial]You'd set up your two arrays, first.[/font]

[code=php]
$users = array("Jon","Darryn","Pamela","Anne");
$passwords = array("kluck","eggs","pants","wine");
[/code]


[font=arial]Then you can loop through them to see if the inputted ones are correct. Assuming you've already set variables to the $_POST formdata values...[/font]

[code=php]
for($u=0; $u<count($users); $u++)
{
if($username == $user[$u] && $password == $passwords[$u]){
# user/pass correct
} else {
# user/pass incorrect
}
}
[/code]


[font=arial]To write to a file, you must first open it ([url=http://php.net/fopen]fopen()[/url]), then select what you want to do with it--append ('a'), append and read ('a+'), read ('r'), read and write ('r+'), write ('w'), or write and read ('w+'). After you decide that, you can manipulate it with functions such as [url=http://php.net/fread]fread()[/url] and [url=http://php.net/fwrite]fwrite()[/url]. Be sure to close it with [url=http://php.net/fclose]fclose()[/url] when you're done![/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@Ben_RogersauthorMar 09.2004 — Thanks, Jona. So that's how to do arrays... when I tried to learn them php.net ranted on about key values and I was lost.

Much thanks.
Copy linkTweet thisAlerts:
@JonaMar 09.2004 — [font=arial]Happy to help![/font]

[b][J]ona[/b]
×

Success!

Help @Ben_Rogers 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.1,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...