How to use sessions with PHP?

I can’t seem to store sessions across php pages. A phpinfo() shows that sessions are enabled.

index.php:

<?php
session_start();
$name="Andrew";
$_SESSION["name"] = $name;
header("Location: results.php");
exit();
?>

results.php:

<?php
session_start();
$name=$_SESSION["name"];
echo $name;
?>

result:
Warning: Undefined array key "name" in /home/runner/Sessions-Test/results.php on line 3

Hi @TresKewlshoes,

I put your code into a new PHP Web Server repl and it looks like your code is working…

https://replit.com/@robsd/AchingSilkyCarriers

Sessions do not work with the webview so you will need to open the website URL in a new tab…

Screenshot 2023-04-26 at 15.02.51

Screenshot 2023-04-26 at 15.03.24

1 Like