Skip to content
PHP Logo

How can PHP variables passed through a URL be accessed and displayed in another PHP file?

To access PHP variables passed through a URL in another PHP file, you can use the $_GET superglobal array to retrieve the values. Simply specify the variable name in the URL query string and then use $_GET['variable_name'] to access the value in the receiving PHP file.

php
// Sending PHP variable through URL
<a href="receiver.php?var=value">Send Variable</a>

// Receiving PHP variable in receiver.php
<?php
if(isset($_GET['var'])){
    $receivedVar = $_GET['var'];
    echo "Received variable: " . $receivedVar;
}
?>