Multifarious Project A personal -system Team Members Abdullah Alghamdi Metaib Alenzai Mohammed Alshehri Hamd Alshamsi
The Project Idea system allows user to login securely into a web-based system.
SYSTEM LAYOUT User logs into the web based system Login page displayed to user as part of client side PHP scripts Authentication and data communication occurs between client and server Server performs processing and authentication procedures and returns appropriate response Server side checks for user profiles and details in the database
Programming Languages Used PHP HTML
PHP and Why? PHP stands for PHP: Hypertext Preprocessor. PHP runs on different platforms (Windows, Linux, Unix, etc.) PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) PHP is an open source software (OSS). PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP is easy to learn and runs efficiently on the server side.
HTML HTML stands for Hyper Text Markup Language An HTML file is a text file containing small markup tags The markup tags tell the Web browser how to display the page An HTML file must have an htm or html file extension An HTML file can be created using a simple text editor
Logon.php This is the main file. It contains the PHP code that will be executed once a username and password will be entered. It authenticates the username and password that are entered by the user by communicating with the server. The code also sets the cookie for 1800 seconds and expires after that, so that the user has to logon again after that time period. The code checks for an invalid usernames and passwords and prevents that kind of input from the user. This file relays all the obtained information to INDEX.PHP and communicates with it.
Logon Page
Logon PHP Code if( isset($_POST['user']) && isset($_POST['pass']) ) { $mbox $_POST['user'], $_POST['pass']); if($mbox) { setcookie("auth",serialize(Array($_POST['user'],$ _POST['pass'])),time()+1800,"/",".fit.edu"); } else { setcookie('auth','',-1,"/",".fit.edu"); }
Logon HTML Code Login Login to Username: Password:
Auth PHP AUTH.PHP contains the logic to authorize a user. The main function in this PHP code is the Die function. If a user enters a wrong username/password or blank username/password, this function will prevent the user from logging in. This file communicates this information to LOGON.PHP and acts as a bridge between the client and the mail server
Auth Code 1- function die_with_honor($s) { die("Error: \"$s\""); } 2- $bad_user = true; require(dirname(__FILE__)."/logon.php");
Index INDEX.PHP verifies the authentication requested by LOGON.PHP by talking to the -server. After verifying login, INDEX.PHP displays 20 messages per page and also displays the number of pages that are in the INBOX. As an example, if the user has 43 messages in his INBOX, then INDEX.PHP will display the first 20 messages and 3 pages. INDEX.PHP communicates with AUTH.PHP file for user authentication purposes. INDEX.PHP also contains the HTML code to display the contents of the inbox to the user who logs into the system. INDEX.PHP also communicates with COMPOSE.PHP, DELETE.PHP and READ.PHP that perform different functions that are discussed later.
Index Page
Index PHP Code 1- $startMsg = 1; if(isset($_GET['start'])) $startMsg = $_GET['start']; $countMsg = 20; if(isset($_GET['count'])) $countMsg = $_GET['count']; 2- $messages = Array(); for($i=$startMsg; $i<$lastMsg; $i++) $messages[imap_uid($conn, $i)] = imap_headerinfo($conn, $i); imap_close($conn); ?>
Index HTML Code From: Subject: Received: Delete: Reply: $msg) { $bgcolor = ($msg->Unseen == 'U' || $msg- >Recent == 'N' ? 'lightgrey' : 'white'); ?>
Read READ.PHP communicates with the database using SQL queries to retrieve data for a particular user. It passes in the SQL query using the IMAP protocol to talk to the Florida Tech Mail Server. The use of the IMAP protocol in READ.PHP allows this system to display simple text s, s with pictures and even s with pictures containing text. The code also formats the contents of an that will be displayed to the user. Once the entire procedure of reading an and displaying the to the user has been completed, it closed the IMAP connection that was established to talk to the Florida Tech mail server.
Read Page
Read PHP Code if (!isset($struct->parts)) { $content = imap_body($conn, $uid, FT_UID); $content = " $content "; } else { for($i=1; $i parts); $i++) { $content.= imap_fetchbody($conn, $uid, "$i", FT_UID); }
Read Code HTML Subject?> [ &count= ">Inbox ] [ ">Reply ] [ &start= &count= ">Delete ] [&nbs p; Logout ]
Compose The COMPOSE.PHP file displays the HTML content required when the user has to compose an . It also contains the code to reply to an , to delete an and also to logout of a system. When a user hits the reply hyperlink at the top of the page, the entire text of the original mail is displayed in the compose window and then the user can proceed to send the reply to the concerned address.
Compose Page
Compose PHP Code 1- if(isset($_POST['to'])) { imap_mail($_POST['to'], $_POST['subject'], $_POST['body'], '', '', '', header("Location: index.php"); } $to = ''; $subject = ''; $body = ''; 2- if( isset($_GET['reply']) ) { $uid = $_GET['reply']; $conn = imap_open ("{mailhost.fit.edu}INBOX", $user, $pass); $header = imap_headerinfo($conn,imap_msgno($conn, $uid)); $struct = imap_fetchstructure($conn, $uid, FT_UID);
Compose HTML Code 1- Compose New Mail To: "> 2- [ Inbox ] [&nb sp; Logout ]
Delete DELETE.PHP allows the user to delete any message that is selected by the user. The actual delete function in PHP does not delete the message from the inbox. So we use the expunge() function to actually delete the message. Once the deletion is completed, the reordered list of s is displayed to the user.
Delete Code $conn = imap_open ("{mailhost.fit.edu}INBOX", $user, $pass); imap_delete($conn, $uid, FT_UID); imap_expunge($conn); imap_close($conn);
Logout setcookie('auth',null,-1,"/",".fit.edu"); header("Location: index.php");
THE END