first hand thanks so much for the help you could give, i´m trying to create a login section with a porfile section, the login work great, but i want to get all the information of the user that just login in to the page and display it on the profile section, how can i do that. Here are the file for the index.php(just get language of the page and redirect to a the correcto version and check if the user is login or not), gallery.php(profile section) and login.php(check the user on the DB), home-de.php(just where loging form is).
The data base is simple just one table call users and fields id, first_name, last_name, email, password.
index.php
<?php
session_start();
$accept_language = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$lang = $accept_language[0];
echo $lang;
switch ($lang)
{
case 'en':
if (isset($_SESSION['users'])) {
header('Location: en/gallery_en.php');
}else{
header('Location: en/home-en.php');
}
break;
default:
if (isset($_SESSION['users'])) {
header('Location: de/gallery_de.php');
}else{
header('Location: de/home-de.php');
}
}
?>
login.php
<?php
session_start();
function login($location){
if (isset($_SESSION['users'])) {
header('Location: '. $location . '');
}
$errores = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$user_email = strtolower($_POST['email']);
$user_pass = $_POST['password'];
try {
$connection = new PDO('mysql:host=localhost;dbname=user_login', 'root', '');
} catch (PDOException $e) {
echo "Error:" . $e->getMessage();;
}
$statement = $connection->prepare('SELECT * FROM users WHERE user_email = :email AND user_pass = :password');
$statement->execute(array(':email' => $user_email,':password' => $user_pass));
$result = $statement->fetch();
if ($result !== false) {
$_SESSION['users'] = $user_email;
header('Location: '. $location . '');
} else {
$errores .= '<li>Datos Incorrectos</li>';
}
}
}
?>
de/home-de.php
<?php
require ('../login.php');
login('../de/gallery.php');
?>
<form id="login-form" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST" name="login">
<div class="login-field">
<label for="email_login">Email</label>
<input type="text" name="email" id="email_login">
<div class="message text-center"><p>This field is required</p></div>
<div class="pattern text-center"><p>Enter a valid email.</p></div>
</div>
<div class="login-field">
<label for="pass_login">Password</label>
<input type="password" name="password" id="pass_login">
<div class="message text-center"><p>This field is required</p></div>
</div>
<input type="submit" value="Login">
</form>
de/gallery_de.php
<?php
session_start();
if (isset($_SESSION['users'])) {
} else {
header('Location: ../index.php');
}
?>
<h1 class="title-bar">Willkommen <?php echo '(here will put the first name of the user)'?></h1>