0

even i have added "if ( ! defined('BASEPATH')) exit('No direct script access allowed'); " on top of controller .Actually I need to display data in div my ajax call: below is ajax call which calls Createcaptcha to get data but instead of data it response "No direct script access allowed"

 $(document).ready(function(){
        $.ajax({
            type: "POST",
            url: 'website/Createcaptcha',
            success: function(data){
                $("#captcha").html(data); 
            }
        });

    });

below is controller

 public function Createcaptcha(){               
        $image = $this->captcha_model->create_image();
  echo $image;

    }

Response data is displayed in div as "No direct script access allowed" , It works fine on xampp localhost

ask
  • 1
  • 1
  • 1
  • 2

5 Answers5

1

Check if your BASEPATH is set in codeigniter. It is set in index.php of root folder. Just echo the BASEPATH and see what it is printed.

Find the following in index.php

define('BASEPATH', str_replace("\\", "/", $system_path));
Somnath Paul
  • 190
  • 1
  • 6
  • 17
0

I replaced <? with <?php and everything worked fine because of php settings in server.

Bishal Paudel
  • 1,896
  • 2
  • 21
  • 28
0

Please use

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

in database.php file.

B2725
  • 352
  • 1
  • 8
0

I had a similar problem and for someone who might look for an answer for this issue, my ten cents.

In basepath website name is set as htts://www.websitename.com and client opened without https (http://www.websitename.com) and also in some cases without www (https://websitename.com or http://websitename.com).

Since either of them do not match to the basepath defined, the request is not honored as ajax request. Solution : ensure that you have proper redirection (http to https & non-www to www).

https & www redirecting answer link

PC.
  • 481
  • 7
  • 23
-1

In my case project path(base URL) was wrong.