Skip to content
PHP Logo

How can PHP sessions be used to pass data between included files?

To pass data between included files in PHP, you can use sessions to store the data and access it across different files. By storing the data in a session variable, you can easily retrieve it in any included file within the same session.

php
// File 1: store.php
session_start();
$_SESSION['data'] = "Hello, world!";

// File 2: retrieve.php
session_start();
echo $_SESSION['data'];