How can you pass a variable value from one PHP script to another using a link?
To pass a variable value from one PHP script to another using a link, you can append the variable and its value to the URL as query parameters. In the receiving script, you can retrieve the variable value from the URL using the $_GET superglobal array. Example PHP code snippet:
// Sending script (script1.php)
$variable = "example";
echo "<a href='script2.php?var=$variable'>Click here</a>";
// Receiving script (script2.php)
if(isset($_GET['var'])){
$received_variable = $_GET['var'];
echo "Received variable value: " . $received_variable;
}
Keywords
Related Questions
- How can the issue of default CSS loading after clicking a link be resolved without using sessions in PHP?
- Are there any best practices for monitoring and managing PHP error logs in a production environment?
- What alternatives to PHPBB are available that may be considered more secure, but may also come at a cost?