Php parameter url

PHP Parameter URL

The PHP parameter URL is a mechanism to pass values or data from one page to another through the URL. The information is appended to the URL as query parameters.

Syntax

To pass parameters through the URL, we append a “?” symbol and then specify the parameter name and its value using the following syntax:

URL?parameter1=value1&parameter2=value2&...

Example

Let’s say we have two PHP files, “page1.php” and “page2.php”. We want to pass a name parameter from “page1.php” to “page2.php”.

In “page1.php”, we can have a link like this:

<a href="page2.php?name=John">Go to Page 2</a>

In “page2.php”, we can retrieve the value of the name parameter using the PHP $_GET superglobal variable:

<?php
$name = $_GET['name'];
echo "Hello, $name!";
?>

When the link is clicked, the URL will become “page2.php?name=John” and the value of the name parameter will be retrieved using $_GET[‘name’].

Leave a comment