1 / 9

PHP Part 3

PHP Part 3. Relational Databases. Consider the following table How would you select all of User 2’s comments?. Comments. SELECT Comment, UserID FROM Comments WHERE ID = 2. Relational Databases. Consider the following tables How would you select all of Jane’s comments?. Users. Comments.

nate
Download Presentation

PHP Part 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP Part 3

  2. Relational Databases • Consider the following table • How would you select all of User 2’s comments? Comments SELECT Comment, UserID FROM Comments WHERE ID = 2

  3. Relational Databases • Consider the following tables • How would you select all of Jane’s comments? Users Comments SELECT Users.Name, Users.UserID, Comments.Comment, Comments.UserID FROM Users, Comments WHERE Users.UserID = Comments.UserID AND Users.UserID = 2

  4. Relational Databases • Consider the following tables • How would you select all of Joe’s comments? Users Comments SELECT Users.Name, Users.ID, Comments.Comment, Comments.UserID FROM Users, Comments WHERE Users.ID = Comments.UserID AND Users.ID = 1

  5. HTTP Cookies • Cookies are small files that the server embeds on the client’s computer • Cookies are sent with each HTTP request • Often used to identify a user • Cookies have • name – the name of the cookie, required • value – the value of the cookie, required • expiration – when the cookie expires, optional • path – scope of cookie, optional • domain – domain of the cookie, optional • secure – only send cookie over HTTPS, optional • HTTP-Only – only allow access by HTTP, optional

  6. PHP Cookies • Setting a Cookie • setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); • string $name, name of the cookie • string $value, value of the cookie • int $expire, Unix timestamp time()+60*60*24 • string $path, path on server ‘/’ all paths • string $domain, ‘www.example.com’ • bool $secure • bool $httponly • Must be set before any output from the script • setcookie(“user”, “Fred”); • setcookie(“user”, “Cam”, time()+3600);

  7. PHP Cookies • Getting a Cookie value • Use the $_COOKIE superglobal • $_COOKIE is an associative array of values if (isset($_COOKIE[“user”])) { echo “Welcome “ . $_COOKIE[“user”] . “<br/>”; } else { echo “Welcome guest <br/>”; }

  8. PHP Cookie • Delete a Cookie • Set its expiration value to the past if(isset($_COOKIE[“user’])) { setcookie(“user”, “”, time-3600); }

More Related