override Posted March 5, 2009 Report Posted March 5, 2009 can some one tell me what i am doing wrong with this code config.php <?php $username = array('Admin', 'User'); $password = array('adminpass', 'userpass'); ?> index.php <?php require ("config.php"); session_start(); if ((!$username) || (!$password)) { echo '<form name=login method=post action=""> user:<input type=text name=user><br> pass:<input type=text name=pass><br> <input type=submit value=go> </form>'; } else { if($user==$username && $pass==$password) { session_register("username"); session_register("password"); echo "Congratulations &username, you have logged in!<br> <a href=\"?logout=1\" >Logout</a>"; } else echo "Incorrect Password please <a href=?index.php?>try again</a>"; } if($logout==1) { session_unregister("username"); session_unregister("password"); } ?> Quote if you like this Uniform Server User Sing take em i do not mind share
Ric Posted March 6, 2009 Report Posted March 6, 2009 There are a few things wrong, the following gives you a clue what you need to do:<?php require ("config.php"); // load in array (name and password values) session_start(); $userin = $_POST['user']; // get from poat $passin = $_POST['pass']; // get from post if ( !isset($userin) || !isset($passin)) // chect not set { ?> <form name="login" method="post" action="index.php"> Name: <input type="text" name="user" ><br> Pass: <input type="password" name="pass" ><br> <input type="submit" value="go"> </form> <? } else //both are set, check for correct values { // scan each array for a match using in_array function if( in_array($userin, $username) && in_array($passin, $password)) { session_register("$userin"); session_register("$passin"); echo "Congratulations $userin, you have logged in!<br> <a href=\"?logout=1\" >Logout</a>"; } else // failed to match echo "Incorrect Name or Password please <a href=?index.php?>try again</a>"; } if($logout==1) { session_unregister("$userin"); session_unregister("$passin"); } ?> All the bestRic Quote
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.