Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 User Login
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JHanson90




PostPosted: Mon May 31, 2004 12:10 pm   Post subject: User Login

I'm making a site with user login but not with a MySQL database. I'm just using sessions. How do I make it so that an if statement accepts different users? Because right now it's like
code:
if($HTTP_SESSION_VARS['username'] == $webmaster['username'] && $HTTP_SESSION_VARS['password'] == $webmaster['password']) { include('membersarea.php'); } else { include('error.php'); }
but I want it so that it will also accept other usernames and passwords, like instead of just being if session username == webmaster's username and session password == webmaster's password, I want it so that it could be like if session username == webmaster's username, friend's username, or some other Joe Schmoe's username and session password == webmaster's password, friend's password, or some other Joe Schmoe's password then include membersarea.php

Get what I mean?

But I don't want to use an elseif for every single user. THen I'd have to include the same file for every single user. TOo much work Sad
Sponsor
Sponsor
Sponsor
sponsor
PaddyLong




PostPosted: Tue Jun 01, 2004 5:32 pm   Post subject: (No subject)

easiest would probably be to have all your logins and passwords in an array
code:

users[0]="webmaster";
pass[0]="webmaster's password";
users[1]="friend";
pass[1]="friend's password";


and then use a for loop of some sort to check each...

code:

$loggedin=false;
for ($i = 0; $i < 2; $i++)
{
     if($HTTP_SESSION_VARS['username'] == $users[$i] && $HTTP_SESSION_VARS['password'] == $pass[$i]) { $loggedin = true; }
}
if($loggedin) { include('membersarea.php'); } else {include('error.php'); }
Homer_simpson




PostPosted: Wed Jun 02, 2004 8:50 am   Post subject: (No subject)

it's easier if you just query this to your database and send username and password(encrypted) in pages in sessions : "Select * from users WHERE username='"$_SESSION['username']"'";
Blade




PostPosted: Wed Jun 02, 2004 2:58 pm   Post subject: Re: User Login

JHanson90 wrote:
I'm making a site with user login but not with a MySQL database. I'm just using sessions. ...


he clearly said he is not using a database...
JHanson90




PostPosted: Wed Jun 02, 2004 4:23 pm   Post subject: (No subject)

I'm really pissed! I worked for hours trying to set it up so that the multiple user login works, using PaddyLong's post. I eventually got it working for me. Then I told my friend to login, and it didn't work for him *anger/frustration level gets a little higher*. So I keep thinking "how?" then I get the idea to try it on Internet Explorer, instead of Mozilla, what I was using. Guess what? It doesn't work on Internet Explorer. So how the heck am I supposed to change the coding around so it works on both???????!!!!!!!!!
PaddyLong




PostPosted: Wed Jun 02, 2004 10:48 pm   Post subject: (No subject)

uhh PHP is server side and browser shouldn't make a difference ... unless there's something screwy with your session

that code was mostly just to use as a guide... although it probably should work (you would of course have to put the $ in front of your user and password declarations though)
Blade




PostPosted: Thu Jun 03, 2004 5:25 pm   Post subject: (No subject)

i dont really know how you are trying to do this... you dont show very much source or anything.

you should really try a basic login program because sessions are only really used to move from page to page and have different features appear on each page (as if you were logged in) and transfer variables and such...
JHanson90




PostPosted: Fri Jun 04, 2004 3:08 pm   Post subject: (No subject)

I got the problem fixed. For some reason Mozilla wasnt killing the sessions when I closed the browser, or something like that, and it kept keeping me logged in. But with help from Amailer, I got it all fixed up.

But what do you mean by a basic login program?
Sponsor
Sponsor
Sponsor
sponsor
Blade




PostPosted: Fri Jun 04, 2004 11:08 pm   Post subject: (No subject)

uhm.. basic login... i mean with a form to send the vars, and an array to compare to. use an if statement to check to see if they username/pass is in the arrays, if it is display something, if not then display something different...

i use it all the time to problem solve... basically cutting out shit that you think could be causing the problem
octopi




PostPosted: Sat Jun 05, 2004 9:56 am   Post subject: (No subject)

Or letting your webserver handle it all via htaccess/htpasswd works well...you can get the username that the user is logged in as threw REMOTE_USER variable, and apache handles these simple sessions way better then php does.
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: