Passing Multiple Variables through URL
When passing multiple variables to another page via URL, using sessions alone may not suffice. The concatenation of additional variables to the same URL can lead to retrieval issues. By default, PHP interprets spaces as a delimiter, which can break the URL.
Solution: Using the Ampersand '&'
To address this, concatenate variables using the ampersand (&) as a separator. Here's an adapted version of your code:
Page 1:
<code class="php">session_start(); $event_id = $_SESSION['event_id']; echo $event_id; $url = "http://localhost/main.php?email=$email_address&event_id=$event_id"; </code>
Page 2:
<code class="php">if (isset($_GET['event_id'])) { $event_id = $_GET['event_id'];} echo $event_id;</code>
Explanation:
By using the ampersand (&), we essentially glue the variables together. This ensures that the URL is correctly parsed by the next page, and both variables can be retrieved successfully using $_GET. The start of variables and each subsequent variable is separated by the ampersand.
The above is the detailed content of How to Pass Multiple Variables through a URL in PHP?. For more information, please follow other related articles on the PHP Chinese website!