Welcome Guest, Not a member yet? Register   Sign In
How do I prevent direct controller function access?
#1

[eluser]Kraig[/eluser]
I have looked around and a lot of people say to use the underscore before the function or just make it private instead of public. However, if I do this then I cannot access it from my script either. Is there another way to prevent someone from entering this directly into their address bar?

www.somesite.com/folder/controller/some_function

This is just an example....So far I have come up with an idea, but it seems like a lot of work to do every time:

Code:
public function some_function()
{
  $val = $this->input->post('val'); // Folder Name
  $val = strip_tags( trim($val) );
  $val = mysql_real_escape_string($val);
  $userID = $this->session->userdata('id');
  $duplicate = $this->account_model->validateFolderName($val);
  
  if ( !$duplicate && $this->input->post('val') ) {
   $this->db->query("INSERT INTO user_folder (user_id, name) VALUES ('".$userID."', '".$val."') ");
   $output_string['duplicate'][ ] = 'false';
   $output_string['folderID'][ ] = $this->account_model->getFolderID($val);
   echo json_encode($output_string);
  } elseif ( $duplicate && $this->input->post('val') ) {
   $output_string['duplicate'][ ] = 'true';
   echo json_encode($output_string);
  } else {
   redirect('errors/error_404', 'refresh'); // Tried to access directly
  }
}


Also how come when I enter "www.somesite.com/folder/controller/" into the address bar I don't get the "No direct script access allowed" error? I have the code below at the top of everyone of my files...minus the views (should I add it to the views?)

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


Messages In This Thread
How do I prevent direct controller function access? - by El Forum - 12-20-2012, 10:16 PM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 04:15 AM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 06:18 AM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 06:21 AM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 07:54 AM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 08:08 AM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 08:59 PM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 09:23 PM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 09:51 PM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 09:57 PM
How do I prevent direct controller function access? - by El Forum - 12-21-2012, 10:02 PM
How do I prevent direct controller function access? - by El Forum - 12-22-2012, 01:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB