How do I turn on magic quotes on a per script basis??
Keep in mind that magic_quotes_gpc can not be set at runtime. - PHP4 manual
Use heredoc.
you can use get_magic_quotes_gpc to test the configuration of magic_quotes and conditionally use addslashes
if (get_magic_quotes_gpc()==0) set_magic_quotes_runtime (1);
This line should be at the top of init script of every PHP engine.