• Home
  • Contact
blog.biernacki.ca

Kuba's Online Workshop

  • Home
  • Contact

Codeigniter keeping bots out of your sessions table or how I cleaned up my sessions

01/06/2014 GitHub How To PHP 1 Comment

A few people have looked at ways to keep their CodeIgniter mysql sessions table clean on their apps, and the biggest culprit for ballooning session tables is due to the fact that your site gets indexed or scanned by web crawlers and various bots.

Typically with CodeIgniter sessions, you would store them in a `ci_session` table  reference in your database, so every time a bot visits your site, a new entry gets created and sits until it is cleared (which sometimes seems like never, and in many cases it is never).  You could try several approaches to combat this session spam, but I will cover the application side approach.

Use this CodeIgniter Clean Sessions (simple drop-in/plugin that I made).

ci-clean-sessions-github

Just drop in `MY_Session.php` into your `/application/library` and it will get to work blocking those pesky visitor bots. This drop-in uses the `user_agent` library to first check if that visitor is a bot and then does a simple check wether to start a session or not. All known bots (in your user_agent.php config) will be blocked from starting a session. Just make sure that your site code does not depend on a session being started, otherwise you might get some errors.

You will have to update your `config/user_agent.php` file to keep updated with any bots that come your way.  There are many lists online that people update, or you could just search through your ci_sessions and find bot user agents and insert those into the file.

codeigniter

Replacing battery on a Syma S107 RC Helicopter

Redirect user back after login using CodeIgniter

Categories
  • Android
  • Apple
  • Coldfusion
  • Cool Apps
  • CSS
  • GitHub
  • Hardware
  • How To
  • In the News
  • Javascript
  • Linux
  • PHP
  • RC Hobby
  • Reviews
  • SysAdmin
  • Thoughts & Rants
  • Tinkering
Recent Comments
  • Jim on Fixing ONKYO RC-710m Remote volume issues
  • Tony on Fixing ONKYO RC-710m Remote volume issues
  • Robert Lawrence on Fixing ONKYO RC-710m Remote volume issues
  • Dasen on Fixing ONKYO RC-710m Remote volume issues
  • Ahmed on Fixing ONKYO RC-710m Remote volume issues
RollmyBlog
  • Twitter
  • WebMojo Design
  • Windsor Ultimate
Proudly powered by WordPress | Theme: Doo by ThemeVS.