Skip to content

Instantly share code, notes, and snippets.

@FootballFan141
Created January 16, 2021 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FootballFan141/bd59b8c4756a952d1bbae36ac73729ee to your computer and use it in GitHub Desktop.
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)
RewriteCond %{REQUEST_URI} commandline
RewriteRule .* / [R=301,L]
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. :-)
<?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