I would agree with what cvrle77 said. Modify an existing url shortening script to save user's IP using $_SERVER['REMOTE_ADDR']