CodeIgniter Forums
run script that is behind a protected directory - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: run script that is behind a protected directory (/thread-8424.html)



run script that is behind a protected directory - El Forum - 05-17-2008

[eluser]nigelb[/eluser]
I have written a ajax query that runs a codeigniter script. The rest of the CI application is the back end of the database.

How can I run this script but protect the rest of the CI app using protected directories.


run script that is behind a protected directory - El Forum - 05-17-2008

[eluser]Pascal Kriete[/eluser]
What do you mean with 'protected directories'? The only access point for a CI app is index.php .


run script that is behind a protected directory - El Forum - 05-17-2008

[eluser]nigelb[/eluser]
i mean htaccess password protected directories


the whole application needs to be behind it, but i want to give access to one script so that it can be called for the ajax query that we run.

The only other options I could think would be two codeigniter installations.


run script that is behind a protected directory - El Forum - 05-17-2008

[eluser]Pascal Kriete[/eluser]
I can't think of anything very nice, but I can think of a hack.

Duplicate the system/codeigniter/codeigniter.php and call it anything you want (codeigniter2 for all I care). Put it in the same folder.

In that file, right after:
Code:
$CFG =& load_class('Config');
$URI =& load_class('URI');
$RTR =& load_class('Router');
$OUT =& load_class('Output');

Force the one allowed path by doing:
Code:
$RTR->set_directory('directory_of_the_controller');  //make it blank if you're not using folders
$RTR->set_class('class_name');   // What your first uri segment would normally be
$RTR->set_method('method_name');  // What your second segment would be

Then, on the public side you create another index.php file identical to the regular one. Change the paths to the system and application folders to point to your protected directory.

At the bottom of the file change the require_once to point at your new codeigniter2.php file. Now your ajax call can call that new index.php .

It's a hack, but it should work. Remember that anything your js has access to, anyone will have access to.


run script that is behind a protected directory - El Forum - 05-18-2008

[eluser]nigelb[/eluser]
[quote author="inparo" date="1211057229"] Remember that anything your js has access to, anyone will have access to.[/quote]

With that in mind I think I will just run a second CI install and cut and paste the neccessary code to this application