Hello,
I have been trying for the last few days to figure out how to send a particular user to their own specific URL. For example, all users will use the same login.php page but when User A logs in they will be redirected to A.php and if User B logs in they will be redirected to B.php etc.
I am totally new to php and have been using it for about 3 weeks. I am very familiar with html. So far I have managed to create a script where the above redirection works but it is not connected to a database. The redirection is all hard-coded into the script.
This is the code which is currently working:
<?php
session_start();
$users['david'] = array('password' => '123', 'redirect' => 'david.php');
$users['peter'] = array('password' => '321', 'redirect' => 'peter.php');
if(array_key_exists($_POST['username'],$users)) {
if($_POST['password'] == $users[$_POST['username']]['password']) {
$_SESSION['loggedIn'] = true;
header('Location:'.$users[$_POST['username']]['redirect']);
exit();
}
else {
// invalid password
header('location: login.php');
exit;
}
}
else {
// invalid username
header('location: login.php');
exit;
}
?>
This works 100% and is almost exactly what I need. The user gets redirected to their own specific URL. The only problem is that the code is not connected to a database and the users, password and redirection are all hard-coded within the script. Is there anyway to adapt the above code so it would connect to a database for the information? I have phpmyadmin installed.
Any help whatsoever would be much appreciated and I would be truly grateful if someone could please help me.
Kind regards,
Robert.