Set the magic_quotes_gpc variable php.ini to Off, will automatically apply addslashes to all values submitted via GET, POST or Cookies.

Code:
if (get_magic_quotes_gpc()){ 
  $_GET = array_map('stripslashes', $_GET); 
  $_POST = array_map('stripslashes', $_POST); 
  $_COOKIE = array_map('stripslashes', $_COOKIE); 
}