Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 12 Cookies and Sessions Part 2. Setting Cookie Parameters setcookie(name, value, expiration, path, host, secure, httponly) epoch – midnight on.

Similar presentations


Presentation on theme: "Chapter 12 Cookies and Sessions Part 2. Setting Cookie Parameters setcookie(name, value, expiration, path, host, secure, httponly) epoch – midnight on."— Presentation transcript:

1 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 383 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 384

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); ‘www.nku.edu’ – access to specific host ‘192.168.0.1’ – 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 385 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 388

11 login.php Script 12.8 on pages 389 http://csweb.hh.nku.edu/csc301/frank/ch12/l ogin.php http://csweb.hh.nku.edu/csc301/frank/ch12/l ogin.php 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 391 ch12\script_12_09\loggedin.inc.php

14 header.html Script 12.10 on page 392 ch12\script_12_10\header.html

15 logout.php Script 12.11 on page 393 ch12\script_12_11\logout.php

16 Assignment #19 http://csweb.hh.nku.edu/csc301/frank/ch12a/ login.php http://csweb.hh.nku.edu/csc301/frank/ch12a/ login.php


Download ppt "Chapter 12 Cookies and Sessions Part 2. Setting Cookie Parameters setcookie(name, value, expiration, path, host, secure, httponly) epoch – midnight on."

Similar presentations


Ads by Google