Fall Semester 2004

Script for individual appointments next week.


Sat-Tue Dec 11-14
Here's another JSP from a while ago:

<% int count, right; String message = "Hello and welcome to the addition quiz!"; 
   if (session.getAttribute("count") == null || request.getParameter("reset") != null) { 
     session.setAttribute("count", new Integer(0)); count = 0; 
     session.setAttribute("right", new Integer(0)); right = 0; 
   } else { 
     count = ((Integer)(session.getAttribute("count"))).intValue(); 
     right = ((Integer)(session.getAttribute("right"))).intValue(); 
     try { 
        if (Integer.parseInt(request.getParameter("answer")) == ((Integer)(session.getAttribute("answerKey"))).intValue())
              right += 1;
        else 
              right += 0; 
     } catch (Exception e) { } 
     count += 1; 
     message = right + " out of " + count; 
     if (count == 10) { 
       message = "Final result: " + message + ". New game started "; count = 0; right = 0; 
     } else 
       message = "Your performance thus far: " + message;
     session.setAttribute("count", new Integer(count)); 
     session.setAttribute("right", new Integer(right)); 
   }
   int one = (int) (Math.random() * 100 - 50), 
       two = (int) (Math.random() * 100 - 50); 
   session.setAttribute("answerKey", new Integer(one + two)); 
 %>
<html>

<body>
<form action="<%=request.getContextPath() + request.getServletPath()%>">
  <%=message%> <p> 
  Question <%=count+1%>. <%=one%> + <%=two%> = <input type="text" name="answer"> <p> 
  <input type="submit" value="Proceed"> <input type="submit" name="reset" value="Reset"> <p> 

</form>

</body>
</html>
It is clean and compact, and a pleasure to study (I hope).

Fri Dec 10
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*; 
import ____.___._; 

public class Three extends HttpServlet {
    public void doGet(HttpServletRequest req, 
		      HttpServletResponse res) 
	throws ServletException, 
	       IOException {
	res.setContentType("text/html"); 
	PrintWriter out = res.getWriter(); 
	out.println(" Hello here are the answers. <p> "); 
        ___ _{ 
            _____._______("___.___.__._____.______"); 
        } _____ (_________ _) { 
            ______.___._______("______________________. ______________________________."); 
        }
        ___________________________________________ 
            _________________, 
            ___________________; 
        _____________________; 
        _____
            _________________________________________________________________; 
            __________________________________________________; 
            ________________; 
            ___________________________________; 
            _______________________________(

              "__________________________________________" + 
              "_________________________________________"   

            ); 
            _____________________ {

                out.println(_________________________ + 
                                   ____ + ___________________); 

            }
            _________________; 
            __________________; 

        } ______________________ { 
            _________________________________________________________________; 
        } ___________________ {
            _____________________________________; 
        }
    }
}

Tue-Thu Dec 7-9
Your Lab Twelve assignment is to enhance Homework Three with Java servlets.

Sat-Mon Dec 4-6
Script for individual appointments next week.

Wed-Fri Dec 1-3
Sample final exam questions.

Final exam is on

7:15-9:15 p.m., Wed., December 15
Please refer to the Registrar's Final Exam Schedule for more details.

Starting today:

The very popular CATCH UP DAYS are finally here!

Tue Nov 30
Notes for an overview of the programming models covered in class.

Tonight: applet to servlet communication, and JDBC.

Mon Nov 29
More examples: a servlet and its JSP.

Try them here: servlet, JSP.

Please consider why the call looks like this:

http://burrowww.cs.indiana.edu:9810/hw67/servlet/Exam?guess=eve&bet=40
Note that a call to
http://burrowww.cs.indiana.edu:9810/hw67/servlet/Exam
after the program is started would break it:

Do you know why?

You should.

(Just to make sure that a full blown example of translation is available to you.)

Wed-Sun Nov 24-28

HAPPY THANKSGIVING!

Tue Nov 23
Here's part of the code developed in class today:
______ _____._______.*;
______ _____._______.____.*;
______ ____.__.*; 

