HTML form honeypots and autofill/autocomplete

A honeypot field in an HTML form is a hidden input field designed to work out whether or not it is a spam bot submitting your contact form, comments form or similar. For some reason I’ve never actually covered this myself on this blog so will point you in the direction of a couple of other blogs which explain how these work, and then talk about an issue I discovered recently with autofill in Google Chrome. It may also be an issue with auto complete in other browsers.

jQuery: Toggling select boxes when one changes

I was asked a couple of days ago on my get and set form values with jQuery post how to make a secondary select box appear with jQuery when the first one is changed. The first might contain a list of countries and the second one some cities which changes as the country changes, allowing the user to select both their country and city. This post shows how to do this with several hidden sub-selects, and an earlier post shows how to do it with JSON and AJAX.

Location of MySQL’s my.cnf file

MySQL’s main configuration file is my.cnf and it is located in different locations depending on the operating system, distribution and version. This post shows how to find out where MySQL will look for the config file.

Multi line strings with Javascript

This post shows how to do multi line strings with Javascript. Please note that it is likely the method presented here is not part of the Javascript/ECMA standard but it does work (and has been tested by me) in Internet Explorer 6 to 8, Firefox 1 to 3 and the current releases of Opera, Safari and Chrome.

Add to the end of each line

It’s simple… add a to the end of each line with nothing after it and you have a multi-line string:

var s = "abc
 def
 ghi
 jkl";
 

Now display the above:

window.alert(s);
 

which shows:

abcdefghijkl
 

Note that the newlines are not rendered at all, so you need to make sure the appropriate spacing or line breaks (n) etc are present in the string.

Another approach

Another approach I found is shown below, but as far as I can tell it only works in Firefox 2+ and not at all in IE, Opera, Chrome and Safari.

var s = (<r><![CDATA[abc
 def
 ghi
 jkl]]></r>).toString();
 

This does render the line breaks so if you used window.alert on the above it would show:

abc
 def
 ghi
 jkl
 

So don’t use the second approach due to lack of browser support 🙂

PHP for loops with multiple statements in each expression

PHP for loops work in the same way as other programming languages and have a useful feature where each expression between the semi-colons can have multiple statements to be executed when separated by a comma. I found this useful myself when I need to have both a zero based and 1 based index in a loop.

Categories PHP

PHP: get keywords from search engine referer url

This post shows how to use PHP to extract the keywords searched on by a user when they found your website using a seach engine. Bing, Google and Yahoo are covered here and you can easily add your own to the PHP code supplied.

Categories PHP