CSci 115: Computing and the Internet
Home Syllabus Assignments Tests

Hendrix Campus

Assignment 3: Campus map

Due at:9:40am, Tue 25 Sep
Point value:30 pts

Hendrix's Information Technology has hired you to create a Web page to help students find which of three labs is closest to the student's current location:

Bailey Library (the main lab)
M C Reynolds (the mathematics lab)
D W Reynolds (the psychology lab)

The idea is that students will click somewhere on the campus map, and a PHP script will compute the closest lab location and report the name of the building where it is located.

The first problem you'll need to confront is how to get an HTML file to display an image on which the user might click so that the click coordinates are sent to the PHP script. This is done by using the <img> tag's ismap attribute, and by placing the <img> element inside an anchor (<a>) element. Basically, you can paste the following into your HTML file.

<a href="findlab.php"><img ismap="ismap" border="0"

When the user clicks the map, the browser will then send a request to findlab.php: You'll see in the browser's location bar that in addition to sending the name findlab.php to the server, the browser also sends to the server a question mark followed by the coordinates where the user clicked. Your PHP script can retrieve these coordinates using the following PHP code (which you should not attempt to understand using what I've taught you thus far).

$x = preg_replace("/,.*/", "", $_SERVER["QUERY_STRING"]);
$y = preg_replace("/.*,/", "", $_SERVER["QUERY_STRING"]);

After determining the click coordinates using the above PHP, your script can compute the distance to each lab using the distance formula.

d = sqrt((x1 − x0)² + (y1 − y0)²)

(We of course assume that you know how to jump over buildings and even how to walk across the grass, so the straight-line distance is an appropriate distance estimate.)