0
0
PHPprogramming~15 mins

$_GET for URL parameters in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Using $_GET to Read URL Parameters in PHP
📖 Scenario: You are building a simple PHP page that greets users by their name passed in the URL.
🎯 Goal: Create a PHP script that reads a name parameter from the URL using $_GET and displays a greeting message.
📋 What You'll Learn
Create a PHP variable to store the name parameter from $_GET
Set a default value if the name parameter is not provided
Display a greeting message using the name variable
💡 Why This Matters
🌍 Real World
Reading URL parameters is common in web pages to customize content based on user input or links.
💼 Career
Understanding how to use <code>$_GET</code> is essential for PHP web developers to handle user requests and build dynamic websites.
Progress0 / 4 steps
1
Create a PHP variable to get the name parameter from the URL
Write a line of PHP code to create a variable called name that gets the value from $_GET['name'].
PHP
Need a hint?

Use $name = $_GET['name']; to get the URL parameter.

2
Add a default value if name is not set in the URL
Add a line of PHP code to set $name to "Guest" if $_GET['name'] is not set or empty.
PHP
Need a hint?

Use empty() to check if $name has no value and assign "Guest" if true.

3
Create a greeting message using the name variable
Write a line of PHP code to create a variable called greeting that stores the string "Hello, " followed by the value of $name.
PHP
Need a hint?

Use the dot . operator to join strings in PHP.

4
Display the greeting message
Write a line of PHP code to print the $greeting variable.
PHP
Need a hint?

Use print($greeting); to show the message on the page.