How do you retrieve parameters from a URL using PHP?

In PHP, you can use the $_GET superglobal variable to retrieve parameters from the URL. Here is a simple example:

If the URL is http://example.com/index.php?name=John&age=25, you can fetch the values of the name and age parameters by using the following code:

$name = $_GET['name'];
$age = $_GET['age'];

echo "Name: " . $name . "<br>";
echo "Age: " . $age;

In this way, you can access the parameters in the URL and output their values. Please note that when using the $_GET variable to obtain parameters, it is important to ensure security by filtering and validating parameters to prevent malicious inputs.

广告
Closing in 10 seconds
bannerAds