Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.

Similar presentations


Presentation on theme: "Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2."— Presentation transcript:

1 Week seven CIT 354 Internet II

2 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2

3 3 Project 1 Presentation (Anyone?) Demonstration

4 4 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

5 5 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

6 6 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

7 7 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)

8 8 Using Cookies Set a Cookie Extract data from a cookie Amend your user authentication routines to use a cookie

9 9 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”, “55sds9809892jjsj2”, time()+14400, “/”, “.yourdoamin.com”, 0) –Counting Time (Table 16.1)

10 10 Using Cookies Setting a test Cookie Example:setcookie.php (P 241) Submitting your Form and Getting Results

11 11 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: secreatA.php and secretB.php ( P 245) Submitting your Form and Getting Results

12 12 Session Basics Start a session Add a variable to the $_session superglobal Enable a per-user access count Maintain user preference throughout multiple pages

13 13 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.

14 14 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.

15 15 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

16 16 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

17 17 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:session01.php (P 257) Submitting your Form and Getting Results

18 18 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:session02.php (P 259) Submitting your Form and Getting Results (Display Changes)

19 19 Chapter Summary Database_Driven User Authentication Using Cookies Session Basics

20 20 Homework and Project 2 Homework –Due Date: Next Week Project 2 –Due Date: Week 9


Download ppt "Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2."

Similar presentations


Ads by Google