PHP

PHP Script to Display a Welcome Message2 min read

Problem: Write a php script to display welcome message

Solution: Here’s a simple PHP script that displays a welcome message




This script starts with a standard HTML document structure and uses PHP tags to embed a PHP script that outputs a welcome message in an h1 heading element. When run on a web server with PHP installed, this script will display the text “Welcome!” on the page.

Here’s an updated version of the script that includes a dynamic greeting based on the current time:

In this script, we use the date function to get the current hour in a 24-hour format. We then use an if-else statement to determine the appropriate greeting based on the current hour and set the value of the $greeting variable accordingly. Finally, we use two echo statements to output the greeting and the welcome message on the page.

Here’s an extended version of the code that includes a personal message based on the user’s name:

In this version of the code, we added a check to see if the name parameter has been passed in the URL (e.g. http://example.com?name=John). If it has, we retrieve the value of the name parameter using the $_GET superglobal array and store it in the $name variable. Then, in the final two echo statements, we use the $greeting and $name variables to personalize the welcome message for the user.

Leave a Comment