Let me explain my situation: I don’t know if it makes a difference. I did not connect with a database. Instead I use a document call install.php to create table and all the data will be saved as a .json file under my data folder inside the MAMP. An example of the codes in install.php is as follow:
<?php
echo "setup admin account...";
$users = [
[ 'username' => 'hannah', 'password' => '123'],
[ 'username' => 'beeno', 'password' => '123']
];
$text = json_encode($users);
file_put_contents('../data/users.json', $text);
I have two different home screens, basically one for index.php and another one for adminhome.php which the admin login will automatically direct to this page.
My login.php code is as follows:
<?php
$text=file_get_contents('../data/users.json');
$users=json_decode($text, true);
foreach($users as &$user){
if($_POST['username'] == $user['username'] && $_POST['password'] == $user['password']){
http_response_code(200);
echo 'matched';
//setcookie('username', $user['username']);
session_start();
$_SESSION['username'] = $user['username'];
*echo "<p><a href='/'>Back to home</a></p>";*
die;
}
}
http_response_code(403);
echo 'not matched';
echo "<p><a href='/'>Back to home</a></p>";
?>
So for this specific block:
$_SESSION[‘username’] = $user[‘username’];
*echo “<a href='slash>Back to home
die;
I want to direct to “adminhome.php.” I tried echo
<a href= (double quotations) adminhome.php (double quotations) Back to Home
. But immediately my website pop the 403 response code. What can I do? Thanks in advance!