Skip to content

Lab - Week 1

Hello World!

  • Create a labs/week1 directory under your /var/www/html directory

  • Open an editor and create a file named helloworld.php and save it to your labs/week1 directory

  • Enter the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<html>
 <head>
  <title>Personalized Hello World</title>
 </head>
 <body>
  <?php
      if(!empty($_POST['name'])) {
          echo "Greetings, {$_POST['name']}, and welcome.";
      }
  ?>
  <form action="<?php $PHP_SELF; ?>" method="post">
      Enter your name: <input type="text" name="name" />
    <input type="submit" />
  </form>
 </body>
</html>
  • Make sure you save the file to your /var/www/html/labs/week1 directory

  • Open a browser and enter the URL for localhost/labs/week1/helloworld.php

  • Show the contents of the file and the screen output to your instructor