Monthly Archives: November 2013

Cookies! Nom!

In Tuesday’s class, viagra here I talked briefly about cookies, information pills but we didn’t have time to go over them in much detail. As promised, here’s some more information. First, I need to correct a mistake in the example code I demo’ed: Setting a cookie requires the built-in PHP function setcookie() and can’t be done setting the $_COOKIE array directly. This explains why my example code was behaving strangely!

Here’s a short (~4 min) video on how to set and retrieve cookies in PHP:

The video talks about using the PHP time() function to set the expiration date of the cookie. The number used to represent time there is called a Unix timestamp, in case you’re curious.

Remember that you can inspect the cookies that any site has set in your browser by using the Chrome Web Developer tools. Scroll down to the Cookies section of this page for more info.

PHP examples from week 2

The PHP example files from this week’s classes are now available to download as a zip file: Week 2 files.

What you’ll find in there:

  • boxes.php – Dynamically generates rectangular div elements of various sizes. I demo’ed this code in Tuesday’s class
  • tinyfacebook (directory) – From Wednesday’s class, prescription it’s a tiny version of Facebook! If you’re in the Tuesday section, buy information pills make sure you take a look at these.
    • all_people.php – Lists the users and links them to their profile pages.
    • profile.php – The individual profile page. It takes in a user id from the URL and uses $_GET to pull up the right person’s profile.

There is more info about $_GET, and a lot of other things, on my PHP notes page.