Updated 1/7/2020 at 4:00pm
Homework #1: PHP Syntax and Variables
-
Remember to follow all the standard Homework Requirements.
-
This assignment will demonstrate:
-
"Include" files
-
Variables
-
General statement of the problem:
- Send an email to me, giving me the URL (domain) to your class Web site.
- Include a "library" PHP file
in your index.php page.
- Use some of the information in this "library"
PHP file to display today's date in the body of your index.php page.
-
To be more specific:
-
Copy the following code and paste it into your HTML editor:
<?php
$dt = new DateTime("now");
$tz = new DateTimeZone('America/Chicago'); // or whatever zone you're after
$dt->setTimezone($tz);
$currDate = $dt->format('F j, Y');
?>
-
Save the pasted code into the local directory where you are working on the
pages for this semester. Save is as file library.php
-
Make a new page in your HTML editor, and save it as index.php
If you have a previous Web site (from, for instance, the Web Design 1 class),
you may copy the index.html file from that site, and save it as index.php. Please
note that the file extension must be .php.
And if you do choose to re-use previous code, you will need to rename all of the pages
as .php pages, which also means that you will need to change
the URLs in the navigation links. All of the pages for this semester will be
.php pages.
-
Use the PHP include command to include page library.php into
your index.php page. You should put the PHP include command at or near the top of your
index.php page, meaning you would normally put it before the <!DOCTYPE html> tag.
-
Now put some PHP code into your index.php page (it will need to be in the page's
<body> section) which displays the variable $currDate (which is in the file library.php).
-
You can add whatever text you wish, or you can simply display the date. It might be fun for you to
put something like this in the page:
Today's date is <the date>
(where <the date> is the
date which is contained in the variable $currDate). If you decide to add some text like this, you
can use either concatenation
to add this text, or variable interpolation, or a combination of the two.
-
Upload your pages (both index.php and library.php) to your Web site.
-
Test your pages on the site by clicking your student number on the
"Student Sites" page of this class site. Make sure
the current date is displayed in your index page.