How can you pass data from one PHP page to another?
To pass data from one PHP page to another, you can use methods like URL parameters, sessions, cookies, or form submissions. One common method is to use URL parameters by appending data to the URL and then retrieving it on the next page. Another method is to store the data in sessions or cookies, allowing you to access it across multiple pages. Lastly, you can pass data through form submissions by using hidden input fields.
// First PHP page (page1.php)
$data = "Hello World";
header("Location: page2.php?data=" . urlencode($data));
exit;
// Second PHP page (page2.php)
if(isset($_GET['data'])) {
$data = $_GET['data'];
echo "Data received: " . $data;
}