______ _____ Three _______ ___________ _

  ______ ____ _____(__________________ _______, 
                    ___________________ ________) ______ ________________, 
                                                         ___________ {

    ________.______________("_________"); 
    ___________ ___ = ________._________(); 

    HttpSession session = request.getSession(); 

    ______ ____             = _______.______________() + _______.______________(),

           _______          = (String) session.get_________("_______"), 

           _______________  = (String) _______.getAttribute("_________"),
           ________________ = (______) session.getAttribute("__________"), 
           _______________  = (String) session.___Attribute("_________"); 

    String__ _____ = {"Paper", "Rock", "________"}; 

    __ (_______ != ____) {

      ______ __________ = _______.____________("____"); 

      ___ ____ = _______.________(__________); 

      ___ _________  = _______.________(_______________); 
      ___ __________ = _______.________(________________); 
      ___ _________  = _______.________(_______________);    

      __ ((____ + 1) % 3 == __________) {
        _______ = "___ ___."; 
        _________ += 1; 
      } ____ __ ((__________ + 1) % 3 == ____) {
        _______ = "___ ____."; 
        _________ += 1; 
      } ____ {
        _______ = "____ __ _ ___."; 
      } 
      __________ = (___)(____.______() * 3); 

      ________________ = __________ + ""; 
      _______________  = _________  + ""; 
      _______________  = _________  + ""; 

    } ____ {

      _______ = "_______."; 
      _______________ = "_"; 
      _______________ = "_"; 
      ________________ = "" + (___)(____.______() * 3); 

    }

    // save the _____ (you guessed it)

    _______.setAttribute("compScore", comp___________); 
    session.___Attribute("message", _______);  
    session.setAttribute("_________", userScore______); 
    session.set_________("comp______", compChoiceString); 

    ___._______(
      "<____ ______=GET ______=" + name + ">" + 
      _______ +  
      " ___ ________ ___ ______: " + 
      names[Integer.parseInt(compChoiceString)] + 
      ", ___ __'_ ____ ____. <_> " + 
      " <_____ ______><__><__> ________ <__> ____ " + 
      "        <__><__>" + _______________ + "<__> " + _______________ + "</_____> <_> " + 

      " ____: <______ ____=\"____\">" + 
      "         <______ _____=\"_\"> _____ " + 
      "         <______ _____=\"_\"> ____ " + 
      "         <______ _____=\"_\"> ________ " + 
      "        </______> <_> " + 

      "  ____ ________ ______ _____ <_____ ____=\"______\" _____=\"_______\"> <_> " + 
      " " + 
      " </____> "
    ); 

  } 

}
(Needless to say the JSP is immediate).

Mon Nov 22
The musician in the twelve minutes video I showed Thursday in class was:
He might be coming for 5-10 min. more to class tomorrow, Tuesday, Nov 23.

Fri-Sun Nov 19-21
Here's the difference between a servlet and its JSP (as shown on Thu):
1,8c1,2
< import javax.servlet.*;
< import javax.servlet.http.*;
< import java.io.*; 
< 
< public class One extends HttpServlet {
<   public void doGet(HttpServletRequest request, 
<                     HttpServletResponse response) throws ServletException, 
<                                                          IOException {
---
> <%
> 
12c6,8
<     PrintWriter out = response.getWriter(); 
---
> 
>     // PrintWriter out = response.getWriter(); 
> 
51,70c47
<     out.println(
<       "<form method=GET action=" + name + ">" + 
<       message +  
<       " The computer has chosen: " + 
<       names[Integer.parseInt(compChoiceString)] + ", now it's your turn. <p> " + 
<       " <table border><tr><td> Computer <td> User " + 
<       "        <tr><td>" + compScoreString + "<td> " + userScoreString + "</table> <p> " + 
<       " What: <select name=\"user\">" + 
<       "         <option value=\"0\"> Paper " + 
<       "         <option value=\"1\"> Rock " + 
<       "         <option value=\"2\"> Scissors " + 
<       "        </select> <p> " + 
<       "  When finished please press <input type=\"submit\" value=\"Proceed\"> <p> " + 
<       "  <input type=\"hidden\" name=\"compScore\"  value=\"" + compScoreString  + "\"> " + 
<       "  <input type=\"hidden\" name=\"message\"    value=\"" + message          + "\"> " + 
<       "  <input type=\"hidden\" name=\"userScore\"  value=\"" + userScoreString  + "\"> " + 
<       "  <input type=\"hidden\" name=\"compChoice\" value=\"" + compChoiceString + "\"> " + 
<       " " + 
<       " </form> "
<     ); 
---
>  %> 
72c49,65
<   } 
---
>       <form method=GET action=<%=name%>>
>       <%=message%> 
>       The computer has chosen:  
>       <%=names[Integer.parseInt(compChoiceString)]%>, now it's your turn. <p>
>       <table border><tr><td> Computer <td> User 
>               <tr><td><%=compScoreString%><td><%=userScoreString%></table> <p> 
>       What: <select name="user">
>                <option value="0"> Paper 
>                <option value="1"> Rock 
>                <option value="2"> Scissors 
>               </select> <p> 
>         When finished please press <input type="submit" value="Proceed"> <p>
>         <input type="hidden" name="compScore"  value="<%=compScoreString%>"> 
>         <input type="hidden" name="message"    value="<%=message%>"> 
>         <input type="hidden" name="userScore"  value="<%=userScoreString%>"> 
>         <input type="hidden" name="compChoice" value="<%=compChoiceString%>"> 
>        </form>
74d66
< }

