Week seven CIT 354 Internet II Objectives DatabaseDriven
Week seven CIT 354 Internet II
Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2 2
Project 1 Presentation (Anyone? ) Demonstration 3
Database_Driven User Authentication Create a database table for authorized users Create a login form and script sequence that authenticates users before displaying any secrets 4
Database_Driven User Authentication Why Authenticate Anyone? – You might want to restrict access to certain members of your development team. A common type of user authentication is database-driven, in which usernames and password are kept in a database table and accessed via a login form and script. Create the User table – Run show_createtable. html 5
Database_Driven User Authentication Adding Users to Your Table Examples: show_adduser. html (P 225) do_adduser. php ( P 227) Submitting your Form and Getting Results 6
Database_Driven User Authentication Creating the Login Form Example: show_login. html (P 231) Creating the Authentication Script Example: do_authuser. php Submitting your Form and Getting Results (Trying to Authenticate Yourself) 7
Using Cookies Set a Cookie Extract data from a cookie Amend your user authentication routines to use a cookie 8
Using Cookies What’s a Cookie? – Cookies are pieces of text that are sent to a user’s Web browser. Cookies can help to create shopping carts, user communities, and personalized sites. Cookie can be used to store an unique identification string that will match a user with data held securely in a database. Setting Cookies – You must set a cookie before sending any other content to the browser. – 6 arguments (name, value, expiration, path, domain, security) – Example: setcookie(“id”, “ 55 sds 9809892 jjsj 2”, time()+14400, “/”, “. yourdoamin. com”, 0) – Counting Time (Table 16. 1) 9
Using Cookies Setting a test Cookie Example: setcookie. php (P 241) Submitting your Form and Getting Results 10
Using Cookie Variables When a Web browser accepts a cookie, you can’t extract its value until the next HTTP request is made. Using Cookie with Authentication Example: do_authuser. php (P 242) Checking for the Authentication Cookie Example: secreat. A. php and secret. B. php ( P 245) Submitting your Form and Getting Results 11
Session Basics Start a session Add a variable to the $_session superglobal Enable a per-user access count Maintain user preference throughout multiple pages 12
Session Basics Before You Begin … Check php. ini What’s a Session? – A session is the amount of time during which a user visits a site. – A session can hold all sorts of variables and values. Understanding Session Variables – A session variables ( and their values) are stored in the temporary session file on the Web server. You can access session variables through the $_SESSION superglobal. 13
Session Basics When you attempt to retrieve a session variable, the sequence goes something like this: 1. The PHP parser gets the value of PHPSESSID form the user cookie. 2. The PHP parser finds a matching temporary session file. 3. Inside the session file, the PHP parser looks for count and then finds its value (say, 76). 4. $_SESSION[count] is equal to 76. 14
Starting a Session Call the session_start() function, and PHP takes care of the rest- sending the cookie and creating the temporary file. Example: session. php (P 251) Submitting your Form and Getting Results 15
Registering and Modifying Session Variables The goal of this script is to register a variable and change its value during the course of a user session. Example: countme. php (P 253) Submitting your Form and Getting Results 16
Managing User Preferences with Sessions Starting a Session and registering Defaults – In this script, you’ll start a session and register the font_family and font_size variables. The displayed HTML will be a form that allows you to change your preferences. Example: session 01. php (P 257) Submitting your Form and Getting Results 17
Managing User Preferences with Sessions Making Preference Changes – In this script, you’ll assign the new values for font_family and font_size and display a confirmation that the changes have been made. Example: session 02. php (P 259) Submitting your Form and Getting Results (Display Changes) 18
Chapter Summary Database_Driven User Authentication Using Cookies Session Basics 19
Homework and Project 2 Homework – Due Date: Next Week Project 2 – Due Date: Week 9 20
- Slides: 20