Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cookies and Sessions Part 2

Similar presentations


Presentation on theme: "Cookies and Sessions Part 2"— Presentation transcript:

1 Cookies and Sessions Part 2
Chapter 12 Cookies and Sessions Part 2

2 Setting Cookie Parameters
setcookie(name, value, expiration, path, host, secure, httponly) epoch – midnight on January 1, 1970 expiration – time in seconds since epoch If not set or set to 0, cookie will continue to function until the browser is closed.

3 login.php Script 12.5 on pages 397-8 ch12\script_12_05\login.php
setcookie ('user_id', $data['user_id'], time()+3600, '/', '', 0, 0); time()+3600 Current time plus 60*60 = 60 minutes

4 Expiration See Tips #2 and #3 on page 398

5 Path setcookie(name, value, expiration, path, host, secure, httponly)
setcookie ('user_id', $data['user_id'], time()+3600, '/', '', 0, 0); ‘/’ – anywhere on the domain ‘folder’ – access only in folder

6 Host setcookie(name, value, expiration, path, host, secure, httponly) setcookie ('user_id', $data['user_id'], time()+3600, '/', '', 0, 0); ‘ – access to specific host ‘ ’ – to specific IP address

7 Secure setcookie(name, value, expiration, path, host, secure, httponly) setcookie ('user_id', $data['user_id'], time()+3600, '/', '', 0, 0); 1 (true) – restricted to https

8 httponly setcookie(name, value, expiration, path, host, secure, httponly) setcookie ('user_id', $data['user_id'], time()+3600, '/', '', 0, 0); 1 (true) – only accessible through http or https (prevents some attacks)

9 logout.php Script 12.6 on page 399 ch12\script_12_06\logout.php
// Delete the cookies: setcookie ('user_id', '', time()-3600, '/', '', 0, 0); setcookie ('first_name', '', time()-3600, '/', '', 0, 0);

10 Sessions vs. Cookies See page 404

11 login.php Script 12.8 on pages 405
ch12\script_12_08\login.php

12 session_start() Must be called before anything is sent to the web browser. The first time this is called, it will attempt to send a cookie with name PHPSESSID and value a 32 hexadecimal value for the unique session id.

13 loggedin.php Script 12.9 on page 407 ch12\script_12_09\loggedin.php

14 header.html Script on page 408 ch12\script_12_10\header.html

15 logout.php Script on page 410 ch12\script_12_11\logout.php

16 Assignment #19


Download ppt "Cookies and Sessions Part 2"

Similar presentations


Ads by Google