Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PHP HTML code. I am having trouble getting the rest of the site to remember who logged in once someone does. I thought I was

PHP HTML code. I am having trouble getting the rest of the site to remember who logged in once someone does. I thought I was correct on calling the access_level as the username/ But idk because when I go to click to another site on my website it doesn't show who is logged in.

This is my login.php

session_start();

// Set the username and password for each account

$accounts = array(

'admin' => 'admin',

'publisher' => 'publisher',

'customer' => 'customer'

);

// Check if the user has submitted the login form

if (isset($_POST['username']) && isset($_POST['password'])) {

$username = $_POST['username'];

$password = $_POST['password'];

// Check if the username and password match an account

if (isset($accounts[$username]) && $accounts[$username] == $password) {

// Set the access level in the session

$_SESSION['access_level'] = $username;

// Redirect to the appropriate page

if ($username == 'admin') {

header('Location: admin.php');

exit();

} else if ($username == 'publisher') {

header('Location: publisher.php');

exit();

} else if ($username == 'customer') {

header('Location: customer.php');

exit();

}

} else {

$error = 'Invalid username or password.';

}

}

?>

Log In

Input your login information

The footer.php has the logout information init and that is where I would like it to remember the username and have the logout option available, if you catch my drift.

This is my footer.php


Validated by:

image text in transcribed

image text in transcribed

if (!isset($_SESSION['access_level'])) {

echo " USER NOT LOGGED IN. Log In here";

} else echo " User: {$_SESSION['access_level']}";

if (isset($_SESSION['access_level'])) {

echo " Logout";

}

echo " ";

echo " ";

echo "Last modified:";

$timestamp = filemtime(__FILE__);

$date_time = new DateTime();

$date_time->setTimezone(new DateTimeZone("America/New_York"));

$date_time->setTimestamp($timestamp);

echo $date_time->format("F j Y g:i a.");

?>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago