[FONT=Verdana]I have a login page on my site – at the moment it only allows one user to log in, i now require it to allow multiple users to log on.
I would like it to redirect the users to different pages and with different session ID’s.
Here’s the code i have:
On the login page:-
[code=php]<?php
// start the session
session_start();
$errorMessage = ”;
if (isset($_POST[‘username’]) && isset($_POST[‘password’])) {
// check if the username and password combination is correct
if ($_POST[‘username’] === ‘theuser’ && $_POST[‘password’] === ‘thepass’) {
// the username and password match,
// set the session
$_SESSION[‘bcmd’] = true;
// after login we move to the main page
header(‘Location: bcmdtextedit.php’);
exit;
} else {
$errorMessage = ‘Incorrect Username/Password’;
}
}
?>
On the logout php file:-
[code=php]<?php
// start the session
session_start();
// if the user is logged in, unset the session
if (isset($_SESSION[‘bcmd’])) {
unset($_SESSION[‘bcmd’]);
}
// now that the user is logged out,
// go to login page
header(‘Location: index.html’);
?>
Any ideas anyone???
Thanks Chris.[/FONT]
[code=php]
<?php
// start the session
session_start();
$errorMessage = '';
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ($_POST['username'] == 'theuser1' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser2' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser3' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser4' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser5' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser6' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser7' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser8' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser9' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser10' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser11' && $_POST['password'] == 'thepass' ) {
// the username and password match,
// set the session
$_SESSION['bcmd'] = true;
// after login we move to the main page
header('Location: {$_POST['username']}.php'); //will direct the user to a page names as their username
exit;
} else {
$errorMessage = 'Incorrect Username/Password';
}
}
?>[/code]
[code=php]<?php
// start the session
session_start();
$errorMessage = '';
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ($_POST['username'] == 'theuser1' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser2' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser3' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser4' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser5' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser6' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser7' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser8' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser9' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser10' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser11' && $_POST['password'] == 'thepass' ) {
// the username and password match,
// set the session
$_SESSION['{$_POST['username']}'] = true;
// after login we move to the main page
header('Location: {$_POST['username']}.php'); //will direct the user to a page names as their username
exit;
} else {
$errorMessage = 'Incorrect Username/Password';
}
}
?>[/code]
[code=php]
<?php
// start the session
session_start();
$errorMessage = 'Incorrect Username/Password';
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ($_POST['username'] == 'theuser1' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser2' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser3' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser4' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser5' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser6' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser7' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser8' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser9' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser10' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser11' && $_POST['password'] == 'thepass' ) {
// the username and password match,
// set the session
$user_name = $_POST['username'];
$_SESSION['true'] = $user_name;
// after login we move to the main page
header('Location: {$user_name}.php'); //will direct the user to a page names as their username
exit;
} else {
echo $errorMessage."<br/>".$_SESSION['true']."could have been wrong";
}
}
?>[/code]
[code=php]<?php
// start the session
session_start();
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ( $_POST['username'] == 'theuser1' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser2' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser3' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser4' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser5' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser6' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser7' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser8' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser9' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser10' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser11' && $_POST['password'] == 'thepass' ) {
// the username and password match,
// set the session
$user_name = $_POST['username'];
$_SESSION['true'] = $user_name;
// after login we move to the main page
header('Location: {$user_name}.php'); //will direct the user to a page names as their username
exit;
} else {
}
}
?>[/code]
[CODE]
<?php
// Store your usernames and passwords in this array. Username first, then the password.
$users = array(
0 =>
array("user1","password1"),
1 =>
array("user2","password2"),
2 =>
array("user3","password3"),
);
for($i=0; $i < count($users); $i++){ // Run through the array to
if($_POST['username'] == $users[$i][0]){ // see if username is present. If it is,
if($_POST['password'] == $users[$i][1]){ // check if the password is correct
echo "Welcome ".$users[$i][0].". You are granted access!"; //Do whatever you want to do here, when user is logged in
}else{
echo "You need to log in to see the page."; // Kick the unauthorized user out.
}
}
}
?>
[/CODE]
[code=php]
header('Location: '.$user_name.'.php');
[/code]
[code=php]<?php
// start the session
session_start();
// is the one accessing this page logged in or not?
if (!isset($_SESSION['scsu']) || $_SESSION['scsu'] !== true) {
// not logged in, move to login page
header('Location: loginpage.php);
exit;
}
?> [/code]
[code=php]<?php
// start the session
session_start();
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ( $_POST['username'] == 'bcmd' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'scsu' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser3' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser4' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser5' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser6' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser7' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser8' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser9' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser10' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser11' && $_POST['password'] == 'thepass' ) {
// the username and password match,
// set the session
$user_name = $_POST['username'];
$_SESSION['true'] = $user_name;
// after login we move to the main page
header('Location: '.$user_name.'.php'); //will direct the user to a page names as their username
exit;
} else {
}
}
?>[/code]
[code=php]
$_SESSION['true'] = $user_name;
[/code]
[code=php]if (!isset($_SESSION['scsu']) || $_SESSION['scsu'] !== true) {[/code]
[code=php]
if ($_SESSION['true'] == 'scsu'){
[/code]
[code=php]if ($_SESSION['true'] == 'scsu'){[/code]
[code=php]
<?php
// start the session
session_start();
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ( $_POST['username'] == 'bcmd' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'scsu' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser3' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser4' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser5' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser6' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser7' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser8' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser9' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser10' && $_POST['password'] == 'thepass' ||
$_POST['username'] == 'theuser11' && $_POST['password'] == 'thepass' ) {
// the username and password match,
// set the session
$user_name = $_POST['username'];
$_SESSION['true'] = $user_name;
$_SESSION['logged_in'] = "1";
// after login we move to the main page
header('Location: '.$user_name.'.php'); //will direct the user to a page names as their username
exit;
} else {
}
}
?>
[/code]
[code=php]
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == "1") {
//do nothing
}else{
header("Location: loginpage.php");
}
[/code]
Not sure could you explain?
Thanks Chris....[/QUOTE]
[code=php]<?php
// start the session
session_start();
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ( $_POST['username'] == 'bcmd' && $_POST['password'] == 'bcmdadmin' ||
$_POST['username'] == 'scsu' && $_POST['password'] == 'scsuadmin' ||
$_POST['username'] == 'catadmin' && $_POST['password'] == 'lol222' ) {
// the username and password match,
// set the session
$user_name = $_POST['username'];
$_SESSION['ADMIN'] = $user_name;
// after login we move to the main page
header('Location: '.$user_name.'.php'); //will direct the user to a page names as their username
exit;
} else {
}
}
?>[/code]
[code=php]<?php
// start the session
session_start();
// if the user is logged in, unset the session
if (isset($_SESSION['ADMIN'])) {
unset($_SESSION['ADMIN']);
}
// now that the user is logged out,
// go to login page
header('Location: logoutsuccess.php');
?>[/code]
[code=php]<?php
// start the session
session_start();
if (isset($_POST['username']) && isset($_POST['password'])) {
// check if the username and password combination is correct
if ( $_POST['username'] == 'bcmd' && $_POST['password'] == 'bcmdadmin' ||
$_POST['username'] == 'scsu' && $_POST['password'] == 'scsuadmin' ||
$_POST['username'] == 'catadmin' && $_POST['password'] == 'lol222' ) {
// the username and password match,
// set the session
$user_name = $_POST['username'];
$_SESSION['ADMIN'] = '$user_name';
// after login we move to the main page
header('Location: '.$user_name.'.php'); //will direct the user to a page names as their username
exit;
} else {
}
}
?>[/code]
0.1.9 — BETA 5.27