ini_set() vs .htaccess

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

ini_set() vs .htaccess

Post by oboedrew »

When a php directive can be set with ini_set() or in .htaccess, is there any consensus on which is preferrable and why?

The obvious difference is that ini_set() allows control per script, whereas .htaccess allows control per directory, but are there other differences that should be taken into consideration?

Thanks,
Drew
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: ini_set() vs .htaccess

Post by Christopher »

I think it is really just the practical differences. You can call ini_set() programmatically, whereas you have to edit a file to change .htaccess. There are some settings that need set before the script runs -- so php.ini or .htaccess would be required.
(#10850)
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

Re: ini_set() vs .htaccess

Post by oboedrew »

I've read that some programmers prefer to do as much as possible in their actual scripts, rather than in .htaccess, even if that means calling ini_set() at the beginning of all the scripts in a directory, rather than just using an .htaccess file for the directory. Is this just a quirky personal preference of some programmers? Or are there many web hosts that disallow .htaccess files, such that a web application is more useful in shared hosting situations if it does not require an .htaccess file?

Cheers,
Drew
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: ini_set() vs .htaccess

Post by pickle »

Duplicating a call to ini_set() is a waste of time in my opinion. If you've got a setting you know will be universal across an application/directory, put it in a central file - whether that's an .htaccess file or a central config.inc file doesn't matter. Calling ini_set() at the top of every file is very inefficient & hell to change.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply