Created
January 16, 2021 04:26
-
-
Save FootballFan141/bd59b8c4756a952d1bbae36ac73729ee to your computer and use it in GitHub Desktop.
restrict direct access to a controller in CodeIgniter (not tested much, feel free to make changes)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteCond %{REQUEST_URI} commandline | |
RewriteRule .* / [R=301,L] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Change "commandline" in .htaccess with the controller you want to restrict access to. It redirects the controller to | |
your websites homepage. | |
For me the CommandLine.php file is a controller for CLI functions, | |
"getFacebookFeed" should only be called from the command line, like in a cron job. | |
I have not tested it much, so feel free to fork and change things. :-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class CommandLine extends CI_Controller { | |
public function __construct() { | |
parent::__construct(); | |
//your code here | |
} | |
public function getFacebookFeed($limit = 6, $length = 150, $force_refresh = false) { | |
/* | |
if(is_cli()) { | |
//your code here | |
} else { | |
redirect(base_url(), 'location', 301); | |
} | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment