Archive for July, 2006

Random number in PHP

Real quick little function to get a random number using PHP.
PLAIN TEXT
PHP:

$x = rand(1,100);

The variable $x will contain a random number between 1 and 100.
It's rand(min, max) if you don't want to use 1 and 100 as your limits.

Get server operating system in PHP

This function returns 'win' if running on a Windows server and 'linux' if not running on a Windows server. It should be pretty easy to extend it to match other server operating systems, but this is all I needed.

is_safe_mode function for PHP

The following function will return TRUE if the server is running PHP in safe mode. It uses the function ini_get, which may be disabled. If ini_get is disabled then the function also returns TRUE since the assumption that any server disabling functions would probably also be running in safe mode.

Get ImageMagick version with PHP

Knowing what version of ImageMagick is usually important if you're going to be shelling to it to perform tasks. For me it was the --sepia-tone option that was added in either 6.2.1 or 6.2.2. Prior to that, using that option caused the conversion to fail.
The following function will return the numeric version of [...]

robots.txt for SimpleMachines forum

Wanting to keep pages out of the SERPS that I felt shouldn't be there I started using the following robots.txt file on a SimpleMachines forum site of mine.
PLAIN TEXT
CODE:

User-Agent: *

Disallow: /index.php?action=search

Disallow: /index.php?action=calendar

Disallow: /index.php?action=login

Disallow: /index.php?action=register

Disallow: /index.php?action=profile

Disallow: /index.php?action=stats

Disallow: /index.php?action=activate

Disallow: /index.php?action=help

Disallow: /index.php?action=admin

Disallow: /index.php?action=pm

Disallow: /index.php?action=mlist

Disallow: /index.php?action=notify

Disallow: /index.php?action=post

Disallow: /index.php?action=markasread

Disallow: /index.php?action=sendtopic

Disallow: /index.php?action=printpage

Disallow: /attachments/

Disallow: /avatars/

Disallow: /Packages/

Disallow: /sitemaps/

Disallow: /Smileys/

Disallow: /Sources/

Disallow: /Themes/

robots.txt for WordPress – short & sweet

On my first Wordpress site I went and added all of the files I didn't want search engines indexing to my robots.txt file thinking that it was necessary to keep them out of the SERPS. But Wordpress makes it easier than I was trying to make it by starting almost every file in the [...]

SEO company sending me spam

You know, I've pretty well accepted that I'm going to have email spam get through to my inbox. Even with Thunderbird's spam filtering, it still gets through. But today I got a spam message from an SEO company called The Search Doctors and it just hit the wrong nerve.

Blocking AdSense ads on your own site

One of the fears of AdSense users is that they will accidentally click on an ad on their own site and get banned by Google. I've always assumed that these fears are a little over-hyped. I just can't see one accidental click causing you to get dropped. Of course you certainly don't [...]

file_get_contents function for PHP 4

One of the functions added in PHP 5 is file_get_contents. This function allows you to just pass a file name and it will return the entire contents of the file. That's all well and good if you're using PHP5, but PHP4 is still very common.

100,000,000 spam postings blocked

Akismet recently passed the 100,000,000 mark on spam messages blocked. Based on the assumption that you spend 1 second per spam message that hits your blog, they estimate that they have save blog authors 27,777 hours by blocking these postings.
Of course as I'm writing this the count just keeps increasing. In fact, the counter is [...]