Hi I'm new to PHP. I just followed a tutorial so far to make a simple php login, shown below. I will have already created there username and password, as well as the .pdf so that it matches their username. All I want it to do is, when they login with their username, they immediately be prompted to download a .pdf which will be called (their username).pdf. Is this possible?
This is a simple site for work, where people can sign in to download their confidential individual file.
Any help would be much appreciated, thanks.
passwords.php:
<?php
$USERS["admin"] = "password";
$USERS["username2"] = "password2";
$USERS["username3"] = "password3";
function check_logged(){
global $SESSION, $USERS;
if (!array_key_exists($SESSION["logged"],$USERS)) {
header("Location: login.php");
};
};
?>
login.php
<?php
session_start();
include("passwords.php");
if ($POST["ac"]=="log") {
/// do after login form is submitted
if ($USERS[$POST["username"]]==$POST["password"]) {
/// check if submitted username and password exist in $USERS array
$SESSION["logged"]=$POST["username"];
} else {
echo 'Incorrect username/password. Please, try again.';
};
};
if (array_key_exists($SESSION["logged"],$USERS)) {
//// check if user is logged or not
echo "You are logged in!";
//// if user is logged show a message
} else {
//// if not logged show login form
echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> ';
echo 'Username: <input type="text" name="username" /><br />';
echo 'Password: <input type="password" name="password" /><br />';
echo '<input type="submit" value="Login" />';
echo '</form>';
};
?>