Thu Nov 18
Here's the code developed in class Tue night
import javax.servlet.*;
import javax._______.http.*;
import java.__.*; 

public class ___ extends ____Servlet {
  public void do___(Http_______Request request, 
                    HttpServlet________ response) ______ ServletException, 
                                                         __Exception {
    response.set_______Type("text/html"); 
    ___________ out = response.getWriter(); 
    String ____             = request.getContextPath() + request.getServletPath(),
           message          = request.getParameter("message"), 
           compScoreString  = request.get_________("compScore"),
           compChoiceString = _______.getParameter("compChoice"), 
           userScoreString  = request.getParameter("userScore"); 

    if (message != ____) {
      ______ userString = request.getParameter("____"); 

      int user = Integer.parseInt(__________); 

      int comp_____  = Integer.parseInt(compScoreString); 
      int comp______ = Integer.parseInt(compChoiceString); 
      int userScore  = Integer.parseInt(userScoreString);    

      if ((user + 1) % 3 == __________) {
        message = "You won."; 
        ____Score += 1; 
      } else if ((compChoice + 1) % 3 == ____) {
        message = "You lose."; 
        ____Score += 1; 
      } else {
        message = "____ __ _ ____"; 
      } 
      compChoice = (int)(Math.random() * 3); 

      compChoice______ = compChoice + ""; 
      ____ScoreString  = compScore  + ""; 
      ____ScoreString  = userScore  + ""; 

    } else {
      _______ = "Welcome."; 
      compScoreString = ___; 
      userScoreString = ___; 
      compChoiceString = __ + (int)(Math.random() * 3); 

    }

    out.println(
      "<form ______=GET ______=" + name + ">" + 
      message +  
      " The computer has chosen: " + compChoice______ + ", now it's your turn. <p> " + 
      " <table border><tr><td> Computer <td> User " + 
      "        <tr><td>" + compScore______ + "<td> " + userScore______ + "</table> <p> " + 
      " What: <______ name=\"user\">" + 
      "         <option value=\"_\"> Paper " + 
      "         <option value=\"1\"> ____ " + 
      "         <option value=\"2\"> Scissors " + 
      "        </select> <p> " + 
      "  When finished please press <input type=\"submit\" value=\"Proceed\"> <p> " + 
      "  <input type=\"______\" name=\"compScore\"  value=\"" + compScore______  + "\"> " + 
      "  <input type=\"hidden\" name=\"_______\"    value=\"" + message          + "\"> " + 
      "  <input type=\"hidden\" name=\"userScore\"  value=\"" + userScore______  + "\"> " + 
      "  <input type=\"hidden\" name=\"compChoice\" value=\"" + compChoice______ + "\"> " + 
      " " + 
      " </form> "
    ); 

  } 

}

Wed Nov 17
Mail processing with PHP:

Sat-Tue Nov 13-16
I didn't see too many updates on your web servers. I want to make sure I don't miss them.

So please use this picture

to clearly identify your What's New? portion of the website.

