How to filter out spammer website request with PHP regular expressions

Recently I got a lot spammer requests from my site, most of them are comment bot or various crawler bot. Which is cluttering my site visitor statistics panel. After some research I come up with some regular expression that can identify these requests.

Here is the function:

How to create seo friendly url for article title

Using a SEO friendly url slug for post title is common for most sites these days, most blog software like Wordpress support it. A slug url is more friendly to search engine also very convenience for your site visitors.

Nowadays, almost all search results you get from Google has such kind of url, for example

The curl error couldn't connect to host

Get this error when trying to request a web page from a PHP host using PHP curl API ... curl_exec returns FALSE curl_error is :couldn't connect to host Verbose information: * About ... out * couldn't connect to host * Closing connection #0 I try to retrieve the page in local ... . Request browser is OK. And of course the PHP web host have access to internet. So this error tells me

Functional programming in PHP and closure

One of the greatest feature of closure is treat it as an object. As known as "Closure is poor man's object".

It can make your code more elegant.

How to check IP address in an IP range with PHP

Sometimes we need to check whether an IP address located in an IP range. For example, here are two IP ranges belong to "Blue Coat" company, if it shows in Server log, means user access your website through proxy of "Blue Coat".

This post shows you how to detect IP address in IP ranges.

Simple file based object cache in PHP

Suppose you have a time consuming query but you don't need it do the real query each time because you don't want wait and the data not change very frequently . You hope to refresh it manually when needed.

This can be implemented by a simple file based cache mechanism.

A PHP script to find different lines of two text files

Its a common scenario that we need to compare two text files and find out their differences. What we want is the items that A file contains and B doesn't, for B file contains it but A doesn't.

For example, in a multi-thread program, when a thread start, it will print a log message contains the thread id, and when the thread end, it also print a message contains its thread id.

For example, in a multi-thread program, when a thread start, it will print a log message contains the thread id, and when .

Quick Sort in PHP

In PHP the array passed as value, this will the swap has no effect on the array. So remember to define the function to accept reference.

The output

Using Predis to access Redis server with PHP5

Get the Predis from GitHub.

Predis is a flexible and feature-complete PHP (>= 5.3) client library for the Redis key-value store.

Insert date to MySQL with PHP and Java

The format of MySQL datetime data type is like this:

The datetime data type has the 'YYYY-MM-DD hh:mm:ss' format, this is defined in ANSI SQL standard. The range of time is '00:00:00' to '23:59:59'. The date part ranges from '1001-01-01' to '9999-12-31'.

Previous Page 1 2 3 4 5 Next Page