jacko310592 Posted January 22, 2010 Share Posted January 22, 2010 hey guys, the following code is supposed to set a cookie once a matching user name and password has been entered (from array), but it doesn’t currently recognise a matching set: <?php $userName = $_POST['name']; $password = $_POST['pass']; $userInfo = array('user1'=>'pass1', 'user2'=>'pass2'); $randomString1 = "xu5rac9Erub7KAPh"; $randomString2 = "P327efA5ujadRAfa"; if (isset($_POST['submit'])){ if (in_array($userName, $userInfo) && $password == $userInfo[$userName]) { setcookie('MyLoginPage', md5($randomString1.$_POST['pass'].$randomString2)); header("Location: ./"); exit; } else { echo "<p>Sorry, you could not be logged in at this time. Refresh the page and try again.</p>"; } } echo '<form action="#" method="post"><fieldset> <legend>Admin Login</legend> <label><input type="text" name="name" id="name" /> Name</label><br /> <label><input type="password" name="pass" id="pass" /> Password</label><br /> <input type="submit" name="submit" id="submit" value="Login" /> </fieldset></form>'; ?> can anyone help with this? thanks Link to comment https://forums.phpfreaks.com/topic/189471-help-with-simple-login-page/ Share on other sites More sharing options...
jacko310592 Posted January 22, 2010 Author Share Posted January 22, 2010 got it working, realised i didnt need "in_array($userName, $userInfo) && " so now its just if ($password == $userInfo[$userName]) { setcookie('MyLoginPage', md5($randomString1.$_POST['pass'].$randomString2)); header("Location: ./"); exit; } Link to comment https://forums.phpfreaks.com/topic/189471-help-with-simple-login-page/#findComment-1000119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.