I'm not able to start session_start () in php and I really can't understand the reason, I've tried a few things people suggested on forums, but the session_start() still does not work
index file where are not retrieving variables $ _SESSION:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Pagina1</title>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<article id="newPrincipal">
<h1>Usuário id:<?php echo $_SESSION['userId']; ?></h1>
</article>
<h1>Result:<?php echo "Usuário id:".$_SESSION['userId']; ?></h1>
</body>
</html>
<?php
echo '<pre>';
print_r($_SESSION['userId']);
echo '</pre>';
login file:
<?php
if(isset($_POST['login-submit'])){
require 'dbh.inc.php';
$users = $_POST['nome'];
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
$token;
if(empty($mailuid) || empty($password)){
header("Location: ../header.php=emptyfields");
exit();
}
else{
$sql = "SELECT * FROM users WHERE Usuarios=? AND email=?";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location: ../index.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $users);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if($row = mysqli_fetch_assoc($result)){
$pwdCheck = password_verify($password, $row['pwdUsers']);
if($pwdCheck == false){
header("Location: ../header.php?error=wrongpwd");
exit();
}
else if($pwdCheck == true){
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userId2'] = $row['uidUsers'];
$_SESSION['email'] = $row['emailUsers'];
header("Location: ../index.php?login=".$_SESSION['userId']);
}
else{
header("Location: ../login.php?error=wrongpwd");
exit();
}
}
}
}
}
else{
header("Location: ../index.php");
}
I'm using an external server not the Xampp / Wamp, I do not know if this would imply anything ...
I tried every ways to retrieve some information using $ _SESSION in the index file, but I could not.