posts

PHP Session Dropping Problem with IE 7

2009.01.26 – We were just struggling here at work with an insane problem where IE 7 (and ONLY IE 7) was dropping sessions for PHP. Literally, we would try a trivial test case of creating a session and a new session id (generated with the session_id() function) would appear each time. Checking the session_save_path showed that new sessions were being created each time. In the end, we discovered that IE 7 will not save session cookies if there is an underscore in the domain name. (Our development sites frequently have an underscore in the subdomain name – it’s amazing that we hadn’t found this out earlier.) We’ve replaced the underscore with a hyphen, and everything appears to work correctly.

Read This

OS X’ Quarantine Resolution (“File Downloaded From The Internet”)

2008.08.15 – If you’ve had the pleasure of upgrading to 10.5, you may have noticed that OS X suddenly began acting like Windows. Whenever you download a file, it now prompts you with a message, asking if you really actually want to open the file. What possessed the fevered brains of the development team is beyond my comprehension. Well, yes, thank you, I downloaded the file for a pretty effing good reason and I’m rather sure that I want to open the file that I, myself, downloaded. I wasn’t just saving it for a special occasion. Now, you can’t disable this “feature” altogether.  You may have seen the fix which enables a custom folder action for the Download folder, but this is a stopgap measure at best.  As you may have discovered, as soon as you expand a zip or other compressed archive, it will prompt you upon opening each and every file contained within. I recently found a post which describes how to disable the prompt, but only on a file-type basis.  Still, this is a great improvement, assuming you have the patience to insert your most commonly used filetypes.  (Note to self: at some point, post a comprehensive version of this file.)

Read This

BBEdit: Regular Expression Case Change Options

2008.02.08 – I’m a huge fan of Regular Expressions. They are, without a doubt, the single most powerful tool in the programmer’s toolbox. BBEdit, my favorite text editor, happens to have really excellent regular expression support. Among its features is the ability to change the case of matched text – which is really great if you’re having to reformat lists or, say, rename every function in your code. Here’s how it works. You write your usual regular expression in the Find window. In the Replace box, you prepend the normal replacement tag (\1, \2, etc) with a key character which transforms the following match. Here’s a list of available transformations:

\u
Make the next character uppercase
\U
Make all following characters uppercase until reaching another case specifier (\u, \L, \l ) or \E
\l (lowercase L)
Make the next character lowercase
\L
Make all following characters lowercase until reaching another case specifier (\u, \U, \l ) or \E
\E
End case transformation opened by \U or \L
So, a match would look like: <br /> This is UPPERCASE: \U\1\E, this is camelCase: \L\1\E\u\2<br />

Read This

Batch File Renaming

2006.07.11 – How many times have you had a bunch of files that you wanted to change the extension on? And all you really want to do is make mv work differently: mv *.jpeg *.jpg Well, if you’re on a Linux, Unix, or Mac box, you’re in luck – this is easy to achieve. All you need to do is list all of the files you’re looking for: ls ./*.jpeg …pipe that through sed, and apply a regular expression replacement (remove the jpeg): ls ./*.jpeg | sed -e 's/\.jpeg//' …and then use xargs to get the output of sed, store it in an expression, {}, and pass it to mv: ls ./*.jpeg | sed -e 's/\.jpeg//' | xargs -t -i {} mv {}.jpeg {}.jpg That should work on most boxes. Macs might freak and think that xargs -t <strong>-i</strong> {} should be xargs -t <strong>-I</strong> {}.

Read This

Mysql, PHP: Internationalization

2006.07.10 – Oh, man. This was a toughie. What follows is an account of how to deal intelligently with foreign characters and data entry in PHP/MySQL. So I’m working on a site, and realize that I need to handle foreign names within content. No fun. So I change my MySQL table to use utf8_general_ci, instead of ye ‘ol latin1_swedish_ci (which does funny things like equivolating umlaut-u to “y”), and, of course, convert all of the columns as well. Now, this looks like it’s working fine until I take my DAO and start trying to edit content, at which point it freaks out and shows foreign characters all wrong. I make sure the html document doctype is set properly, only to discover that the PHP MySQL client (i.e., Mr. mysql_query() function) is actuallystill using latin1_swedish! I hack a bit of code into my DAO, so that I can override this on a per-table basis, by having it run the following once as a normal query immediately after connecting: ** ** SET NAMES utf8; At this point, everything works great. Except for one little catch – RLIKE and REGEXP, the core of my tokenized search engine, work based on latin1_swedish again, so not only is ‘Ç’ != ‘C’, but I can’t even search within that foreign text for native characters. Which messes everything up. Anybody got any good ideas?

Read This

MySQL: The Having Clause

2006.06.22 – This one has been driving me crazy for years helpful site. Let’s say that you have a MySQL database with a bunch of users in it, and you want to see only those users that have duplicate email addresses. You’d think this would work, but it doesn’t: SELECT COUNT(*) AS count, * FROM users WHERE count > 1 GROUP BY email; The problem is that WHERE is applied before the GROUP BY, so you can’t use aggregation functions (COUNT, MAX, etc) with a WHERE. The solution is to use HAVING, which is applied after the GROUP BY: SELECT COUNT(*) AS count, * FROM users GROUP BY email HAVING count > 1; This will give the expected result.

Read This