How to use store and use session variables across pages with PHP?

Spread the love

Sometimes, we want to use store and use session variables across pages with PHP.

In this article, we’ll look at how to use store and use session variables across pages with PHP.

How to use store and use session variables across pages with PHP?

To use store and use session variables across pages with PHP, we call the session_start function.

For instance, in 1.php, we write

<?php

session_start();
$_SESSION["email"] = "email@example.com";

to call session_start to start the session.

Then we can populate the $_SESSION array with the values we want to keep.

Next, in 2.php, we write

<?php

session_start();
if ($_SESSION["email"]) {
    echo "Your Email Is Here";
}

We call session_start before we try to get the value of $_SESSION["email"] that we set in 1.php.

Conclusion

To use store and use session variables across pages with PHP, we call the session_start function.

Leave a Reply

Your email address will not be published.