CPSC 343 Database Theory and Practice Fall 2024

HTML/PHP Local Quick Start

This document is intended to describe the local environment for working with HTML and PHP in CPSC 343. Refer to the PHP Quick Start for information on the PHP language, the PHP Web Quick Start for information on getting information about the web server environment, processing HTML forms, and working with sessions and cookies, or the PHP MySQL Quick Start for information on interacting with MySQL from PHP.


Contents


Setup

Your HTML and PHP files will need to be viewed through a webserver configured to run PHP files. It is recommended to use VSCode as an editor. You'll then need to install the PHP Server extension to view/run your files:

It's recommended that you also install a code formatter for PHP/HTML — this makes it easy to auto-format your files for greater readability.

To use the code formatter, use ctrl-shift-I or invoke the Command Palette (ctrl-shift-P) and search for "format document". You can also configure VSCode to automatically format on save: File→Preferences→Settings, then search for "format on save" and toggle the checkbox on.

It is strongly recommended that you use VSCode in the HWS Linux environment, whether on the computers in the Rosenberg 009 and Lansing 310 labs or through the Linux virtual desktop. Working on your own computer requires also downloading and installing php, which can be somewhat involved depending on your operating system.


Naming and Viewing Your HTML and PHP Files

Files containing PHP code must have a filename ending with .php; files containing only HTML code must have a filename ending with .html (or .php, but there's no reason to make the PHP processor handle a file without any PHP).

To view the file using VSCode:


Viewing the Quick Start Examples

The examples used in the other Quick Start documents are available for you to try out. The URL:

  http://bridgeman-vm.hws.edu/cs343f24/quickstart

Note that this link only works on campus. See the instructions on Canvas about off-campus access to the HWS network in the "systems and software" module.


Finding Problems

Because the PHP is processed by the webserver, PHP syntax errors and other problems which prevent PHP from executing are logged on the server. You can find these error messages in the Output window in VSCode. (This view is opened automatically when you start the PHP server, but if you've lost it, you can use View→Output to re-open it. Make sure "PHP Server" is selected in the drop-down list in the title bar within the view.)

To examine the HTML received by the web browser (useful for debugging PHP output problems), use your browser's View Source feature. In Firefox, you can right-click on the page and choose "View Page Source" or use the hamburger menu followed by More Tools → Page Source. However, Firefox also has a "feature" where it resends the page request to get the source instead of using a cached copy, so this may not work correctly when session variables and similar things are used. In that case, you can use the Inspector: from the hamburger menu, choose More Tools → Web Developer Tools and then click on the Inspector tab.


Off-Campus Access

If you are not on the campus network, you can still view your HTML and PHP files but you will need to run VPN in order to access the database server. See the instructions on Canvas about off-campus access to the HWS network in the "systems and software" module.