Jump to content

Help with client login


lookinfreshuk

Recommended Posts

hello,

 

i want to create a client login system so when they use there login it redirects them to a page only for them, is this possible? i am using the following code but it only re-drirects them after login to the "index.php" page not the 2nd user to "Harts.php", what am i doing wrong?, thanks

 

<?php

$usernames = array("admin","admin2");

$passwords = array("admin","admin2");

$page = array("index.php","Harts.php");

 

for($i=0;$i<count($usernames);$i++)

{

  $logindata[$usernames[$i]]=$passwords[$i];

}

 

$found = 0;

for($i=0;$i<count($usernames);$i++)

{

  if ($usernames[$i] == $_POST["username"])

  {

  $found = 1;

  }

}

if ($found == 0)

{

  header('Location: login.php?value=fail');

  exit;

}

 

if($logindata[$_POST["username"]]==$_POST["password"])

{

  session_start();

  $_SESSION["username"]=$_POST["username"];

  header('Location: '.$page);

  exit;

}

else

{

  header('Location: login.php?value=fail');

  exit;

}

?>

 

Link to comment
Share on other sites

Hey LookinfreshUK, try the following in place of your current code.

 

<?PHP
  $usernames = array('admin','admin2');
  $passwords = array('admin','admin2');
  $page      = array('index.php','Harts.php');
  
  // Count the amount of users in array.
  $count_users = count($usernames);

  // Set users found to "0".
  $user_found  = '0';

  // Set username and password variables from $_POST data.
  $username = $_POST['username'];
  $password = $_POST['password'];

  // Check to see if we have a match in usernames
  // If we have a match set a variable with the record number
  // Update "$user_found" if we find a match
  for($u=0; $u<$count_users; $u++) {
    if($username == $usernames[$u]) { 
      $userRecord = $u; 
      $user_found = '1';
    }
  }

  // If no user is found, login has failed. Re-direct back to login.
  if(!$user_found) { 
   header('Location: login.php?value=fail');
   exit;
  }

  // If usernames don't match, login has failed. Re-direct back to login.
  if($usernames[$userRecord] != $username) {
   header('Location: login.php?value=fail');
   exit;

  // If passwords don't match, login has failed. Re-direct back to login.
  } else if($passwords[$userRecord] != $password) {
   header('Location: login.php?value=fail');
   exit;

  // If usernames and passwords match, login succeeded. Re-directed to player specific page.
  } else {
   $_SESSION['username'] = $username;
   header("Location: $page[$userRecord]");
   exit;
  }
?>

 

Tell me if it works or not bud :)

 

Regards, Paul.

Link to comment
Share on other sites

NEW CODE AS YOU PUT ^^

 

<?PHP
$usernames = array('admin','harts');
$passwords = array('admin','harts');
$page = array('index.php','Harts.php');

// Count the amount of users in array.
$count_users = count ($usernames);

// Set users found to "0"
$user_found = '0';

// Set username and password variables from $_POST data.
$username = $_POST['username'];
$password = $_POST['password'];

// Check to see if we gave a match in usernames
// If we have a match set a cariable with the record number
// Update "$user_found" if we find a match
for($u=0; $u<$count_users; $u++) {
if($username == $usernames[$u]) {
	$userRecord = $u;
	$user_found = '1';

}
}

// If no user is found, login has failed. Re-direct back to login.
if(!$user_found) {
header('Location: login.php?value=fail');
exit;
}

// If usernames don't match, login has failed. Re-direct back to login.
if($usernames[$userRecord] !=$username) {
header('Location: login.php?value=fail');
exit;

// If passwords don't match, login has faled. Re-direct back to login.
} else if($passwords[$userRecord] !=$password) {
header('Location: login.php?vale=fail');
exit;

// If usernames and passwords match, login succeeded. Re-direct to player specific page.
} else {
$_SESSION['username'] = $username;
header("Location: $page[$userRecord]");
exit;
}
?>

 

wont even allow the login, it wont move page, just says login failed... :S

 

thanks for the try tho!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.