Page 1 of 1

Open file based on user input - what's the best way?

Posted: Wed May 28, 2008 11:09 am
by javafool
Scenario:

A user has a 6 digit number (ex: 123456) and I know the user's name is Bob. 2 other users have numbers (ex: Mary - 552233 and Ron - 987654). I want the user to enter his first name and number to open a web page. There are only going to be 3 users and each should have a unique static page based upon their number and name. Since the number of users is small, I don't want to use a database. I was thinking either inline PHP logic or an external file to store the user's name and number. If someone doesn't know the name and number, they should be presented the "login" page again.

What is the best quick and dirty way to do this? It doesn't have to be pretty. Your suggestions or examples would be greatly appreciated.

Re: Open file based on user input - what's the best way?

Posted: Wed May 28, 2008 11:26 am
by panic!
Hi,

Welcome to the forum,

Code: Select all

SEE BELOW

try that, dont have time to actually run/test it but give it a go.

Re: Open file based on user input - what's the best way?

Posted: Wed May 28, 2008 11:31 am
by panic!
actually try:

Code: Select all

<?
 
 
if($_POST['username'])
{
$users['Mary']='552233';
$users['Ron']='987654';
$users['Bob']='12345';
 
$file['Mary']='mary.html';
$file['Ron']='Ron.html';
$file['Bob']='Bob.html';
 
 if($users[$_POST['username']]==$_POST['pincode'])
{
print "SUCCESS";
print file_get_contents($file[$_POST['username']]);
die();
}
 
}
 
?>
<form method="post">
<input name="username"> <input name="pincode"> <input type="submit">
</form>

Re: Open file based on user input - what's the best way?

Posted: Wed May 28, 2008 11:54 am
by javafool
Panic,

Very cool! I'll play around with this tonight.

Next I'll try to figure out how to move the users to a flat file and see if I can make that work. I know it would be easier to create a MySQL table to store the info in and retrieve it but I want to make something portable. If this was something that would be utilized a lot, that would be the way to go for ease of administration, as well as speed.

Thanks again!

Re: Open file based on user input - what's the best way?

Posted: Wed May 28, 2008 1:16 pm
by javafool
Quick follow-up question. Using this example, what is the best way to force the username to be all lower case? Should be as simple as running the username through strtolower, right?

Thanks for both your assistance and being patient with a newb!

Re: Open file based on user input - what's the best way?

Posted: Wed May 28, 2008 3:18 pm
by panic!
replace

if($users[$_POST['username']]==$_POST['pincode'])

with

if($users[strtolower($_POST['username'])]==$_POST['pincode'])

no problems.