I have this project and so far this is what it’s suppose to do:
There are 4 pages. The first page asks the user to enter their username and password (these are finite and defined by the second page) and asks the user to choose a file they want to work with. The second page verifies the username and password are correct and echoes the information from the chosen file into a table and has two links underneath: one to take the user back to page 1, and the second to take the user to page 3. Page 3 calls in two functions from page 4 to loop through all the information in that same file using regex to make sure Student Numbers and email addresses are in the correct format. If it’s correct, it will alert the user that all the information is legitimate, or else it will write the errors to a log file. What I’m having trouble with is on page 3 and 4. The functions aren’t working because Apache says there are undefined variables, and on page 3 I can’t seem to get rid of the array to string conversion notice. This is driving me nuts. Here’s the code for all four pages:
Page 1
[code]<?php
/* File: page1.php
This file is first major assignment in the PHP level 1 course.
The purpose: “To write a php application that helps an instructor set up a website for their courses.”
Author: name
Last modified: May 04, 2007.
*/
echo ‘’;
echo ‘’;
echo ‘’;
echo ‘’;
echo ‘Comp 1920 - Assignment 1’;
echo ‘’;
echo ‘’;
echo ‘’;
echo 'Please enter your username:
';
echo 'Please enter your password:
';
$directory = “./courses/”;
$fileslist = scandir($directory);
echo “Please Select a File:
”;
echo ‘’;
foreach($fileslist as $filenames) {
//The following code splits the string into 'filename' and 'extension'.
list($name, $extension) = explode('.txt', $filenames);
if (is_dir ($directory)){
//I'll think of something to put here later...
}
else {
die ("Directory 'courses' or required files do not exist.");
}
if (is_dir($filenames)) {
continue;
}
elseif (!ereg("^.*.(txt)$", $filenames) ){
continue;
}
echo "<option value="$filenames">$name</option><br />";
}
echo “
”;
echo ‘’;
echo ‘’;
echo ‘’;
echo ‘’;
?>[/code]
Page 2
[code]<?php
/* File: page2.php
This file is first major assignment in the PHP level 1 course.
The purpose: “To write a php application that helps an instructor set up a website for their courses.”
Author: name
Last modified: May 04, 2007.
*/
/* The following code determines if the username field has a value. If it doesn’t, it will kill the script.
*/
if (!($_GET[“username”])){
die (“Please enter your username.”);
}
elseif ($_GET[“username”] !=“comp1920”){
die (“Invalid username, sorry.”);
}
/* The following code determines if the password name field has a value/valid value. If it doesn’t, it will kill the script.
*/
if (!($_GET[“password”])) {
die (“Please enter a password.”);
}
elseif ($_GET[“password”] != “php”) {
die (“Invalid password, sorry.”);
}
/*
The following script determines which file was chosen and will echo out the contents in a table for the user to review. It provides links back to page1 or onto page3, depending if they decide to use the file.
*/
$resultfile = $_GET[“filename”];
if (!($_GET[“filename”])) {
die (“Please select a course file to work with.”);
} else {
$file = file("./courses/".$resultfile);
echo “You chose file: $resultfilen
”.$finaloutput.“ | n”;
Someone please help! I really can’t figure out how to get page 3 to so what it’s supposed to do!
Link to the project description:
http://php1920.redirectme.net/res_COMP1 … nment1.htm