Errata (Second Edition)

This page lists the errors found in the book.

Chapter 15. Caching, Page 360

Location on the page: 
Just after Caching Data with cache_set()
Chapter: 
15. Caching
Error: 

cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = null)

Correction: 

cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $headers = null)

Description of the Error: 

The order of the second and third parameters are switched.

Chapter 15. Caching, Page 361

Location on the page: 
Code example at top (from filter.module)
Chapter: 
15. Caching
Error: 

cache_set($cid, 'cache_filter', $text, time() + (60 * 60 * 24));

Correction: 

cache_set($cid, $text, 'cache_filter', time() + (60 * 60 * 24));

Description of the Error: 

Order of second and third parameters are switched.

Chapter 16. Sessions, Page 365

Location on the page: 
Section "What Are Sessions?", 1st paragraph
Chapter: 
16. Sessions
Error: 

... PHP issues the browser a cookie containing a randomly generated 32-character ID, called PHPSESSID by default.

Correction: 

... PHP issues the browser a cookie containing a randomly generated 32-character ID. The name of the cookie is a 36-character string such as SESS41847725f5e919b45880017743781461 (which is the cookie name for this site). The apparently random 32-character ID that follows SESS is actually an MD5 hash based on the base URL of the site, or on the cookie domain if set in settings.php.

The examples of HTTP response and request headers also show the cookie name to be PHPSESSID, where it should be of the form described above.

Chapter 16. Sessions, Page 367

Location on the page: 
3rd paragraph - Caution
Chapter: 
16. Sessions
Error: 

Drupal doesn't store session information the first time an anonymous user visits a site. This is to keep evil web crawlers and robots from flooding the sessions table. As a developer, this means you cannot store session information for the first visit from an anonymous user.

Correction: 

Drupal doesn't usually store session information the first time an anonymous user visits a site. This is to keep evil web crawlers and robots from flooding the sessions table. As a developer, you should try to avoid storing session information for the first visit from an anonymous user.

Description of the Error: 

Drupal will store session information for the first page view from an anonymous visitor if data has been stored in $_SESSION. See http://api.drupal.org/api/function/sess_write/6.

Chapter 16. Sessions, Page 370

Location on the page: 
Below Table 16-2
Chapter: 
16. Sessions
Error: 

This is only done if the browser has presented a valid cookie to avoid bloating the sessions table with sessions for web crawlers.

Correction: 

To avoid bloating the sessions table with sessions for web crawlers, this is only done if the browser has presented a valid cookie, or if data has been stored in $_SESSION (e.g. by a module).

Chapter Front Matter, Page 393

Location on the page: 
Building a jQuery Voting Widget
Chapter: 
Front Matter
Error: 

create the file plus1.info

Correction: 

create the file plusone.info

Chapter 17. Using jQuery, Page 401

Location on the page: 
line 7 of function theme_plusone_widget
Chapter: 
17. Using jQuery
Error: 

Users without the 'rate content' permission are not eligible to vote. Treat them the same as the author when theming the widget.

Correction: 

replace 'if ($is_author) {' with 'if ($is_author || !user_access('rate content')) {'

Description of the Error: 

Users without 'rate content' permission are not permitted to access /plusone/vote/, so ajax or browser post fail for them.

Chapter 18. Localization, Page 416

Location on the page: 
Subtitle of Figure 18.11
Chapter: 
18. Localization
Error: 

A list of translatable strings containing the word "search" (...)

Correction: 

A list of translatable strings containing the word "Search" (...)

Description of the Error: 

In the example showed on the figure the word "Search" was the one we
searched for. "Search" is not the same as "search" because for the Locale
Module the case of letters in strings matters.

Chapter 20. Writing Secure Code, Page 456

Location on the page: 
Second and third code examples
Chapter: 
20. Writing Secure Code
Error: 

drupal_set_message(t('Your favorite color is @color', array('@color' => $color));

drupal_set_message(t('Your favorite color is %color', array('%color' => $color));

Correction: 

drupal_set_message(t('Your favorite color is @color', array('@color' => $color)));

drupal_set_message(t('Your favorite color is %color', array('%color' => $color)));

Description of the Error: 

Missing closing parentheses.

Chapter 23. Installation Profiles, Page 553

Location on the page: 
bottom
Chapter: 
23. Installation Profiles
Error: 

call to university_profile_tasks()

Correction: 

downloaded code for the profile uses university_profile_final() instead

Description of the Error: 

using hook_profile_tasks() results in db_query being undefined. hook_profile_final() which isn't even in the drupal api avoids this.