I thought I would take some time and increase my understanding of PHP and MySQL. I came up with an idea for a project and decided the lowest hanging fruit would be a script to track external links.
The script will reside on a go.domain.com subdomain with the name go.php. It takes a single parameter on the GET string named url, checks it for cleanness, checks that the referrer has the same domain name, then performs a 301 redirect and logs the request.
Here’s the table:
CREATE TABLE go_log
(
access_time TIMESTAMP NOT NULL DEFAULT
CURRENT_TIMESTAMP,
user_name VARCHAR(45) DEFAULT NULL,
user_ip INT UNSIGNED NOT NULL,
referer VARCHAR(500) NOT NULL,
link VARCHAR(500) NOT NULL
) ENGINE=ARCHIVE DEFAULT CHARSET=utf8;
The referer and link columns are roughly twice as big as what a Google search reveals as the longest URL, just to be safe …
[Read more]