PHP stdClass Object to Array

This post defines two ultra simple recursive function to convert multidimensional Objects to Arrays and multidimensional Arrays to Objects.

http://www.if-not-true-then-false.com/2009/php-tip-convert-stdclass-object-to-multidimensional-array-and-convert-multidimensional-array-to-stdclass-object/

NOTE: If this function is called as a class method, then the return line needs to be replaced with the following…

return array_map( array($this, __FUNCTION__), $d );

PHP implementation of Google Analytics

As you know the main implementation of GA is a JavaScript library which is all well and good as long as

  1. The user has JavaScript enabled
  2. Everything we want to track outputs html (so the GA code runs)

If we ever need to track page views and other events for a client who insists we catch that small minority of users with JavaScript turned off then we can us this

It can also be used in AJAX scripts and code that doesn’t actually display any html such as CSV export scripts.

https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration#_gat.GA_Tracker_._trackPageview

Prevent Robots Indexing Stuff with Response Headers

Every so often you have parts of your website that would be better off not indexed by search engines.  API calls, search result pages, PDF documents — all examples of responses which may not have value outside of the current user.  No we all know we can signal to the search engines not to index pages using a META tag, but oftentimes service calls and documents don’t get the luxury of a META tag.  Luckily you can add a header to prevent these responses from being indexed.

http://davidwalsh.name/prevent-robot-index

ERROR FIX: Warning: session_start() [function.session-start]: Cannot send session cache limiter

Usually this is just a case of some data or white space being sent to the browser before the session_start command is run. However, this error also occurs if a file is saved using UTF-8 although it works fine when saved as ANSI.

FIX: If you need the UTF-8 encoding then it will need to be saved without Byte Order Mark (BOM). Most editors have an option to save as UTF-8 without BOM; this should get rid of the error.