Jump to content

help with simple login page


jacko310592

Recommended Posts

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

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;
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.