http://silo.cs.indiana.edu:46016/cgi-bin/spr2009appts001/schedule Homework One Homework Two Homework Three Homework Four: two programs are needed Homework Five: to what extent we can save state on the server side (like PHP does with sessions) when we use Perl/CGI or Python/CGI? Lab this week: Homework Five. Midterm Exam next week: Thu 03/05 a) take-home exam b) prototype to be shown in class on Thu 02/26 c) choose one of the methods available - client-side state Perl, Python, PHP - server-side state Perl, Python, PHP Post grades by Mon Mar 9, along with a solution (to be discussed in class on Tue Mar 10). Semester project: define, design, implement We will discuss projects the week of Mar 3-5: discuss process. I will post the dates for three milestones then. -- Homework Five: The Flag Quiz in Perl/CGI with server-side state 1. Create a table that will hold the sessions. This table will somhow be the equivalent of ~/apache/phpsessions -bash-3.2$ cd /nobackup/dgerman/mysql-5.0.22/ -bash-3.2$ ls -ld connect_as* -rwxr--r-- 1 dgerman faculty 106 Feb 10 13:55 connect_aslbird -rwxr--r-- 1 dgerman faculty 178 Feb 11 13:54 connect_asnobody_fromlocalhost -rwxr--r-- 1 dgerman faculty 82 Feb 6 11:47 connect_asroot -bash-3.2$ ./connect_asroot Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 35 Server version: 5.0.22-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database HomeworkFive; Query OK, 1 row affected (0.04 sec) mysql> grant all on HomeworkFive.* to 'lbird'@'silo.cs.indiana.edu'; Query OK, 0 rows affected (0.05 sec) mysql> exit Bye -bash-3.2$ ./connect_aslbird Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 36 Server version: 5.0.22-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use HomeworkFive Database changed mysql> edit UW PICO(tm) 4.10 File: /tmp/sqlYAYohG Modified create table sessions ( session_id char(8) primary key, message varchar(240), questions varchar(240), correct int, total int, anskey varchar(32), modified timestamp ); [ Wrote 10 lines ] -> ; Query OK, 0 rows affected (0.01 sec) mysql> show tables; +------------------------+ | Tables_in_HomeworkFive | +------------------------+ | sessions | +------------------------+ 1 row in set (0.01 sec) mysql> describe sessions; +------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+-------------------+-------+ | session_id | char(8) | NO | PRI | | | | message | varchar(240) | YES | | NULL | | | questions | varchar(240) | YES | | NULL | | | correct | int(11) | YES | | NULL | | | total | int(11) | YES | | NULL | | | anskey | varchar(32) | YES | | NULL | | | modified | timestamp | YES | | CURRENT_TIMESTAMP | | +------------+--------------+------+-----+-------------------+-------+ 7 rows in set (0.00 sec) mysql> -bash-3.2$ ls -l total 168 -rw------- 1 dgerman faculty 164 Feb 20 14:06 sess_39a21676d6bc70dd2a68050f478a0a3d -bash-3.2$ cat sess_39a21676d6bc70dd2a68050f478a0a3d message|s:49:"No, that was not it. Score currently: 0 out of 3.";correct|i:0;total|i:3;questions|s:34:"Australia,Spain,China,South Africa";key|s:13:"United States";-bash-3.2$ 2. Develop the program: Go to some folder 0224 in cgi-bin and create a program: one It just connects to the database. 3. Modify the program so it retrives state and user input 3.1 Add supporting code (subroutines: get_state, get_sessionID etc.) to the file 3.2 Write code to retrieve state and input When I run the program from the command line I get: -bash-3.2$ ./one Status: 302 Moved Location: /470afaab -bash-3.2$ When I call the program on-line I type this URl: http://silo.cs.indiana.edu:46016/cgi-bin/0224/one ... and the program prints Hello! and the URL changes to something like: http://silo.cs.indiana.edu:46016/cgi-bin/0224/one/ed1bc336 Furthermore the database has changed: mysql> select * from sessions; Empty set (0.00 sec) mysql> select * from sessions; Empty set (0.00 sec) mysql> select * from sessions; +------------+---------+-----------+---------+-------+--------+---------------------+ | session_id | message | questions | correct | total | anskey | modified | +------------+---------+-----------+---------+-------+--------+---------------------+ | 470afaab | NULL | NULL | NULL | NULL | NULL | 2009-02-24 14:08:49 | | ed1bc336 | NULL | NULL | NULL | NULL | NULL | 2009-02-24 14:08:58 | +------------+---------+-----------+---------+-------+--------+---------------------+ 2 rows in set (0.00 sec) mysql> ***(to be continued on Thu 02/26)***