bizerk Posted February 16, 2007 Share Posted February 16, 2007 I have a script where if the user supplies the correct LOGIN NAME AND PASSWORD, that the user can upload images correctly, and if not it echos "Wrong credentials". I want to make it so there can be more than one username you can use, and more than one password. How can I make it so each user name has it's own password and there is more than one... I tried to do this: if($_POST['Submit']) { if($name =="example" or "example2"and $password =="pass123" or "pass456") { foreach ($_FILES as $key=>$file) { if (!empty($file['name'])) { uploadFiles($key); } } }else{ echo "Wrong Credentials, Please try to Login Again"; } } That usually works with my other script, but for this one it does not work... :/. Any tips? And how would I make it so that EXAMPLE username ONLY WORKS WITH pass123. I know I could just use mysql, but am lazy. :] Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/ Share on other sites More sharing options...
JBS103 Posted February 16, 2007 Share Posted February 16, 2007 You can try using a Switch function where you check the user name, and if it finds that the user name is correct, you can check the password. If you start using a lot of members, I definitely suggest start using a database though. Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186708 Share on other sites More sharing options...
bizerk Posted February 16, 2007 Author Share Posted February 16, 2007 So do that for Both usernames? so for like user: example. how would I implement that. I mean i know how but would that be possible with two users? Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186709 Share on other sites More sharing options...
sspoke Posted February 16, 2007 Share Posted February 16, 2007 well.. if($name =="example" or "example2"and $password =="pass123" or "pass456") could be if($name =="example" && $password =="pass123" || $name =="example2" && $password =="pass123") dunno?? but you could make it far more advanced with a function that returns True of match found or False if not and much eaiser to edit than if you put all names and passwords in a huge array If(functioncall($name,$pass)){ Goodpage }else{ badpage } functioncall($name,$pass){ $dfdsfds = array("example","password","example2","password2"); check array of names with password mix for($i=0; $i < count($dfdsfds); $i++ if($dfdsfds[i] == $name && $$dfdsfds[i+1] == $pass) return True; } return False; } ya.. something like that } Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186711 Share on other sites More sharing options...
JBS103 Posted February 16, 2007 Share Posted February 16, 2007 <?php $name = ... if($_POST['Submit']) { switch ($name) { case "username1": if($pass1 != "pass1") { //kill program - Not the correct password } break; case "username2": if($pass2 != "pass2") { //kill program - Not the correct password } break; default: echo "No user found"; //Kill program } //Finish the rest of the coding here } ?> I think this will work. I am unsure as to the efficiency and safety. Thats a question for someone more experienced. You could just use two different if statements, or combine them into one if() statement. Research your options in the manual. If it grows beyond two users, I would suggest using something like the switch. Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186713 Share on other sites More sharing options...
bizerk Posted February 16, 2007 Author Share Posted February 16, 2007 Yeah sspoke, that worked perfectly. This got me wondering though. Is there anyway that I can clear a page using php? or Would I have to make it go to another page... I was wondering now that I can make an admin account, that like I could make it so if a user logged in as ADMIN, they could delete all files or something which i have already made the unlink script for. Anyway thats possible? Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186716 Share on other sites More sharing options...
sspoke Posted February 16, 2007 Share Posted February 16, 2007 I dont think you can clear a page but you can make your full admin page from 1 page no need to redirect to more pages just filter out the $_POST data.. like if you want to add a file if($_POST['Add']){ echo "the page for adding files"; } elseif($_POST['deletefiles']){ echo "the page for deleting files"; } else { echo "unknown page some error maybe"; } Ya its like this in the packets.. thatonepage.php?Add thatonepage.php?deletefiles but thats a GET method $_GET[] POST is invisble to browsers you can always use a include header and footer for the page of the page you want to always to show for design or links w/e I could make it so if a user logged in as ADMIN, they could delete all files or something which i have already made the unlink script just brach your logged in if statement.. like <?php $name = $_POST['usernamedata']; $pass = $_POST['passworddata']; If(functioncall($name,$pass)){ if($_POST['Add']){ echo "the page for adding files"; //ADD here Your Adding files full script } elseif($_POST['deletefiles']){ echo "the page for deleting files"; // ADD here your unlink script } else { echo "unknown page some error maybe"; } } ?> but that would require the user to put in username/password every time he refreshes page you have to use sessions and cookies its really hard to explain well not hard but its long just download some working login/ cms script and modd it how you like it thats what I always do. Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186718 Share on other sites More sharing options...
marcus Posted February 17, 2007 Share Posted February 17, 2007 If you're going to do a function w/ both a username and password you want to do something like: login($username,$password){ $una = array('example','example2'); $pwa = array('password','password2'); if(in_array($username,$una) && in_array($password,$pwa)){ //good page here }else { //bad page here } } //then call the function $un = $_POST['username']; $pw = $_POST['password']; login($un,$pw); Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186721 Share on other sites More sharing options...
bizerk Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks a lot sspoke for all that information, really really helpful. Link to comment https://forums.phpfreaks.com/topic/38836-solved-multiple-login-names-and-passwords/#findComment-186736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.