Page 1 of 1
what is the code meant
Posted: Thu Oct 20, 2011 8:38 pm
by Lphp
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
some code
not close ?> in php page , what is that code mean? why use this kind of code
thank you!
Re: what is the code meant
Posted: Thu Oct 20, 2011 9:14 pm
by Christopher
It checks to see if a constant is defined. The page cannot be accessed directly. It has to be included by another page that defines BASEPATH.
Re: what is the code meant
Posted: Thu Oct 20, 2011 10:10 pm
by twinedev
If your page ends in PHP code (ie, has no HTML after a closing
?> tag, may people will leave off the closing tag. The reason is that if you close the php tag, but then have a blank line after it, in an editor it isn't that noticeable, but if you include that file, that blank like will be sent to the browser, so you can no longer do any
header() after you included that file. (unless you have enabled output buffering)
I have gotten in the habit of just ending the file with:
or something similar so that when scrolling, I know it is the bottom for sure without the closing tag.
-Greg