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
Access MySQL Field's Comments with PHP
Mongodb Aggregate Query Using PHP Driver
Zend Framework 2 - Removed Form Element Causes Validation to Fail
Laravel Expected Response Code 250 But Got Code "530"
PHP Type Hinting Not Getting Along with Interfaces and Abstract Classes
How to Set Base Url for All Pages of My Website
How to Curry Method Calls in PHP
Http Auth via PHP - PHP_Auth_User Not Set
How to Load the Requested Language File: Language/En/Form_Validation_Lang.Php
Php/Apache: PHP Fatal Error: Call to Undefined Function MySQL_Connect()
File Upload PHP $_Files Undefined Index Error
Woocommerce: Display Also Product Variation Description on Cart Items
PHP Xpath - Find Element with a Value and Also Get Elements Before and After Element
PHP $String{0} VS. $String[0];
Class App\Http\Controllers\Usercontroller Does Not Exist
Difference(When Being Applied to My Code) Between Int(10) and Int(12)