Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14065 articles
Browse latest View live

Can't select MSSQL table

$
0
0
I am connected to a MSSQL Server (10.50.2550.0) and I want to select a table from a database where I have read permission.

The database configuration looks like this:
Code:
$db['lardis_mssql'] = array(
   'dsn'    => '',
   'hostname' => '192.168.120.xxx',
   'username' => 'username',
   'password' => 'password',
   'database' => 'LardisLog',
   'dbdriver' => 'sqlsrv',
   'dbprefix' => '',
   'pconnect' => FALSE,
   'db_debug' => (ENVIRONMENT !== 'production'),
   'cache_on' => FALSE,
   'cachedir' => '',
   'char_set' => 'utf8',
   'dbcollat' => 'utf8_general_ci',
   'swap_pre' => '',
   'encrypt' => FALSE,
   'compress' => FALSE,
   'stricton' => FALSE,
   'failover' => array(),
   'save_queries' => TRUE
);

The connection is successfull and the database has the following tables:
  • dbo.Events
  • dbo.Users
  • dbo.Networks
The query in the model looks like this:

Code:
$query = $this->db->get('Events');
//$query = $this->db->query("SELECT * FROM Events");
return $query->result_array();

The result looks like this:

Quote:A Database Error Occurred
Error Number: HY000/1
no such table: Events
SELECT * FROM "Events"
Filename: C:/xampp/htdocs/ci3/system/database/DB_driver.php
Line Number: 691

When I leave "database" in the database.php empty, I get the same result. Therefore I think there is an misconfiguration at the sql server.
could this be possible or where could be the error?

Thanks in advance

PS: In the SQL Server Management Studio the standard database of my user is "LardisLog" and the sorting is "Latin1_General_CI_AS"

Error codeigniter generates multiple sessions for the same user

$
0
0
Hello community, I am a novice in this framework. forgive my english I speak spanish and is a google translator. But a project with codeigniter 3.19 and Ion Auth 3 is created as a method of authentication and user registration.

On my local server xampp windows, a session works perfectly for each user. But in my web linux, ubuntu 16.04, vestacp, with cloudflare, I generate 10 sessions every 1 sg we are constantly having a million session records and taking into account that I have very little traffic it is supposed to be an error that creates duplicate session for each user.

session capture in all fields ip_address gives me the ip of my server.

[Image: 129832d1544475311-error-codeigniter-gene...ession.jpg]
Quote:web where I have the problem with the sessions
tvglu.net
es.tvglu.net
attached configurations, very grateful any help.
Quote:/application/config/config.php 

$config
['sess_driver'] = 'database'
$config['sess_cookie_name'] = 'cisession'
$config['sess_expiration'] = 7200
$config['sess_save_path'] = 'ci_session'
$config['sess_match_ip'] = FALSE
$config['sess_time_to_update'] = 300
$config['sess_regenerate_destroy'] = FALSE

$config['cookie_prefix']    = 'cisession'
$config['cookie_domain']    = ''
$config['cookie_path']        = '/'
$config['cookie_secure']    = FALSE
$config['cookie_httponly']     = FALSE

$config['proxy_ips'] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';  
Quote:/application/config/autoload.php 

$autoload
['libraries'] = array('ion_auth');  
Quote:tabla base de datos 

CREATE TABLE 
`ci_session` ( 
 `
idvarchar(128NOT NULL
 `
ip_addressvarchar(45NOT NULL
 `
timestampint(10unsigned NOT NULL DEFAULT '0'
 `
datablob NOT NULL
 
PRIMARY KEY (`id`), 
 
KEY `ci_sessions_timestamp` (`timestamp`) 
ENGINE=InnoDB DEFAULT CHARSET=latin1  
PHP Code:
/application/libraries/Ion_auth.php 

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

class 
Ion_auth 

 
   /** 
     * account status ('not_activated', etc ...) 
     * 
     * @var string 
     **/ 
 
   protected $status

 
   /** 
     * extra where 
     * 
     * @var array 
     **/ 
 
   public $_extra_where = array(); 

 
   /** 
     * extra set 
     * 
     * @var array 
     **/ 
 
   public $_extra_set = array(); 

 
   /** 
     * caching of users and their groups 
     * 
     * @var array 
     **/ 
 
   public $_cache_user_in_group

 
   /** 
     * __construct 
     * 
     * @return void 
     * @author Ben 
     **/ 
 
   public function __construct() 
 
   
 
       $this->load->config('ion_auth'TRUE); 
 
       $this->load->library(array('email')); 
 
       $this->lang->load('ion_auth'); 
 
       $this->load->helper(array('cookie''language','url')); 

 
       $this->load->library('session'); 

 
       $this->load->model('ion_auth_model'); 

 
       $this->_cache_user_in_group =& $this->ion_auth_model->_cache_user_in_group

 
       //auto-login the user if they are remembered 
 
       if (!$this->logged_in() && get_cookie($this->config->item('identity_cookie_name''ion_auth')) && get_cookie($this->config->item('remember_cookie_name''ion_auth'))) 
 
       
 
           $this->ion_auth_model->login_remembered_user(); 
 
       

 
       $email_config $this->config->item('email_config''ion_auth'); 

 
       if ($this->config->item('use_ci_email''ion_auth') && isset($email_config) && is_array($email_config)) 
 
       
 
           $this->email->initialize($email_config); 
 
       

 
       $this->ion_auth_model->trigger_events('library_constructor'); 
 
   

 
   /** 
     * __call 
     * 
     * Acts as a simple way to call model methods without loads of stupid alias' 
     * 
     **/ 
 
   public function __call($method$arguments
 
   
 
       if (!method_exists$this->ion_auth_model$method) ) 
 
       
 
           throw new Exception('Undefined method Ion_auth::' $method '() called'); 
 
       
 
       if($method == 'create_user'
 
       
 
           return call_user_func_array(array($this'register'), $arguments); 
 
       
 
       if($method=='update_user'
 
       
 
           return call_user_func_array(array($this'update'), $arguments); 
 
       
 
       return call_user_func_array( array($this->ion_auth_model$method), $arguments); 
 
   

 
   /** 
     * __get 
     * 
     * Enables the use of CI super-global without having to define an extra variable. 
     * 
     * I can't remember where I first saw this, so thank you if you are the original author. -Militis 
     * 
     * [MENTION=178865]Access[/MENTION]    public 
     * @param    $var 
     * @return    mixed 
     */ 
 
   public function __get($var
 
   
 
       return get_instance()->$var
 
   


 
   /** 
     * forgotten password feature 
     * 
     * @return mixed  boolian / array 
     * @author Mathew 
     **/ 
 
   public function forgotten_password($identity   //changed $email to $identity 
 
   
 
       if $this->ion_auth_model->forgotten_password($identity) )   //changed 
 
       
 
           // Get user information 
 
           $user $this->where($this->config->item('identity''ion_auth'), $identity)->where('active'1)->users()->row();  //changed to get_user_by_identity from email 

 
           if ($user
 
           
 
               $data = array( 
 
                   'identity'        => $user->{$this->config->item('identity''ion_auth')}, 
 
                   'forgotten_password_code' => $user->forgotten_password_code 
                
); 

 
               if(!$this->config->item('use_ci_email''ion_auth')) 
 
               
 
                   $this->set_message('forgot_password_successful'); 
 
                   return $data
 
               
 
               else 
                

 
                   $message $this->load->view($this->config->item('email_templates''ion_auth').$this->config->item('email_forgot_password''ion_auth'), $datatrue); 
 
                   $this->email->clear(); 
 
                   $this->email->from($this->config->item('admin_email''ion_auth'), $this->config->item('site_title''ion_auth')); 
 
                   $this->email->to($user->email); 
 
                   $this->email->subject($this->config->item('site_title''ion_auth') . ' - ' $this->lang->line('email_forgotten_password_subject')); 
 
                   $this->email->message($message); 

 
                   if ($this->email->send()) 
 
                   
 
                       $this->set_message('forgot_password_successful'); 
 
                       return TRUE
 
                   
 
                   else 
                    

 
                       $this->set_error('forgot_password_unsuccessful'); 
 
                       return FALSE
 
                   
 
               
 
           
 
           else 
            

 
               $this->set_error('forgot_password_unsuccessful'); 
 
               return FALSE
 
           
 
       
 
       else 
        

 
           $this->set_error('forgot_password_unsuccessful'); 
 
           return FALSE
 
       
 
   

 
   /** 
     * forgotten_password_complete 
     * 
     * @return void 
     * @author Mathew 
     **/ 
 
   public function forgotten_password_complete($code
 
   
 
       $this->ion_auth_model->trigger_events('pre_password_change'); 

 
       $identity $this->config->item('identity''ion_auth'); 
 
       $profile  $this->where('forgotten_password_code'$code)->users()->row(); //pass the code to profile 

 
       if (!$profile
 
       
 
           $this->ion_auth_model->trigger_events(array('post_password_change''password_change_unsuccessful')); 
 
           $this->set_error('password_change_unsuccessful'); 
 
           return FALSE
 
       

 
       $new_password $this->ion_auth_model->forgotten_password_complete($code$profile->salt); 

 
       if ($new_password
 
       
 
           $data = array( 
 
               'identity'     => $profile->{$identity}, 
 
               'new_password' => $new_password 
            
); 
 
           if(!$this->config->item('use_ci_email''ion_auth')) 
 
           
 
               $this->set_message('password_change_successful'); 
 
               $this->ion_auth_model->trigger_events(array('post_password_change''password_change_successful')); 
 
                   return $data
 
           
 
           else 
            

 
               $message $this->load->view($this->config->item('email_templates''ion_auth').$this->config->item('email_forgot_password_complete''ion_auth'), $datatrue); 

 
               $this->email->clear(); 
 
               $this->email->from($this->config->item('admin_email''ion_auth'), $this->config->item('site_title''ion_auth')); 
 
               $this->email->to($profile->email); 
 
               $this->email->subject($this->config->item('site_title''ion_auth') . ' - ' $this->lang->line('email_new_password_subject')); 
 
               $this->email->message($message); 

 
               if ($this->email->send()) 
 
               
 
                   $this->set_message('password_change_successful'); 
 
                   $this->ion_auth_model->trigger_events(array('post_password_change''password_change_successful')); 
 
                   return TRUE
 
               
 
               else 
                

 
                   $this->set_error('password_change_unsuccessful'); 
 
                   $this->ion_auth_model->trigger_events(array('post_password_change''password_change_unsuccessful')); 
 
                   return FALSE
 
               

 
           
 
       

 
       $this->ion_auth_model->trigger_events(array('post_password_change''password_change_unsuccessful')); 
 
       return FALSE
 
   

 
   /** 
     * forgotten_password_check 
     * 
     * @return void 
     * @author Michael 
     **/ 
 
   public function forgotten_password_check($code
 
   
 
       $profile $this->where('forgotten_password_code'$code)->users()->row(); //pass the code to profile 

 
       if (!is_object($profile)) 
 
       
 
           $this->set_error('password_change_unsuccessful'); 
 
           return FALSE
 
       
 
       else 
        

 
           if ($this->config->item('forgot_password_expiration''ion_auth') > 0) { 
 
               //Make sure it isn't expired 
 
               $expiration $this->config->item('forgot_password_expiration''ion_auth'); 
 
               if (time() - $profile->forgotten_password_time $expiration) { 
 
                   //it has expired 
 
                   $this->clear_forgotten_password_code($code); 
 
                   $this->set_error('password_change_unsuccessful'); 
 
                   return FALSE
 
               
 
           
 
           return $profile
 
       
 
   

 
   /** 
     * register 
     * 
     * @return void 
     * @author Mathew 
     **/ 
 
   public function register($username$password$email$additional_data = array(), $group_ids = array()) //need to test email activation 
 
   
 
       $this->ion_auth_model->trigger_events('pre_account_creation'); 

 
       $email_activation $this->config->item('email_activation''ion_auth'); 

 
       if (!$email_activation
 
       
 
           $id $this->ion_auth_model->register($username$password$email$additional_data$group_ids); 
 
           if ($id !== FALSE
 
           
 
               $this->set_message('account_creation_successful'); 
 
               $this->ion_auth_model->trigger_events(array('post_account_creation''post_account_creation_successful')); 
 
               return $id
 
           
 
           else 
            

 
               $this->set_error('account_creation_unsuccessful'); 
 
               $this->ion_auth_model->trigger_events(array('post_account_creation''post_account_creation_unsuccessful')); 
 
               return FALSE
 
           
 
       
 
       else 
        

 
           $id $this->ion_auth_model->register($username$password$email$additional_data$group_ids); 

 
           if (!$id
 
           
 
               $this->set_error('account_creation_unsuccessful'); 
 
               return FALSE
 
           

 
           $deactivate $this->ion_auth_model->deactivate($id); 

 
           if (!$deactivate
 
           
 
               $this->set_error('deactivate_unsuccessful'); 
 
               $this->ion_auth_model->trigger_events(array('post_account_creation''post_account_creation_unsuccessful')); 
 
               return FALSE
 
           

 
           $activation_code $this->ion_auth_model->activation_code
 
           $identity        $this->config->item('identity''ion_auth'); 
 
           $user            $this->ion_auth_model->user($id)->row(); 

 
           $data = array( 
 
               'identity'   => $user->{$identity}, 
 
               'id'         => $user->id
 
               'email'      => $email
 
               'activation' => $activation_code
 
           ); 
 
           if(!$this->config->item('use_ci_email''ion_auth')) 
 
           
 
               $this->ion_auth_model->trigger_events(array('post_account_creation''post_account_creation_successful''activation_email_successful')); 
 
               $this->set_message('activation_email_successful'); 
 
                   return $data
 
           
 
           else 
            

 
               $message $this->load->view($this->config->item('email_templates''ion_auth').$this->config->item('email_activate''ion_auth'), $datatrue); 

 
               $this->email->clear(); 
 
               $this->email->from($this->config->item('admin_email''ion_auth'), $this->config->item('site_title''ion_auth')); 
 
               $this->email->to($email); 
 
               $this->email->subject($this->config->item('site_title''ion_auth') . ' - ' $this->lang->line('email_activation_subject')); 
 
               $this->email->message($message); 

 
               if ($this->email->send() == TRUE
 
               
 
                   $this->ion_auth_model->trigger_events(array('post_account_creation''post_account_creation_successful''activation_email_successful')); 
 
                   $this->set_message('activation_email_successful'); 
 
                   return $id
 
               
 
            
            


 
           $this->ion_auth_model->trigger_events(array('post_account_creation''post_account_creation_unsuccessful''activation_email_unsuccessful')); 
 
           $this->set_error('activation_email_unsuccessful'); 
 
           return FALSE
 
       
 
   

 
   /** 
     * logout 
     * 
     * @return void 
     * @author Mathew 
     **/ 
 
   public function logout() 
 
   
 
       $this->ion_auth_model->trigger_events('logout'); 

 
       $identity $this->config->item('identity''ion_auth'); 
 
               $this->session->unset_userdata( array($identity => '''id' => '''user_id' => '') ); 

 
       //delete the remember me cookies if they exist 
 
       if (get_cookie($this->config->item('identity_cookie_name''ion_auth'))) 
 
       
 
           delete_cookie($this->config->item('identity_cookie_name''ion_auth')); 
 
       
 
       if (get_cookie($this->config->item('remember_cookie_name''ion_auth'))) 
 
       
 
           delete_cookie($this->config->item('remember_cookie_name''ion_auth')); 
 
       

 
       //Destroy the session 
 
       $this->session->sess_destroy(); 

 
       //Recreate the session 
 
       if (substr(CI_VERSION01) == '2'
 
       
 
           $this->session->sess_create(); 
 
       
 
       else 
        

 
           $this->session->sess_regenerate(TRUE); 
 
       

 
       $this->set_message('logout_successful'); 
 
       return TRUE
 
   

 
   /** 
     * logged_in 
     * 
     * @return bool 
     * @author Mathew 
     **/ 
 
   public function logged_in() 
 
   
 
       $this->ion_auth_model->trigger_events('logged_in'); 

 
       return (bool) $this->session->userdata('identity'); 
 
   

 
   /** 
     * logged_in 
     * 
     * @return integer 
     * @author jrmadsen67 
     **/ 
 
   public function get_user_id() 
 
   
 
       $user_id $this->session->userdata('user_id'); 
 
       if (!empty($user_id)) 
 
       
 
           return $user_id
 
       
 
       return null
 
   


 
   /** 
     * is_admin 
     * 
     * @return bool 
     * @author Ben Edmunds 
     **/ 
 
   public function is_admin($id=false
 
   
 
       $this->ion_auth_model->trigger_events('is_admin'); 

 
       $admin_group $this->config->item('admin_group''ion_auth'); 

 
       return $this->in_group($admin_group$id); 
 
   

 
   /** 
     * in_group 
     * 
     * @param mixed group(s) to check 
     * @param bool user id 
     * @param bool check if all groups is present, or any of the groups 
     * 
     * @return bool 
     * @author Phil Sturgeon 
     **/ 
 
   public function in_group($check_group$id=false$check_all false
 
   
 
       $this->ion_auth_model->trigger_events('in_group'); 

 
       $id || $id $this->session->userdata('user_id'); 

 
       if (!is_array($check_group)) 
 
       
 
           $check_group = array($check_group); 
 
       

 
       if (isset($this->_cache_user_in_group[$id])) 
 
       
 
           $groups_array $this->_cache_user_in_group[$id]; 
 
       
 
       else 
        

 
           $users_groups $this->ion_auth_model->get_users_groups($id)->result(); 
 
           $groups_array = array(); 
 
           foreach ($users_groups as $group
 
           
 
               $groups_array[$group->id] = $group->name
 
           
 
           $this->_cache_user_in_group[$id] = $groups_array
 
       
 
       foreach ($check_group as $key => $value
 
       
 
           $groups = (is_string($value)) ? $groups_array array_keys($groups_array); 

 
           /** 
             * if !all (default), in_array 
             * if all, !in_array 
             */ 
 
           if (in_array($value$groups) xor $check_all
 
           
 
               /** 
                 * if !all (default), true 
                 * if all, false 
                 */ 
 
               return !$check_all
 
           
 
       
 
       /** 
         * if !all (default), false 
         * if all, true 
         */ 
 
       return $check_all
 
   

Smart cache library

$
0
0
We have created a free smart cache library for CodeIgniter and made it available in Github at https://github.com/msnisha/smart-cache If anyone interested please download and use it. 

Features

1. Partial caching of views
2. Keeping dynamic session variable within cached files using hook. (Example Username in cached header)
3. Conditionally accessing cache content.

append part of an object in javascript

$
0
0
I have a javascript array call myArray. I set the first two items with:

myArray["email"]=jsonResponse["email"];

myArray["photo"]=photo;

I want to append some values on to the end of it in a function called

send_to_backend_logger_survey(request, sender, sendResponse)
{
ArrayPart=request.values;
var myArray2=myArray.concat(ArrayPart);   << causes error
myArray.push(ArrayPart);                           <<also causes error
}

I tried both the concat and also the push but neither works. request is an object
task: "log_results_survey"
values: array(3)

I am trying to append just the values of array(3) onto myArray. What am I doing wrong?

set_cookie() doesn't work with redirect()

$
0
0
Hello,
This is my code:

PHP Code:
namespace App\Controllers;
use 
CodeIgniter\Controller;

class 
Home extends Controller
{
    public function 
__construct()
 
 {
 
   helper(['cookie']);
 
 }
    public function 
page1()
    {
        
set_cookie('test''testvalue-'.time(), time() + 86400);
        return 
redirect()->to('page2');
    }
    public function 
page2()
    {
        echo 
get_cookie('test');
    }


Redirect is working but there is no 'test' cookie on page2. Please help.

Migrate CI2 to CI3 (USA ONLY)

$
0
0
We are looking for a developer to help us to migrate from CI2 to CI3 through these 21 Steps .. . https://www.codeigniter.com/user_guide/installation/upgrade_300.html

We seek someone that has the ability to complete this migration process and can make it as streamlined as possible for the transition.

We have an "admin" and "client" area which has around 45 models and around 50 controllers total between both areas.


Please contact me if you are inside the USA and have CI2-CI3 migration experience.

xaiborweb

$
0
0
@xaiborweb

No one can reply to you because you private messaging turned off.

Codeigniter + Infinity scroll help

$
0
0
Hey guys,
I was wondering, has anyone made a project with infinite scroll and filtering data with "GET" parameters in url? Do you know any good examples to begin with? 
Since every tut i found on internet was about infinite scroll and not with data filtering using query string parameters. 

Should i make two different controllers (sth like "index" and "entries") or can i achieve it with a single controller?

Note that i don't want to refresh the page on every dropdown change, i just want to refresh the "div" content.

I hope i made myself clear! If you need any further clarification feel free to ask!

Thanks!

Array Randomizer?

$
0
0
Hi everyone.

I want to distribute/assign some data randomly but even amount from an array of users to an array of data.

Here's an example:

I have an array of user ids:
PHP Code:
$users = array(204725210194); 

Then the array of data:
PHP Code:
$data = array(
 
   array('department' => '???''datecreated' => '???'),
 
   array('department' => '???''datecreated' => '???'),
 
   array('department' => '???''datecreated' => '???'),
 
   array('department' => '???''datecreated' => '???'),
 
   array('department' => '???''datecreated' => '???'),
 
   array('department' => '???''datecreated' => '???'),
 
   array('department' => '???''datecreated' => '???'),
 
   array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???'),
    array('department' => '???''datecreated' => '???')
);

// Just assume that we have real data :) 

And the result should be like this (to be used by Query Builder's insert_batch()):
PHP Code:
$data = array(
 
   array('department' => '???''datecreated' => '???''assignee' => '20'),
 
   array('department' => '???''datecreated' => '???''assignee' => '210'),
 
   array('department' => '???''datecreated' => '???''assignee' => '25'),
 
   array('department' => '???''datecreated' => '???''assignee' => '194'),
 
   array('department' => '???''datecreated' => '???''assignee' => '47'),
 
   array('department' => '???''datecreated' => '???''assignee' => '20'),
 
   array('department' => '???''datecreated' => '???''assignee' => '25'),
 
   array('department' => '???''datecreated' => '???''assignee' => '194'),
    array('department' => '???''datecreated' => '???''assignee' => '20'),
    array('department' => '???''datecreated' => '???''assignee' => '194'),
    array('department' => '???''datecreated' => '???''assignee' => '210'),
    array('department' => '???''datecreated' => '???''assignee' => '47'),
    array('department' => '???''datecreated' => '???''assignee' => '210'),
    array('department' => '???''datecreated' => '???''assignee' => '25'),
    array('department' => '???''datecreated' => '???''assignee' => '20'),
    array('department' => '???''datecreated' => '???''assignee' => '210'),
    array('department' => '???''datecreated' => '???''assignee' => '47')
); 

Now, I want to assign (from the example) 17 rows to 5 users. So 3 for each user (and the remaining 2 will be either distributed to a random user or to the last person). We want this to be random. I tried to code it myself but failed.

How can I achieve this? Any help?
Thank you very much Smile

favicon.ico 404 for the forum

$
0
0
Hello guys,

Please check why the wonderful flames do not light the CI forum's tab.

Code:
https://forum.codeigniter.com/favicon.ico gives 404

[Image: ci-forum-favicon-404-thumb.png]

unexpected T_CONST--Help Please

$
0
0
One of the four web sites I have created with CI has suddenly started getting this error:

Parse error: syntax error, unexpected T_CONST in /home3/billhogs/public_html/ccbridgeclub/system/core/CodeIgniter.php on line 58

I read a thread here in May that suggested reloading the system directory.  The website was running 3.1.3 so I upgraded to 3.1.9 (renamed the 3.1.3 application and system dirs and uploaded 3.1.9 dirs along with the index.php).

I get the same error in the new 3.1.9.  Confused

The php is 7.0.x

Any help will be greatly appreciated and I will report what finally solved the issue.

Thanks in advance.


Bill

Codeigniter Get List all Classes and Methods

$
0
0
Hello CI patrons. 

I am just creating a simple library to get list all classes and methods on HMVC structure, i called the function on MY_Controller but here something wrong to get methods
and when i var_dump it got result like this 
[Image: image.png]

,there's something wrong with my code ? 

Thank you


PHP Code:
[color=#333333]public static function get_class_and_methods()
[/color]
    {

        // $classes = get_declared_classes();



        $appdir     APPPATH."modules";

        $appdirScan array_diff(scandir($appdir), array('.''..'));

        echo "<pre>";

        $arrAllModules = [];

    

        
foreach ($appdirScan as $keyParent => $module) {

            $scanperModule array_diff(preg_grep('~\.(php|phtml)$~'scandir($appdir."/".$module."/controllers")), array('.''..'));

            $arrAllModules[] = $scanperModule;



            foreach ($scanperModule as $keyFChild => $value) {

                // $a = file_get_contents($appdir."/".$module."/controllers/".$value);

                $classes self::getClassNameFromFile($appdir."/".$module."/controllers/".$value);

                $methods get_class_methods($classes);

                var_dump ($methods);

                // $aUserMethods = array();

                // if(is_array($methods)){

                    // foreach($methods as $method) {

                        // var_dump ($method);

                        // if($method != '__construct' && $method != 'get_instance' && $method != $classes && $method != "setOutput" && $method != "checkAjaxSession" && $method != "setDeniedPage" && $method != "debug" && $method != "__get") {

                        //     $aUserMethods[] = $method;

                        // }

                    // }

                // }

            }

        }

        // $flatten = array_flatten(array_merge($arrAllModules));



        die();



    }



    private static function getClassNameFromFile($filePathName)

    {

        $php_code file_get_contents($filePathName);



        $classes = array();

        $tokens token_get_all($php_code);

        $count count($tokens);

        for ($i 2$i $count$i++) {

            if ($tokens[$i 2][0] == T_CLASS

                
&& $tokens[$i 1][0] == T_WHITESPACE

                
&& $tokens[$i][0] == T_STRING

            
) {



                $class_name $tokens[$i][1];

                $classes[] = $class_name;

            }

        }



        return $classes[0];

    }





    function array_flatten($array) { 

        
if (!is_array($array)) { 

            
return FALSE; 

        
} 

          

        $result 
= array(); 

        
foreach ($array as $key => $value) { 

            
if (is_array($value)) { 

              $result 
array_merge($resultarray_flatten($value)); 

            
} 

            
else { 

              $result
[$key] = $value; 

            
} 

        
} 

          
return $result;
[
color=#333333]    } 
[/color

Alternate to use keyword

$
0
0
I would like to use this library/tool with CI3:

https://github.com/webonyx/graphql-php

It is normal OOP PHP so it uses namespaces and the 'use' keyword. How do I go about converting that to Codeigniter that doesn't? Do I just go thru all the files and change then to require('')?

Admin password/email changed and he still logged in and carried operations

$
0
0
Hello,
A  system developed with  Codeigniter is It is giving us admin log issues.

When Admin  password is changed  in DB, the  Admins is still logged in and carry operations
When  the admin  email is changed in DB , the same admin is still logged on and carry operations.
When both email and password is changed  in DB , the still logged on and carried operation.

Please, how can we resolve this?
How can the admin be logged of immediately hiw password or Email is Changed? 

Any suggestion will be help.


Thank you in advance.

HMVC broken in php 7.3 -- help

$
0
0
Hi, 

I am using the HMVC and on php7.3, I get this: 

Code:
A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: MX/Router.php

Line Number: 239

Backtrace:

File: /web/application/third_party/MX/Router.php
Line: 239
Function: strpos

File: /web/application/third_party/MX/Router.php
Line: 101
Function: _set_default_controller

File: /web/public/index.php
Line: 315
Function: require_once

Though this is a CI forum,  I do not know how to ask help from the HMVC page: https://bitbucket.org/wiredesignz/codeig...sions-hmvc
If someone knows what to do, please let me know. 
Thanks

CodeIgniter Transactions - trans_status returns TRUE but nothing commited

$
0
0
Problem:
I have written a function in my model to insert an order into my database. I am using transactions to make sure that everything commits or else it will be rolled back.

My problem is that CodeIgniter is not showing any database errors, however it is rolling back the transaction but then returning TRUE for trans_status. However, this only happens if there is a discount on the order. If there is no discount on the order, everything commits and works properly.

I am currently using CodeIgniter 3.19, PHP (7.2), and mySQL (5.7), Apache 2.4.

The function logic works as such:
  1. Inserts the order array into tbl_orders
  2. Saves order_id, and goes through each of the order products (attaches order_id) and inserts the product in tbl_order_products,
  3. Saves order_product_id and attaches it to an array of users attendance options and inserts that into tbl_order_attendance
  4. Takes the payment transaction array (attaches the order_id) and inserts that into tbl_transactions
  5. IF there is a discount on the order, it decreases the discount_redeem_count (number of redeemable discount codes) by 1. 
Actual Function
[Function]:


Code:
public function add_order(Order $order, array $order_products, Transaction $transaction = NULL){
  $this->db->trans_start();

  $order->create_order_code();
  $order_array = $order->create_order_array();

  $this->db->insert('tbl_orders', $order_array);
  $order_id = $this->db->insert_id();
  $new_order = new Order($order_id);

  foreach($order_products as $key=>$value){
    $order_products[$key]->set_order($new_order);
    $order_product_array = $order_products[$key]->create_order_product_array();

    $this->db->insert('tbl_order_products', $order_product_array);
    $order_product_id = $this->db->insert_id();

    $product = $order_products[$key]->get_product();

    switch ($product->get_product_class()){
        case 'Iteration':
            $this->db->select('module_id, webcast_capacity, in_person_capacity');
            $this->db->from('tbl_modules');
            $this->db->where('iteration_id', $product->get_product_class_id());
            $results = $this->db->get()->result_array();
            break;
        case 'Module':
            $this->db->select('module_id, webcast_capacity, in_person_capacity');
            $this->db->from('tbl_modules');
            $this->db->where('module_id', $product->get_product_class_id());
            $results = $this->db->get->result_array();
            break;
      }

      if(!empty($results)){
        foreach($results as $result){
        $module_id = $result['module_id'];

        if($result['webcast_capacity'] !== NULL && $result['in_person_capacity'] !== NULL){
          $attendance_method = $order_products[$key]->get_attendance_method();
        }elseif($result['webcast_capacity'] !== NULL && $result['in_person_capacity'] === NULL){
          $attendance_method = 'webcast';
        }elseif($result['webcast_capacity'] === NULL && $result['in_person_capacity'] !== NULL){
          $attendance_method = 'in-person';
        }

        $order_product_attendance_array = array(
          'order_product_id' => $order_product_id,
          'user_id' => $order_products[$key]->get_customer(true),
          'module_id' => $module_id,
          'attendance_method' => $attendance_method,
        );

        $order_product_attendance[] = $order_product_attendance_array;
      }
      $this->db->insert_batch('tbl_order_product_attendance', $order_product_attendance);
    }

    if(!empty($order_products[$key]->get_discount())){
      $discount = $order_products[$key]->get_discount();
    }
  }

  if(!empty($transaction)){
    $transaction->set_order($new_order);
    $transaction_array = $transaction->create_transaction_array();
    $this->db->insert('tbl_transactions', $transaction_array);
    $transaction_id = $this->db->insert_id();
  }

  if(!empty($discount)){
    $this->db->set('discount_redeem_count', 'discount_redeem_count-1', false);
    $this->db->where('discount_id', $discount->get_discount_id());
    $this->db->update('tbl_discounts');
  }

  if($this->db->trans_status() !== false){
    $result['outcome'] = true;
    $result['insert_id'] = $order_id;
    return $result;
  }else{
    $result['outcome'] = false;
    return $result;
  }
}

When this function completes with a discount, both trans_complete and trans_status return TRUE. However the transaction is never committed.

What I've tried:
I have dumped the contents of $this->db->error() after each query and there are no errors in any of the queries.

I have used this->db->last_query() to print out each query and then checked the syntax online to see if there were any problems, there were none.

I also tried changing to using CodeIgniters Manual Transactions like:

[Example]

PHP Code:
$this->db->trans_begin();
 // all the queries
if($this->db->trans_status() !== false){
    $this->db->trans_commit();
    $result['outcome'] = true;
    $result['insert_id'] = $order_id;
    return $result;
}else{
    $this->db->trans_rollback();
    $result['outcome'] = false;
    return $result;


I have tried echoing and var_dumping all of the return insert_ids and they all work, I have also outputted the affected_rows() of the UPDATE query and it is showing that 1 row was updated. However, still nothing being committed:
[Values Dumped]


Code:
int(10) // order_id
int(10) // order_product_id
array(3) { 
    ["module_id"]=> string(1) "1" 
    ["webcast_capacity"]=> string(3) "250" 
    ["in_person_capacity"]=> string(3) "250" } // $results array (modules)

array(1) { 
    [0]=> array(4) { 
        ["order_product_id"]=> int(10 
        ["user_id"]=> string(1) "5" 
        ["module_id"]=> string(1) "1" 
        ["attendance_method"]=> string(7) "webcast" } } // order_product_attendance array

int(9) // transaction_id
int(1) // affected rows
string(99) "UPDATE `tbl_discounts` 
            SET discount_redeem_count = discount_redeem_count- 1 
            WHERE `discount_id` = 1" // UPDATE query

I have tried submitting an order that doesn't have a discount and the entire process works! Which leads me to believe that my problem is with my UPDATE query. [After Update:] But it seems that the update query is working as well.

Suggestions Tried:
We have tried setting log_threshold to 4, and looked through the CodeIgniter Log Files which shows no history of a rollback.

We have checked the mySQL Query Log:

[Query Log]

Code:
2018-12-03T15:20:09.452725Z         3 Query     UPDATE `tbl_discounts` SET discount_redeem_count = discount_redeem_count-1 WHERE `discount_id` = '1'
2018-12-03T15:20:09.453673Z         3 Quit
It shows that a QUIT command is being sent directly after the UPDATE query. This would initiate a rollback, however the trans_status is returning TRUE.


I also changed my my.cnf file for mySQL to have innodb_buffer_pool_size=256M and innodb_log_file_size=64M. There was no change in the outcome.

As @ebcode recommended, I changed UPDATE query to use a simple_query() instead of using methods from CodeIgniter's Query Builder Class:
[Simple Query]

Code:
if(!empty($discount)){
    $this->db->simple_query('UPDATE `tbl_discounts` SET '.
    'discount_redeem_count = discount_redeem_count-1 WHERE '.
    '`discount_id` = \''.$discount['discount_id'].'\'');
}

However, this produced did not affect the outcome any differently. 

If you have an idea that I haven't tried yet, or need more information from me, please comment and I will reply promptly.

Question:

Why does trans_status return TRUE if none of my transaction is being committed?

function being called twice

$
0
0
This is a strange issue. I have a chrome extension (written in javascript and running in the browser) that send XMLHttpRequest over to my CI program. There is a controller on my server called Subit_backend and it has a function called logger_survey (/Subit_backend/logger_survey). This works fine, the logger_survey() runs on the server and it sends back a message to the calling javascript. Works fine. Then immediately logger_survey() is firing again. I have a debugger set at the first line of logger_survey so I can see it is being called again. 

I am pretty sure that my javascript code is not running the send twice. (I also have a debugger on this).
Code:
    var xhr = new XMLHttpRequest();
    xhr.onerror = function() { alert('error'); };
    xhr.open('POST', url, true);
   xhr.setRequestHeader("Content-type", "application/json")
   xhr.setRequestHeader("X-Requested-With",'xmlhttprequest');
    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    
   xhr.onload = function (){
        if((xhr.status === 200)&&(xhr.readyState===4)) {
                var jsonResponse2 = JSON.parse(xhr.responseText);
                sendResponse({task: jsonResponse2});
               return true; //The sendResponse callback is only valid if used synchronously, or if the event
handler returns true to indicate that it will respond asynchronously.     
            }
    };
    
    xhr.send(json);
    }
Is there anything I can do to flush the input buffer in CI so I don't get the same request twice? Or can I perhaps check some id and just ignore the immediate, second call?  Anyone seen this?

Discussion Forum

$
0
0
Do you have an example of codes in creating discussion forum using codeigniter?

Captcha doest work on Linux Ubuntu 16.04

$
0
0
Hi guys,
Why the captcha doest work on Ubuntu Linux, I followed exactly like the User guide and even try to watch some videos from youtube, I followed exactly like they did and I also already create the captcha directory on the root directory CI.
But still doest work? What should I do? Pls help.. Thanks a lot

Here is my controller  script:

public function index()
    {
        $this->load->helper('captcha');

        $vals = array(
                    'img_path'        =>    './captcha/',
                    'img_url'        =>    base_url().'captcha/',
                    'expiration'    => 7200,
                    'word_length'    => 8,
                    'font_size'        => 22
        );
        $cap = create_captcha($vals);
        $data['captcha'] = $cap['image'];

        $this->load->view('index', $data);
    }

And this is the views:

                   <div class="form-group">
                        <div class="col-md-5 col-md-offset-2">
                            <?php echo $captcha; ?>
                        </div>
                        <div class="col-md-5">
                            <a href="javascript:;"><i class="glyphicon glyphicon-refresh"></i>REFRESH CAPTCHA</a>
                        </div>
                    </div>

I will appreciate your helps... Thanks

Privileges in Code Igniter

$
0
0
anyone who has a source code of setting privileges in code igniter?
Viewing all 14065 articles
Browse latest View live