pawertiger Posted November 7, 2012 Share Posted November 7, 2012 So I found this code from a website to use as a login, but it can only allow one user right now with the code given. Anyone know how to add multiple users? First code (where the usernames and passwords for users are) <?php define("ADMINUSER", "adf"); define("ADMINPASSWORD", "adf"); define("ADMINHOME", "index.php"); ?> 2nd code Code after clicking submit on login <?php session_start(); include("sec.php"); if (($user==ADMINUSER) && ($pass==ADMINPASSWORD)) { $_SESSION['myuser'] = "jd"; header("Location: welcome.php"); } else { header("Location: auth.php?flag=wrong"); } ?> 3rd code Login one with the username and password input <?php session_start(); //This script (PHP Login Without MySql v1.2) //was designed by Aarmale. If you like this //script, comment at the SourceForge page!! //------------------------------------- require 'include.php';// change variables such as username and pass @ include.php!!!!! //------------------------------------- // if the submit button is pressed or the SESSION named login exists... if (isset($_POST['submit']) || isset($_SESSION['login'])) { // if the SESSION exists... (this is here if the submit button is pressed) if (isset($_SESSION['login'])) { // if the SESSION equls the MD5 hash... if ($_SESSION['login'] == $hash) { //say your info! echo " <p align=center> <font size=4>Logged In!</font> </p><p align=left> <a href=logout.php>Logout. Note, this may not work. Exit browser/clear cookies to log out.</a><BR><BR></p>"; } else { //if the SESSION exists, but does not equal the hash say... echo "Bad SESSION. Clear them out and try again."; } } else { //info // if the submit button is pressed, but the SESSION dose not exist, go through these steps... if ($_POST['user'] == $user && $_POST['pass'] == $pass){ //user = your username & password = your password. acess granted. add SESSIONs and refresh. $_SESSION["login"] = $hash; header("Location: $_SERVER[php_SELF]"); } else { echo "incorrect user/pass"; } } } else { //if none of the if/else statemants happen, show the login form... print "<form action="; echo "$self "; print "method=post>Login<fieldset><BR>Username: <input type=text name=user><BR> Password: <input type=password name=pass><BR><input type=submit name=submit value=submit></fieldset></form>"; } ?> <br/> <br/><br/> <?php if ($ads == TRUE) { //if you set ads on (in includes.php) insert code below... ?> <!-- Start ads code--> <script type="text/javascript"> google_ad_client = "pub-<?php echo "$pub_code" ?>"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text"; google_color_border = "FFFFFF"; google_color_bg = "FFFFCC"; google_color_link = "C3D9FF"; google_color_text = "000000"; google_color_url = "008000"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> <?php } else { } ?> Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/270436-help-adding-users/ Share on other sites More sharing options...
pawertiger Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) Wow I copied the wrong codes...... Please view code from here. Sorry. Login page: <head> <style type="text/css"> <!-- body { font: 10px Verdana, Arial, Helvetica, sans-serif; text-decoration: none; } td { font: 10px Verdana, Arial, Helvetica, sans-serif; text-decoration: none; } --> </style> </head> <body> <form method="post" name="auth" action="success.php"> <table width="400" border="0" cellspacing="4" cellpadding="0"> <tr> <td width="150" align="right">User Name: </td> <td><input name="user" type="text" id="user"></td> </tr> <tr> <td width="150" align="right">Password: </td> <td><input name="pass" type="password" id="pass"></td> </tr> <tr> <td width="150" align="right"> </td> <td><input type="reset" name="Submit2" value="Clear"> <input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> <br> <table width="400" border="0" cellspacing="4" cellpadding="0"> <tr> <td align="center"><? if ($flag==wrong) { echo "Invalid User Name or Password"; } ?> <? if ($flag==out) { echo "Logged Out"; } ?></td> </tr> </table> </body> Code 2: Users <?php define("ADMINUSER", "tno"); define("ADMINPASSWORD", "tno"); define("ADMINHOME", "index.php"); ?> Code 3: When someone clicks the submit from the first code <?php session_start(); include("sec.php"); if (($user==ADMINUSER) && ($pass==ADMINPASSWORD)) { $_SESSION['myuser'] = "jd"; header("Location: welcome.php"); } else { header("Location: auth.php?flag=wrong"); } ?> Edited November 7, 2012 by pawertiger Quote Link to comment https://forums.phpfreaks.com/topic/270436-help-adding-users/#findComment-1390958 Share on other sites More sharing options...
pawertiger Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) Deleting post. Edited November 7, 2012 by pawertiger Quote Link to comment https://forums.phpfreaks.com/topic/270436-help-adding-users/#findComment-1390959 Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2012 Share Posted November 8, 2012 You would use an array with the array key/index being the username and the value being the password. $admin['user_name_1'] = 'password_1'; $admin['user_name_2'] = 'password_2'; The logic test would then become - if(isset($admin[$user]) && $pass==$admin[$user]) Quote Link to comment https://forums.phpfreaks.com/topic/270436-help-adding-users/#findComment-1390983 Share on other sites More sharing options...
pawertiger Posted November 9, 2012 Author Share Posted November 9, 2012 It worked, many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/270436-help-adding-users/#findComment-1391204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.