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 a PHP beginner implement a login form on the index.php page and redirect to the start page upon successful login?
- What are the differences between using Redirect and RewriteRule in .htaccess for URL redirection in PHP, and when should each be used?
- Is it possible to execute a PHP script instead of following a link when clicked?