My Presentation Slides – https://docs.google.com/present/edit?id=0Afxsly4_lDMxZGY4azZjN3dfMTM2Y3czbjVrOTk
A few times now I have developed code for my clients, and when I send it to them, they get an error dealing with output already being sent when something attempts to send a header… You know the classic:
Warning: Cannot modify header information – headers already sent by (output started at /home/a/public_html/wp-admin/includes/plugin.php:1721) in /home/a/public_html/wp-includes/pluggable.php on line 934
This is caused by output having already been sent to the browser, and the headers have to go before the output. Php is smart enough to clear the output buffer if possible before sending headers… So if the output buffer hasn’t been sent to the browser yet because output buffering is enabled php will clear the buffer, and send the header. But if output buffering is disabled, you get an error… And something won’t work right…
So, open up your php.ini file and set output_buffering = Off.
A Gravatar is a picture associated with an email address. It is a brilliant system that allows anyone anywhere to create a photo to be associated with an email address they have (gravatar.com verifies the email address before allowing them to edit the picture). And then makes this photo publicly accessible to anyone! (See: http://en.gravatar.com/site/implement/hash/) for full details).
All you do to get the image associated with an email address is compose a url.
Just take the email address, trim any whitespace off the ends, make it all lower case, md5 it, and the url is:
So, php code to do this is:
$emailAddress = 'Bob.cOOl@example.com'; $url = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($emailAddress)));
You can also add a size parameter to the url to get a specific size… i.e.
$emailAddress = 'Bob.cOOl@example.com'; $size = 177; $url = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($emailAddress))) . '?size=' . $size;
Check out this link for more you can do: http://en.gravatar.com/site/implement/hash/
Note: json_encode will put double quotes on the end of your string, so to fix this, you need to strip them… Use preg_replace:
I must do this every 6 months and ALWAYS have to research it…
Instead of just setting the content-type as an octet-stream like usual, specify the mime type for Excel, and the browser will open it in the right program. This isn’t JUST Ms Office, this content-type will tell the browser to open it in Open Office as well.
header(“Content-type: application/vnd.ms-excel “);
header(“Content-Disposition: attachment; filename=\”” . preg_replace(“/[^a-zA-Z0-9\s\-]/”, “”, $event_key) . “.csv\””);
The magic thing to do is to escape double quotes by making them double double quotes… And enclosing the string in quotes. Pretty easy…
echo ‘”‘ . str_replace(“\””, “\”\””, $data) . ‘”, ‘;
I was using a php sdk today where the config file is NOT a php file, but rather a file named .cfg…
The problem? You have to restrict access to this file with a .htaccess file to prevent someone from reading it. Whereas, if it were a php file, not only would you not have to prevent access to it, you also don’t have to write your own parser.
Lesson… Don’t use a cfg file, where a php config file will do.
I used to rely on the Firefox Plugin Tamper Data to get the nitty gritty deatails of http requests. Firebug has a feature that is similar as well (the net tab). But I find it buggy. Recently, a fellow developer introduced me to the HttpFox Firefox plug-in, and it is awesome!
I now use it all the time.
The only caveat, is only start it when you need it, and stop it when you are done. Leaving HttpFox running and capturing for long periods of time slows Firefox a lot.
Check it out: http://code.google.com/p/httpfox/