My model code
public function show_active_cat($limit,$offset) {
$query = $this->db->select()
->from('categories')
->where('status', 1)
->limit($limit, $offset)
->order_by('created', 'DESC')
->get();
return $query->result();
}
public function num_rows() {
$query = $this->db
->select('id,cat_name,parrent_id,status')
->from('categories')
->where('status',1)
->get();
return $query->num_rows();
}
Controller Code
public function categories($page = 'categories') {
if (!file_exists('application/views/public/' . $page . '.php')) {
show_404();
} else {
$this->load->library('pagination');
$config = [
'base_url' => base_url('pages/categories'),
'per_page' => 2,
'total_rows' => $this->categorymodel->num_rows(),
'uri_segment' => 3,
'full_tag_open' => "<ul class='pagination'>",
'full_tag_close' => "</ul>",
'first_tag_open' => '<li>',
'first_tag_close' => '</li>',
'last_tag_open' => '<li>',
'last_tag_close' => '</li>',
'next_tag_open' => '<li>',
'next_tag_close' => '</li>',
'prev_tag_open' => '<li>',
'prev_tag_close' => '</li>',
'num_tag_open' => '<li>',
'num_tag_close' => '</li>',
'cur_tag_open' => "<li class='active'><a>",
'cur_tag_close' => '</a></li>',
];
$this->pagination->initialize($config);
$data['cat_list'] = $this->categorymodel->show_active_cat($config['per_page'], $this->uri->segment(3));
$this->load->view('templates/public-header');
$this->load->view('public/categories',$data);
$this->load->view('templates/public-footer');
}
}
My htaccess
<IfModule authz_core_module>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Deny from all
The problem is when I try to click a panination link to get the next records then url is: http://192.168.1.66:2020/ci/pages/categories/2
Message:
404 Page Not Found
The page you requested was not found.
Here i found solution when i removed if statement and then its worked fine
`if (!file_exists('application/views/public/' . $page . '.php'))
{
show_404();
}`
Related
Controller is :
elseif ($profile_is_exsit > '0')
{
$url = DB::table('marriage_bureau')->select('title','custom_id')->where('user_id',$user_id)->first();
$title = $url->title;
$custom_id = $url->custom_id;
return redirect('marriage-bureau/{title}/{custom_id}');
}
This return redirect is generating Error. I need to generate a URL followed by the following route.
Routes in web.php
Route::get('marriage-bureau/{title}/{id}','marriage_bureau\ViewMarriageBureauController#index');
You can provide variable to the url
return redirect("marriage-bureau/{$title}/{$custom_id}");
You can do this
return redirect()->route('route name', ['title' => $title, 'custom_id' => $custom_id]);
In your controller use:
elseif ($profile_is_exsit > '0')
{
$url = DB::table('marriage_bureau')->select('title','custom_id')->where('user_id',$user_id)->first();
$title = $url->title;
$custom_id = $url->custom_id;
return redirect()->route('your-route-name', ['title' => $title, 'custom_id' => $custom_id]);
}
In your route use:
Route::get('marriage-bureau/{title}/{id}',
[
'uses'=>'marriage_bureau\ViewMarriageBureauController#index',
'as'=>'your-route-name',
]
);
am trying to capture all queries and record a log of interactions, however some queries are not being captured, this specific query for example:
$this->db->update('showtec.motoristas', $motorista);
I capture the queries using the Hooks function like this:
Hooks.php:
$hook['post_controller'] = array(
'class' => 'Db_query_log',
'function' => 'log_db_queries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
db_log.php:
<?php
class Db_query_log {
function __construct() {
}
function log_db_queries() {
$CI =& get_instance();
$CI->load->model('auditoria');
$data = array();
$queries = $CI->db->queries;
$data['id_usuario_gestor'] = $CI->auth->get_login('id_user');
foreach ($queries as $query){
if (preg_match($pattern = '/' . 'INSERT' . '/', $query)){
$queryArray = explode("`", $query);
if($queryArray[3] != 'ip'){
$data['query'] = $query;
$data['clause'] = 'insert';
break;
}
}elseif (preg_match($pattern = '/' . 'UPDATE' . '/', $query)){
$data['query'] = $query;
$data['clause'] = 'update';
break;
}elseif (preg_match($pattern = '/' . 'DELETE' . '/', $query)){
$data['query'] = $query;
$data['clause'] = 'delete';
break;
}
}
if(array_key_exists('query', $data)){
$CI->auditoria->salvarAuditoria($data);
}
}
}
I've built a simple project using Codeigniter 3 and when I send an ajax request using $.ajax method in localhost it works perfectly but I get
"403 Forbidden"
error when I do so on live server.
I set $config['csrf_protection'] = FALSE; and $config['csrf_regenerate'] = FALSE; in config.php.
This is the js code which sends data using ajax.
$.ajax({
url : '/login/authenticate',
type : 'post',
data : $(this).serialize(),
success : function(response) {
if (response.state == false) {
var msg = response.msg;
err_msg(msg);
} else {
if(response.type == "admin"){
window.location.href ='/admin';
} else {
window.location.href = '/user';
}
}
}
});
Please tell me how to resolve this issue.
This is my login controller
class Login extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('login_view');
}
//check the email and password and log the user in if the user info is correct
public function authenticate()
{
$this->load->model("userModel","user", true);
$this->load->library('form_validation');
//Form validation - codeigniter provides you with powerful form validation functionality
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE) {
$res = array('state' => false, 'msg' => validation_errors());
} else {
$type = $this->user->login($email, $password);
if ($type == "user" ) {
$res = array('state' => true, 'type' => $type, 'msg' => 'You are logged in!');
$toast = array('state' => true, 'msg' => 'You are logged in!');
$this->session->set_flashdata('toast', $toast);
}else if($type == "admin"){
$res = array('state' => true, 'type' => $type, 'msg' => 'You are logged in!');
$toast = array('state' => true, 'msg' => 'You are logged in!');
$this->session->set_flashdata('toast', $toast);
}else if ($type == -3) {
$msg = "You can't be logged in because you are not active at the moment.";
$res = array('state' => false, 'msg' => $msg);
}else if ($type == -1) {
$msg = "Wrong Password!";
$res = array('state' => false, 'msg' => $msg);
}else {
$msg = "You were not registered!";
$res = array('state' => false, 'msg' => $msg);
}
}
return $this->output
->set_content_type('application/json')
->set_output(json_encode($res));
}
}
Hi I didn't get any error while using the above code..see below images
use form name or form ID to serialize data instead of $(this).serialize()
i think you forgot to set .htaccess configuration.
so please create a new file in the root of project name it .htaccess and paste code below in it
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /pishtazan/ # this is for the subfolder in my localhost if you work online remove name of folder
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /pishtazan/index.php [PT,L] #also here you can rename/delete folder name
</IfModule>
if you don't want or it conflict your whole project simply you can edit your javascript ajax url to 'index.php/login/authenticate' and try it
I am developing a laravel 5.0 project. I don't know when or how this error occurs.
Error parsing header X-XSS-Protection: â1;mode=blockâ: expected 0
or 1 at character position 0. The default protections will be applied.
Specific in Developer > Network
X-XSS-Protection:%E2%80%9C1;mode=block%E2%80%9D
The above error shows up in console. I've read about what this means and what X-XSS-Protection is but i have no idea what should i do to fix it (because i don't even know how this error occurs) . Please feel free ask for code blocks or files and i will provide. From what i understand laravel has it's own default security which are used in http headers but i have never searched about this topic. Is there a specific file where laravel configures the http headers?
Here is my .htaccess file :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
EDIT 1 :
(I have never edit this file)
What i found after searching X-XSS-Protection : (look at the last array)
In vendor\symfony\http-foundation\Tests\ResponseHeaderBagTest.php
public function provideAllPreserveCase()
{
return array(
array(
array('fOo' => 'BAR'),
array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache')),
),
array(
array('ETag' => 'xyzzy'),
array('ETag' => array('xyzzy'), 'Cache-Control' => array('private, must-revalidate')),
),
array(
array('Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ=='),
array('Content-MD5' => array('Q2hlY2sgSW50ZWdyaXR5IQ=='), 'Cache-Control' => array('no-cache')),
),
array(
array('P3P' => 'CP="CAO PSA OUR"'),
array('P3P' => array('CP="CAO PSA OUR"'), 'Cache-Control' => array('no-cache')),
),
array(
array('WWW-Authenticate' => 'Basic realm="WallyWorld"'),
array('WWW-Authenticate' => array('Basic realm="WallyWorld"'), 'Cache-Control' => array('no-cache')),
),
array(
array('X-UA-Compatible' => 'IE=edge,chrome=1'),
array('X-UA-Compatible' => array('IE=edge,chrome=1'), 'Cache-Control' => array('no-cache')),
),
array(
array('X-XSS-Protection' => '1; mode=block'),
array('X-XSS-Protection' => array('1; mode=block'), 'Cache-Control' => array('no-cache')),
),
);
}
I am developing SaaS app and in routes i have following code
$subdomain = '';
$domain_parts = explode('.', Request::server('HTTP_HOST'));
if (count($domain_parts) == 3) {
$subdomain = $domain_parts[0];
if ($subdomain == 'www') {
$subdomain = '';
}
}
if (empty($subdomain)) {
Route::get('/', 'IndexController#showIntro');
} else {
Route::group(array('domain' => '{subdomain}.'.Config::get('app.domain'), 'before' => 'db.setup'), function() {
{
Route::get('/', array(
'as' => 'login',
'uses' => 'LoginController#showLoginForm'
));
Route::post('login', array(
'as' => 'performLogin',
'uses' => 'LoginController#performLogin'
));
Route::get('logout', array(
'as' => 'logout',
'uses' => 'LoginController#performLogout'
));
});
The problem is if subdomain is exists then it will not redirecting to login page. If i remove the content of the array in Route::group
then it will work but the array content is neccesarry, The error i am getting is NotFoundHttpExceptioni know there is a small mistake but not getting that, So any solution for this route error.
Thank you.
Your evaluation here is actually not necessary:
$subdomain = '';
$domain_parts = explode('.', Request::server('HTTP_HOST'));
if (count($domain_parts) == 3) {
$subdomain = $domain_parts[0];
if ($subdomain == 'www') {
$subdomain = '';
}
}
if (empty($subdomain)) {
Route::get('/', 'IndexController#showIntro');
} else {
You can get rid of this code, and then simply put
Route::get('/', 'IndexController#showIntro');
after the Route::group() for subdomain.
I do something like this:
Route::group(array('domain' => '{account}.' . Config::get('database.environment_url') .'') , function()
{
// Subdomain-only activity here.
}
// If there is no subdomain, Laravel will go straight to this route first.
Route::get('/' , 'IndexController#showIntro');
Hope this helps!
EDIT:: To add to this - as you know, WWW is considered a subdomain by laravel. If you want to do something special for the "www" subdomain, you can do it within the Subdomain group.