What is the $_GET command in PHP and how is it used to pass variables in the browser?
The $_GET command in PHP is used to retrieve data that is sent to the server from a form using the GET method. This data is passed through the URL as key-value pairs and can be accessed using the $_GET superglobal array. To pass variables in the browser using $_GET, simply append the variable name and its value to the URL using a question mark (?) followed by the variable name, an equal sign (=), and the value. Multiple variables can be passed by separating them with an ampersand (&).
// Example of passing variables in the browser using $_GET
// URL: http://example.com/page.php?name=John&age=25
$name = $_GET['name'];
$age = $_GET['age'];
echo "Name: " . $name . "<br>";
echo "Age: " . $age;
Related Questions
- What are some best practices for recursively listing directories and filtering files based on their extensions in PHP?
- How can error reporting be optimized in PHP to quickly identify and resolve issues in MySQL queries?
- Are there any PHP libraries or frameworks that can simplify form validation and processing?