Previous   -   Index


Tutorial Questions


  1. Experiment with the cookie, session variable and hidden form field trolley examples. Try to understand the differences in behaviour with the back and reload button when using GET/POST/COOKIE/private cache. This is a matrix of about 36 expeiments so is non-trivial.

  2. Copy the following HTML code to a file called welcome.php on a suitable web server. Add PHP code to count how many times a user returns to the page.
       <html>
       <head><title>welcome.php</title></head>
       <body>
       <p>Hello visitor, you have visited this page many times.</p>
       <p>To continue, <a href="welcome.php">click here</a></p>;
       </body>
       </html>
    
    Implement two solutions, one that uses cookies and one that uses sessions. Don't forget to put the xml declaration and xhtml1.1 doctype at the top of your solutions.

  3. How could you implement a visit counter that uses neither sessions nor cookies?

  4. JavaScript can be used to manipulate cookies. How can Session data be made available to JavaScript?

  5. Create an HTML form that allows a user to input two numbers to a PHP page and displays a coloured rectangle of a size defined by the two numbers. Extend the form to allow the user to specify the background colour of the page and the colour of the rectangle. Allow the user to specify the colours as RGB values. What input type would be most suitable?

  6. Create a PHP script based on footsie.php that displays the maximum and minimum values for each month (as opposed to the average). Here is a sample from an input file:

        May
        6000
        6400
        June
        6300
        6550
        July
        6110
        6670

    The code for this is not particularly difficult but you will need to think carefully about the HTML for the table that you are trying to generate.

    If you feel that this is all too easy, try to improve on the (pretty dreadful) scaling algorithm used in the footsie example. Not that this is particularly difficult but it is the sort of thing that consumes an anoying amount of time.

  7. Use a session to preserve the settings for Question 4.

  8. Still confused about using session variables? Have a look at this registration example. Note the use of session_destroy() to clear session data and print_r()for providing debug information.

Previous   -   Index

best viewed using Mozilla browsers
© k.mcmanus 2004
Valid XHTML 1.! . Valid CSS . WCAG priority 3 approved