(Note that clicking on it takes it to the sample what's new I set up on the demo server).

Thu-Fri Nov 11-12
Installing Tomcat_5.0.27 is easy:

  • define environment variables appropriately

  • get the archive, uncompress, unpack

  • set $CATALINA_HOME/conf/server.xml file correctly

  • start the server (with $CATALINA_HOME/bin/startup.sh)

I will create more links to more concrete examples here but this is all there is to it!

Mon-Wed Nov 8-10
Links to just a couple more notes have been posted.

Fri-Sun Nov 5-7
Here's the code developed in class (helping with Homework Five) :
<html>
  <script>
  c_choice = Math.round(Math.random() * 2);
  names = new Array("Paper", "Rock", "Scissors");
  function process() {
    alert("User has selected: " + document.forms[0].u_choice.options[document.forms[0].u_choice.selectedIndex].value);
    c_choice = Math.round(Math.random() * 2);
    document.getElementById("c_choice").innerHTML =  names[c_choice];
  }
  </script>

  <body>

  Computer has chosen: <span id="c_choice"></span> <p>

  <script>
    document.getElementById("c_choice").innerHTML =  names[c_choice];
  </script>

  <form>
     User chooses: <select name="u_choice">
       <option value="Paper"> Paper
       <option value="Rock"> Rock
       <option value="Scissors"> Scissors
     </select>
     <p> Then the user presses <input type="button"
                                      value="Submit"
                                      onClick="process()">
  </form>
  </body>

</html>

Thu Nov 4
Here's a link with maybe useful information

Mon-Wed Nov 1-3
Lab Notes Ten, posted, describe the installation of Tomcat.

Here's the code you need for your Lab Eight work:

<?
   function get_book_cats($isbn) {

       $conn = db_connect(); 

       $query = "select dgerman_php_catboo.catid, catname 
                 from dgerman_php_categories, dgerman_php_catboo 
                 where '$isbn' = dgerman_php_catboo.isbn and
                       dgerman_php_categories.catid = dgerman_php_catboo.catid"; 

       $result = @mysql_query($query); 


       if (! $result) return false;



       $num_cats = @mysql_num_rows($result); 
       if ($num_cats == 0) return false; 



              $cat_array = array(); 

              for (
                   $count = 0; 
                   $row = @mysql_fetch_array($result); 
                   $count++
                  ) 
                $cat_array[$count] = $row; 

       if (! is_array($cat_array)) {
                     echo "No categories currently available. <br>"; 
              }



              foreach ($cat_array as $row) {

                     $url = "show_cat.php?catid=".($row["catid"]); 
                     $title = $row["catname"]; 



                     do_html_url($url, $title); 

              }


   } 
 ?>
The only question now is, where do you place it?

Sat-Sun Oct 30-31
Homework Assignment Five has been posted.

Code needed for Lab Eight to be posted soon.

Fri Oct 29
Grading the exams here some of the thoughts that came through my mind:

Thu Oct 28
Here's the code we developed in class on Tue (partially obscured) :
#!/usr/bin/perl

use CGI; 

use ___;
use MD5;

$DB = "DBI:_____:a348"; 

$________ = "a348"; 
$password = "______"; 

$DB_TABLE = "___________"; 
$SECRET = "something secret"; 

_______ = 30 * 60 * 60 * 24; # one month

$MAX_TRIES = 10; 
$ID_LENGTH = _;

__ = new CGI; 

$DBH = DBI->_______($DB, $username, $password, { PrintError => 0 }) 
       || die "Couldn't open database: ", $DBI::errstr; 

my ($session_id) = &get_session_id(); 

print $q->______, $q->start_html; 

my $state          = &get_state(___________); 
if (! $state->{message}) { 
  $state = &__________($state); 
} else { 
  $number = $q->param('number'); 
  $_____ = &calculate(______, _______); 
} 

&save_state($state, $session_id); 

&report($state); 

&show_form(); # get ready for more input 

print $q->end_html;

sub ______________ {
  &expire_old_sessions(); 
  my ($id) = $q->path_info =~ m:^/([a-h0-9]{$ID_LENGTH}):o;
  return $id if $id and &check_id($id); 
  my $session_id = &generate_id; 
  die "Couldn't make a new session_id" unless $session_id; 
  print $q->________($q->script_name() . "/$session_id"); 
  exit(0);   
}

sub ___________________ {
  $DBH->do(<<END);
DELETE FROM $DB_TABLE
  WHERE (unix_timestamp() - unix_timestamp(modified)) > $EXPIRE
END
}

sub ___________ {
  my $tries = 0; 
  my $id = &hash($SECRET . rand()); 
  while ($tries++ < __________) {
    last if 
      $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')"); 
    $id = &hash($SECRET . rand()); 
  }
  return undef if $tries >= $MAX_TRIES;
  return $id; 
}
sub hash {
  my $value = shift; 
  return substr(MD5->hexhash($value), 0, $ID_LENGTH);   
}

sub ________ {
  my $id = shift; 
  return $id 
    if $DBH->do("SELECT 1 FROM $DB_TABLE WHERE session_id = '$id'") > 0; 
  return $id 
    if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')"); 
  return ''; 
}

sub show_form {
  print $q->start_form(),  qq{
        ______ _____ ____ ______: _________________________________ <p> }, 
        "When done please press ", 
        $q->submit(-value=>'Proceed'),
        $q->end_form(); 
}

sub _________ {
  my $id = shift; 
  my $query = "SELECT * FROM _________ WHERE session_id = '$id'"; 
  my $sth = $DBH->prepare($query) || die "Prepare: ", $DBH->errstr; 
  $sth->execute || die "Execute: ", $sth->errstr;
  my $state = $sth->fetchrow_hashref;
  $sth->finish; 

  return $state; 

}

sub _________ { 

  my $state = shift; #  first param
  my $number = shift; # second param

  my $balance = $state->{_______}; 
  my $_______ = $state->{mess___}; 

  if ($number > 0 && $number < 11) {
      $balance += $number; 
      if ($balance >= 100) {
          $message = "Congratulations, you ____\n"; 
	  $balance = 0; 
	  $message .= "The current balance is $balance.\n";
      } else {
          $computer = int(rand(10)) + 1; 
	  ________________________________________________ 
	  $balance += $computer; 
	  if ($balance >= 100) {
              $message .= "The computer just won the game.\n"; 
	      _____________ 
	      $message .= "The current balance is $balance.\n"; 
	  } else {
	      $message .= "The current balance is $balance.\n"; 
	  }
      }
  } else {
      $message = "Sorry, you lost.\n"; 
      ____________; 
      $message .= "The current balance is $balance.\n";
  }

  $state->{_______} = $balance; 
  $state->{message} = ________; 

  return $state; 
}

sub __________ {
  my ($state, $id) = @_; 
  my $sth = $DBH->prepare(<<END) || die "Prepare: ", $DBH->errstr; 
UPDATE $DB_TABLE
  SET _______ = ?, _______ = ?   
  WHERE session_id = '$id'
END

  $sth->execute(@{$state}{qw(balance message)}) 
  || die "Execute: ", $DBH->errstr; 

  $sth->finish; 
}

sub ______ {
  my ($state) = @_; 
  print  qq{
          _______: $state->{balance} <p> 
          Message: $_____->{message} <p> 
  }; # note that computer choice printed is just a number 
}

sub initialize {
  my $state = shift; 
  $state = {} unless $state; 
  $state->{_______} = 0;  
  $________message_ = "_______. The current balance is: ". $state->{balance}; 

  return $state; 

}

Wed Oct 27
Here's a copy of Pavel's Hangman code from Summer 2003 (extending Lecture Notes 15).

Thu-Tue Oct 21-26
Example of a Perl program that implements the game (this is not a web script) and sample session.
#!/usr/bin/perl

while (true) {

    if ($message) { 
	$number = <STDIN>; 
        if ($number > 0 && $number < 11) {
	    $balance += $number; 
	    if ($balance >= 100) {
		$message = "Congratulations, you won.\n"; 
		$balance = 0; 
		$message .= "The current balance is $balance.\n";
	    } else {
		$computer = int(rand(10)) + 1; 
		$message = "Computer has chosen... $computer\n"; 
		$balance += $computer; 
		if ($balance >= 100) {
		    $message .= "The computer just won the game.\n"; 
		    $balance = 0; 
		    $message .= "The current balance is $balance.\n"; 
		} else {
		    $message .= "The current balance is $balance.\n"; 
		}
	    }
	} else {
	    $message = "Sorry, you lost.\n"; 
	    $balance = 0; 
	    $message .= "The current balance is $balance.\n";
        }
    } else {
	$message = "Welcome.\n"; 
        $balance = 0; 
	$message .= "The current balance is $balance.\n";
    }
    print $message; 
    print "Please enter a new number: "; 

}

print "Thanks for playing."; 

# Example of running a session with this program: 
# 
# burrowww.cs.indiana.edu% ./demo
# Welcome.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 9
# The current balance is 19.
# Please enter a new number: 10
# Computer has chosen... 2
# The current balance is 31.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 51.
# Please enter a new number: 10
# Computer has chosen... 6
# The current balance is 67.
# Please enter a new number: 10
# Computer has chosen... 7
# The current balance is 84.
# Please enter a new number: 10
# Computer has chosen... 6
# The computer just won the game.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 1
# The current balance is 11.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 31.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 51.
# Please enter a new number: 3
# Computer has chosen... 7
# The current balance is 61.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 81.
# Please enter a new number: 8
# Computer has chosen... 2
# The current balance is 91.
# Please enter a new number: 10
# Congratulations, you won.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 7
# The current balance is 17.
# Please enter a new number: -3
# Sorry, you lost.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 7
# The current balance is 17.
# Please enter a new number: 11
# Sorry, you lost.
# The current balance is 0.
# Please enter a new number: 
# 

Wed Oct 20
Here's the message sent to the distribution list today:
Date: Wed, 20 Oct 2004 15:47:07 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A348/A548 Fall 2004 Distr. List <dgerman@indiana.edu>
Subject: Labs today and tomorrow and the Midterm Exam 


Dear A348/A548 friends,

Thu and Fri I am in Savannah, GA, for a presentation to a conference (FIE
2004). http://fie.engrng.pitt.edu/fie2004/index.htm (under Authors) would
give you my paper (German, Dan-Adrian). We'll cover the paper in class at
some point in November.

The exam is proctored by Pavel Anaschenko. It's on Thu 5:30pm in class.

The exam is open-book. Labs today and tomorrow should be used to eliminate
all questions about Homework 2 and 4, Lab 7 and the Sample Midterm posted.

Please review the template posted under What's New? Wed-Thu Sep 15-16. It
should help you approach the problems uniformly. For the exam tomorrow the
technology of your choice is required: PHP or CGI with or without sessions.

For Tue please post all four implementations. CGI/DBI implementation of the
problem you will receive for the exam tomorrow will be discussed in class on
Tue so, as far as that implementation goes, significant help will be offered
then. All four implementations are due on your web sites by Tue end of day,
source code included.

If you have questions or concerns please let me know.

Good luck with your exam tomorrow.

... Adrian

Fri-Sun Oct 15-17
Here's how I would get started on the Paper-Rock-Scissors game in CGI/MySQL.

This should come in handy for Tuesday's class.

Thu Oct 14
Web notes updated, including next week.

Grading in progress.

Mon-Wed Oct 11-13
This is the second part of Homework Four:
<? session_start(); ?> 
<____><____><_____>________ ____ ____ Two (using sessions)</_____></____><____> 
<? 
  __ (________) _
    if ($age == $ageCopy) { 
      $age += 1; 
      __ ((_________) _ _ __ ___________) {
        ________ _ ___________ 
        __________ __ __ 
      _ ____ __ ((___________ _ _) _ _ __ _____) {
        ________ _ ____________   
        __________ __ __ 
      _ ____ _
        ________ _ _________________ 
      _ 
      ___________ _ ___________  
    } else { 
      $message = "You can't reload. "; 
    } 
  _ ____ _
    session_register("message");   
    session_register("age"); 
    session_register("compScore"); 
    session_register("userScore"); 
    session_register("compChoice"); 
    $message = "Welcome."; 
    $compScore = 0; 
    $userScore = 0; 
    $compChoice = rand(0, 2) ;
    $age = 0; 
  _

 __   

<____>
  <? ____ _________ ?> <_> 
  ___ ________ ___ ______: <?=___________?>, ___ __'_ ____ ____. <_>
  <_____ ______><__><__> ________ <__> ____ 
         <__><__> <?=__________?> <__> <?=__________?> </_____> <_> 
  ____: <______ ____=______>
          <______ _____=___> _____
          <______ _____=___> ____ 
          <______ _____=___> ________ 
        </______> <_> 
  ____ ________ ______ _____ <_____ ____="______" _____="_______"> <_>

  <input type="hidden" name="ageCopy"  value="<?=$age?>"> 

</____> </____></____>

Sat-Sun Oct 9-10
Here's the template for part one of Homework Four:
<html><head><title>Homework ____ Part One (______ ______)</title></head><____> 

__

  __ ($mess___) {
    if (($____ + _) % 3 == $c____hoice) {
      $mess___ = "You ____"; 
      $us___core __ 1; 
    } ____ if (($c____hoice + 1) _ 3 == $_____ {
      $mess___ = "You _____"; 
      $____Score += 1; 
    } else _
      $____age = "This is a ____"; 
    } 
    $c    hoice = _and(0, 2) ; 
  _ ____ _
    $mess___ = "________"; 
    $c_____ore = _; 
    $us___core = 0_ 
    $c____hoice = ____(0, 2) ; 
  }

 __   

<____>
  <? ___o $message; ?> <p> 
  The computer has chosen: ___$c____hoice?>, now it's your ____. <p> 
  <_____ border><tr><td> Computer <td> User 
         <tr><td> <?=$compScore?> <td> <?=$us___core?> </table> <p> 
  What: <______ name="user">
          <option value=___> Paper
          <option _____="1"> ____ 
          <______ value="_"> Scissors 
        </select> <p> 
  When finished please press <input type="submit" value="_______"> <p>
  <input type="____en" name="_____core_ ___________________core_>"> 
  <input type="hidden" name="mess___" value="__=$message?>"> 
  <_____ type="hidden" name="us___core" value="___$user__ore?>"> 
  <input type="hidden" name="c____hoice" value="____compChoice?>"> 

</form> </body></____>

Fri Oct 8
Here's the message of yesterday:
Date: Thu, 7 Oct 2004 16:39:40 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A348/A548 Fall 2004 Distr. List <dgerman@indiana.edu>
Subject: A348/A548 update


Dear A348/A548 friends,

The priority this week would be to install PHP properly. That means you
should do it on /nobackup have your own ~/apache/apache_1.3.26/phpsessions
at the end and making sure register_globals is On.

With this behind us we need to finish Homework Four right away.

For next week please make individual appointments through the script that
has been posted on What's New? under Thu Oct 7 or directly at:

    http://burrowww.cs.indiana.edu:9760/cgi-bin/fall2004/schedule

Just choose a time and type your username then click Proceed.

Please let me know if you have any questions and/or if you need any help.

... Adrian
Reminder that PHP to be installed is located (and can be found in):
frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/software/php
frilled.cs.indiana.edu%ls -ld *
-rw-r--r--  1 dgerman faculty 4832738 Jun 14 00:19 php-4.3.7.tar.gz
frilled.cs.indiana.edu%
One extra change needs to be made to php.ini:
register_globals = On
But we also need to be aware of potential security problems as well.

Thu Oct 7
Script for individual appointments next week.

Wed Oct 6
Thanks to Mike Sassman and Adrian Padilla for suggesting the example below:
#!/usr/bin/perl

use CGI; 

$pda = new CGI; 

print "Content-type: text/html\n\n"; 

if ( $pda->param('message') ) {

  $userSelection = $pda->param('helicopter'); 
  
  if ($userSelection == 0 && $pda->param('compChoice') == 0) { 
    print "Both have chosen paper: tie."; 
  } elsif ($userSelection == 0 && $pda->param('compChoice') == 1) { 
    print "User's paper beats computer's rock."; 
  } elsif ($userSelection == 0 && $pda->param('compChoice') == 2) { 
    print "User's paper loses to computer's scissors."; 
  } elsif ($userSelection == 1 && $pda->param('compChoice') == 0) { 
    print "User's rock second to computer's paper."; 
  } elsif ($userSelection == 1 && $pda->param('compChoice') == 1) { 
    print "Rock user rock computer tie."; 
  } elsif ($userSelection == 1 && $pda->param('compChoice') == 2) { 
    print "Computer scissors user rock user wins."; 
  } elsif ($userSelection == 2 && $pda->param('compChoice') == 0) { 
    print "Computer paper but user scissors wins."; 
  } elsif ($userSelection == 2 && $pda->param('compChoice') == 1) { 
    print "Paper computer, but user rock, loses."; 
  } elsif ($userSelection == 2 && $pda->param('compChoice') == 2) { 
    print "Scissors scissors tie."; 
  } else { 
    print "Boy, aren't you surprised to see this...?!"; 
  } 

} else {

  $x = int(rand(3)); 

  @choices = ("paper", "rock", "scissors"); 

  print qq{
    <form>

      The computer has chosen: $choices[$x] ($x) <p> 

      It's your turn: <select name="helicopter"> 
        <option value="0"> Paper
        <option value="1"> Rock
        <option value="2"> Scissors
      </select> <p> 

      Then push <input type="submit" value="Proceed"> 

      <input type="hidden" name="compChoice" value="$x"> 
      <input type="hidden" name="message" value="Existing user."> 

    </form> 
  }; 
} 

Sat-Tue Oct 2-5
Notes updated, including Lab Seven (which is Midterm Preparation).

You should start working on Homework Four now (same program from Homework Two).

For the following assignments you need to work the same program as for Homework Four only using:

Sun-Fri Sep 26-Oct  1
Here's where you can get PHP from:
frilled.cs.indiana.edu%pwd
/nfs/grouchy/san/r1a0l7/www/classes/a348-dger/software/php
frilled.cs.indiana.edu%ls -l
total 4728
-rw-r--r--  1 dgerman faculty 4832738 Jun 14 00:19 php-4.3.7.tar.gz
frilled.cs.indiana.edu%
As far as the extra space needed the information is here.

Fri-Sat Sep 24-25
Programs worked out in class on Thu, your help with Homework Two:
#!/usr/bin/perl

print qq{Content-type: text/html\n\n}; 

$in = $ENV{QUERY_STRING};
@pairs = split(/&/, $in); 
foreach $pair (@pairs) {
  ($nam, $val) = split(/=/, $pair); 
  $in{$nam} = $val; 
}

# foreach $k (keys %in){
#   print $k, " --> ", $in{$k}, "<p>"; 
# }

$balance = $in{balance}; 

if ($in{fun} eq "add") { $balance += $in{arg}; } 
elsif ($in{fun} eq "sub") { $balance -= $in{arg}; }
else { $balance += 0; } 

print qq{
<form method=GET action=$ENV{SCRIPT_NAME}>
  Balance: $balance <p> 
  What: <select name="fun">
          <option value="non"> Click me! 
          <option value="add"> Deposit 
          <option value="sub"> Withdraw 
        </select> <p> 
  Amount: <input type="text" name="arg"> <p> 
  When finished please press <input type="submit" value="Proceed"> <p>

  <input type="text" name="balance" value="$balance"> 

</form> 
}; 
The calculator above is yours without any limiting conditions.

Parts of the one below have been obscured, though, to not limit any participation on your part:

#!/usr/bin/perl

# state is ________ of: 
#   $mess___ 
#   $____Score 
#   $user_____
#   $comp______

# _____ is provided by the: 
#   $user 

print qq{Content-type: ____/____\n\n}; 

$in = $ENV{____________}; # what if it's POST? 
@_____ = split(/&/, $in); 
foreach $____ (@pairs) {
  ($nam, $___) = split(/=/, $pair); 
  $in{$___} = $val; 
}

# foreach $k (keys %in){
#   print $k, " --> ", $in{$k}, "<p>"; 
# }

$message = $in{message}; 
$compScore = ______________; 
$userScore = $in{userScore}; 
$__________ = $in{compChoice}; 

if (________) {
  $user = $__{user}; 
  if (($user + 1) % 3 == $compChoice) {
    $message = "________"; 
    $_________ += 1; 
  } elsif (($__________ + 1) % 3 == $user) {
    $message = "You lose."; 
    $compScore __ _; 
  } else {
    $message = "This is a tie."; 
  } 
  $compChoice = ____________; 
} else {
  $_______ = "Welcome."; 
  $compScore = 0; 
  $userScore = 0; 
  $compChoice = ___(rand(3)); 
}

print qq{
<form method=GET action=_________________>
  $message <p> 
  The computer has chosen: $compChoice, now it's your ____. <p> 
  <table border><tr><td> ________ <td> User 
         <tr><td> $compScore <td> $userScore </table> <p> 
  What: <select name="user">
          <option value="0"> _____
          <option value=___> Rock 
          <______ value="2"> Scissors 
        </select> <p> 
  When finished please press <input type="submit" value="Proceed"> <p>
  <_____ type="hidden" name="compScore" value="$compScore"> 
  <input type="______" name="_______" value="$message"> 
  <input type="hidden" name="userScore" value="__________"> 
  <input type="hidden" ____="compChoice" value="$compChoice"> 

</form> 
}; 

Thu Sep 23
Wildlife as sees it:

... both courtesy of Brandon McGhan (Spring 2003 A348/A548 student).

Grades will be updated (very late) tonight.

Wed Sep 22
The program we developed in class yesterday:
#!/usr/bin/perl

print "Content-type: text/html\n\n"; 
print qq{<html><head><title>Homework Two</title></head><body>}; 

print $ENV{QUERY_STRING}, "<p>"; 

if ($ENV{REQUEST_METHOD} eq "POST") {
  read(STDIN, $input, $ENV{CONTENT_LENGTH}); 
} else { 
  $input = $ENV{QUERY_STRING}; 
} 

$input =~ s/\+/ /g; 
@pairs = split(/&/, $input); 

foreach $pair (@pairs) {
  # print $pair, "<p>"; 
  ($nam, $val) = split(/=/, $pair); 
  $nam =~ s/%(..)/chr(hex($1))/ge; 
  $val =~ s/%(..)/chr(hex($1))/ge; 
  print $nam, " goes with ", $val, "<p>"; 
}

print qq{
<form method=POST action="$ENV{SCRIPT_NAME}">
Username: <input type="text" name="uname" size=8> <p> 
Password: <input type="password" name="pword" size=14> <p> 

When done please press <input type="submit" value="proceed"> 

</form> 
}; 

print qq{</body></html>};  

Tue Sep 21
The program developed in class last time (on Tue):
#!/usr/bin/perl

print "Content-type: text/html\n\n"; 

foreach $k (keys %ENV) {
  if ($k eq $ENV{QUERY_STRING}) {
    print $k, " --> ", $ENV{$k}, "<br>\n"; 
  } else {
    print "<a href=\"",$ENV{SCRIPT_NAME},"?$k\">$k</a> <br>\n"; 
  }
}

Today in class we will solve Homework Two. Come prepared to take notes.

Sun-Mon Sep 19-20
Please use the following link if you want to download and install SSH:
http://kb.indiana.edu/data/aelc.html
The necessary info is somewhere on that page.

Fri-Sat Sep 17-18
burrowww.cs.indiana.edu% crontab -l
0 * * * * /u/dgerman/apache/apache_1.3.26/bin/apachectl restart > /dev/null
burrowww.cs.indiana.edu% 
The entry above works (for me) and does not send e-mail.

Wed-Thu Sep 15-16
Here's a flowchart we need to study carefully:

Sat-Tue Sep 11-14
Students of the week (for last week):
Chris O'Brien Soren Packer Ronald Smith

Fri Sep 10
Here's how you make your archive available for Lab One:
burrowww.cs.indiana.edu% chmod 711 ~
burrowww.cs.indiana.edu% chmod 755 ~/public
burrowww.cs.indiana.edu% chmod 644 ~/public/whoa.tar.gz
Don't forget to move the file there, first (from lab1).

Thu Sep 9
Here's how we will be grading your Lab Assignment One:
#!/usr/bin/perl

$username = $ARGV[0];

if ($username eq "") { `yes | rm -ir wh* exp* `; print `ls -ld * `; exit; }

`cp /u/$username/public/whoa.tar.gz . `;

`gunzip whoa.tar.gz`;

`tar xvf whoa.tar`;

print `du -a exp*`;

print `more exp*/doc*/doc?.txt`;

print "Should I delete it? ";

$answer = <STDIN>;
chop($answer); 
if ($answer eq "yes") {
  `yes | rm -ir wh* exp* ` ; print ` ls -ld * `;
}

Wed Sep 8
Check this link to find out if your Lab Assignment One is accessible.

Mon Sep 6
A348 labs now meet in LH15 only please see attached schedule.

Mon-Fri Aug 31-Sep 3
First week of classes, syllabus, list of port assignments posted.


Updated by Adrian German for A348/A548