This code right here;
PHP Code:
<?php
// Session start
session_start();
// Checks password and username
if($username == "test" AND $password == "1337") {
// Session userid and loggedin is true
$_SESSION[username] = "test";
$_SESSION[userid] = 1;
$_SESSION[loggedin] = 1;
echo "<font face='verdana' size='1'>You are now logged in as 'test'</font>";
} else {
echo "You need access to view this page!"
exit;
}
php?>
does not work. Reason being, the script has NO idea what $username or $password is. To fix this, you need to add the following:
PHP Code:
<?php
// Session start
session_start();
$username = $_POST[username];
$password = $_POST[password];
// Checks password and username
if($username == "test" AND $password == "1337") {
// Session userid and loggedin is true
$_SESSION[username] = "test";
$_SESSION[userid] = 1;
$_SESSION[loggedin] = 1;
echo "<font face='verdana' size='1'>You are now logged in as 'test'</font>";
} else {
echo "You need access to view this page!"
exit;
}
php?>
Unless I missed something, this should do it.
BTW, if you want to make this for multiple users, and continue to not use SQL, you can just keep adding like so:
PHP Code:
<?php
// Session start
session_start();
$username = $_POST[username];
$password = $_POST[password];
// Checks password and username
if ($username == "test" AND $password == "1234") {
// Session userid and loggedin is true
$_SESSION[username] = "admin";
$_SESSION[userid] = 1;
$_SESSION[loggedin] = 1;
header('Location: admin/index.php');
} elseif ($username == "joshua" AND $password == "1234") {
$_SESSION[username] = "Joshua";
$_SESSION[userid] = 2;
$_SESSION[loggedin] = 2;
header('Location: users/draketech/index.php');
} else {
header('Location: loginfailed.php');
exit;
}
?>
And when you apply it to your pages, just change
PHP Code:
session_start();
if ($_SESSION['loggedin'] == 1) {
to
PHP Code:
session_start();
if ($_SESSION['loggedin'] == whatever number that user is.) {
Bookmarks