include and include_once()

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
siyaco
Forum Commoner
Posts: 26
Joined: Mon Feb 05, 2007 1:36 am
Location: Kurdistan Mountains

include and include_once()

Post by siyaco »

what is the main difference between include and include_once() and what does it mean for security. because i heard that include_once is better for security, but i did not understand exactly
thanks all advance
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

include_once is not for security. The difference is that include() will always include the file, but include_once() will not include the file if it has already been included. include_once() is to prevent variables, functions, and classes from being declared twice by including the same code again.
(#10850)
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

From php.net
include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
siyaco
Forum Commoner
Posts: 26
Joined: Mon Feb 05, 2007 1:36 am
Location: Kurdistan Mountains

Post by siyaco »

thanks
Post Reply