What are some common methods for transferring data between pages using PHP?
When transferring data between pages in PHP, common methods include using session variables, URL parameters, and form submissions. Session variables can store data that persists across multiple pages for a single user session. URL parameters can pass data through the URL itself. Form submissions can send data from one page to another using POST or GET methods.
// Using session variables to transfer data between pages
session_start();
$_SESSION['data'] = 'Hello, World!';
// Using URL parameters to transfer data between pages
// Page 1
$data = 'Hello, World!';
header("Location: page2.php?data=" . urlencode($data));
// Page 2
$data = $_GET['data'];
// Using form submissions to transfer data between pages
// Page 1
<form action="page2.php" method="post">
<input type="hidden" name="data" value="Hello, World!">
<input type="submit" value="Submit">
</form>
// Page 2
$data = $_POST['data'];
Related questions
-
PHP CSV data grouping
-
UTF-8 Umlauts mbstring
-
image processing file uploads error handling