Setting $_Session Doesn't Work on Localhost Using Xampp

Problem with PHP session in Xampp

You've forgotten the session_start at the top of file_2.php

So it should be:

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>

<?php

if (!(isset($_SESSION["test_message"])))
echo "Test message is not set";
else
echo $_SESSION["test_message"];

var_dump($_SESSION);

session_destroy();
?>

</body>
</html>

session_start() should be at the top of every file where you need to access the session functions.

EDIT:

You should really use session_write_close before redirecting to another page.

first file:

<?php
session_start();

$_SESSION["test_message"] = "Hello, world";

session_write_close();
header("Location: http://localhost/file_2.php");
?>

Empty sessions on local xampp server

What finally worked for me was to uninstall xampp and install a previous version. I had tried re-installing the same version before without success.

$_SESSION doesn't work. xampp php7

When I clear the session with session_unset(); it works!
Thanks for the help =)



Related Topics



Leave a reply



Submit