jemz — 2012-11-30T01:36:44-05:00 — #1
Hi, can you help me to enlighten my mind when should i use this require_once,include_once,$_server ?
does the require_once and include_once having the same functionality?
Thank you in advance.
cups — 2012-11-30T04:14:58-05:00 — #2
When you are not sure whether an include file has already been included, possibly higher up in your include files. This can happen when you are relying on external libraries and you are not sure what is happening higher up.
The diff between include and require is in how it handles failure:
Manual page on require states:
"require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue."
The same goes for the *_once() cousins.
jemz — 2012-11-30T04:44:32-05:00 — #3
Hi cups, thank you for the reply, what about the $_SERVER ? when to use this is this also different in require?
cups — 2012-11-30T12:24:13-05:00 — #4
$_SERVER is an array of variables which are only available on the server side some to do with the script which is running, others to do with the server setup and others concerned with the request that was made for this script.
These can be very useful, to see what they contain do this on one of your scripts (not on a live server, obviously).
jemz — 2012-12-02T06:55:53-05:00 — #5
Thank you cups
starlion — 2012-12-03T09:11:29-05:00 — #6
Generally speaking, I always use include_once or require_once, unless I -know- i'm going to repeat the same output multiple times.
Call it lazy if you like, but it also helps me when I want to intercept a user - for example, when their session has timed out, and they're not logged in anymore, I want to give them the login screen again. My login page include_once's my header - but since my header would already have been called by the page they were trying to access, I dont want the header twice.
jemz — 2012-12-03T11:13:36-05:00 — #7
Oh..I see ,...thank you for the reply.