• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where to put if ( ! defined('BASEPATH')) exit('No direct script access allowed');

#1
[eluser]sessions[/eluser]
Sorry if this has been asked hundreds of times here, I did a quick search before posting..

Where should this line go..

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

..just controllers? controllers and models?

why or why not?

Thanks

#2
[eluser]sessions[/eluser]
Do you use this line in your own projects:

if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

?

It's in the controller file in a fresh CI download.
What is it for and does it only belong in controllers or models too?

#3
[eluser]Otemu[/eluser]
Hi,

Good answers for you here http://ellislab.com/forums/viewthread/228527/ and here http://ellislab.com/forums/viewthread/228527/

#4
[eluser]sessions[/eluser]
Thanks,

That article linked to this: http://ellislab.com/forums/viewthread/93620/ where someone said: "Making sure BASEPATH is defined is just a simple way to know that CI has been loaded."

which basically answers my question. But does the line:

if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

only belong in controllers? why?

Edit: also where is BASEPATH defined in the framework? i found online people say it's defined in index.php...but which index.php? there's one in the root, controllers folder, etc. All that I checked so far didn't have it.

#5
[eluser]InsiteFX[/eluser]
BASEPATH is defined in the index.php file, the if should be placed in all CodeIgniter files at the top.

#6
[eluser]sessions[/eluser]
The constant BASEPATH is referred to at the top of all controllers that I saw. But where is it defined?

You mentioned they go at the top of all files. So you put that line of code in models too?


#7
[eluser]InsiteFX[/eluser]
I told you above it is defined in index.php

Yes place it at the top of all your files.

#8
[eluser]sessions[/eluser]
Every index.php file I've checked says this:

Code:
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

&lt;/body&gt;
&lt;/html&gt;

There is an index.php in root, controllers folder, etc. Can you tell me which index.php file it is defined in?

#9
[eluser]InsiteFX[/eluser]
If you read the other index files they have a .html extension not .php

There is only one index.php file and it is in the root.

#10
[eluser]sessions[/eluser]
Now I see it! Thank you!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.