Professional Documents
Culture Documents
Tutorial P1 - Intro To PHP (1.5 Hours) : Hello World! " ?
Tutorial P1 - Intro To PHP (1.5 Hours) : Hello World! " ?
1. First write your first php page using Notepad. Check to see the page is working fine.
Save it as page.php inside folder C:XAMPP/htdocs/.
<html>
<head>
<title>My first PHP page</title>
</head>
<body>
<?php
?>
</body>
</html>
2. Make sure XAMPP is running. Open your browser and type http://localhost/ in the address bar.
If XAMPP is running you will see a Welcome page. Now type http://localhost/page.php - What
do you see? Also, comment about the source code when you view the source code.
When we view the source code, we cannot see the PHP code. Whatever enclosed in the PHP
code, it cannot be seen.
Name:__Tan Wan Sean
__________________________________ Date: ______4/8/2020__________
3. Add the code to display the server’s date into page.php. Save and view.
echo date("r");
echo "<p>Today it's " . date("l") . "</p>";
4. We can also use predefined variables as follows. Insert the following inside the php section::
$file = $_SERVER['PHP_SELF'];
$user = $_SERVER['HTTP_USER_AGENT'];
$address = $_SERVER['REMOTE_ADDR'];
The above defines the present file you are using, the web browser you are using and your IP
address as seen by the server.
6. Comment about the php file when viewed from your browser and also the source code:
Name:__Tan Wan Sean
__________________________________ Date: ______4/8/2020__________
The code in the php appeared in the source code by uploading the php file.
Can you combine them all in one line? Write you code below:
<?php
echo "Today is " . date("l, y/m/d, F-(n)") . "<br>";
?>
8. Upload your file into InfinityFree server – does it work? Comment about the date/time.
Yes, it works. The date and time are displayed using the echo date function.
References:
1. http://www.w3schools.com/php/
2. http://html.net/tutorials/php/lesson1.php