-1

So, suppose I have a php file named A like this:

<?php
$_SESSION["Ad gloriam"] = "La musique donne une âme à nos coeurs et des ailes à la pensée.";
?>
    <h4> Hello, everything goes OK<h4>
    <h4> The $_SESSION["Ad gloriam"] = <?php
        echo ($_SESSION["Ad gloriam"]);
    ?></h4>
<script src="/php2.php">
</script>

The result looks to something like this:

enter image description here


Now, suppose we have a /php2.php file witch I have load in A:

<?php
    echo ("console.log ('".$_SESSION["Ad gloriam"]."');");
    echo ("console.log ('Si la vertu ne suffit pas à assurer le bonheur, la méchanceté suffit à rendre malheureux.');");
?>

Normally, the script will be execute when I load A and I will see in the console:

  • La musique donne une âme à nos coeurs et des ailes à la pensée. (=> from $_SESSION["Ad gloriam"]);
  • Si la vertu ne suffit pas à assurer le bonheur, la méchanceté suffit à rendre malheureux. (=> a test).

However, $_SESSION["Ad gloriam"] returns nothing and I do not see anything in the console.

What did I wrong?

I do not find anything about the subject in the web. Maybe, I do not achieve to put a name on this error.

NOTE: My title is, maybe, not very clear. Tell me a better title in the comments if you find one, please.

Tell me if you have some questions.

SphynxTech
  • 1,799
  • 2
  • 18
  • 38

1 Answers1

2

Each php file needs to start a session.

Just add

session_start(); 

to each file as first line.

coding Bott
  • 4,287
  • 1
  • 27
  • 44