Codeigniter 3 session with redis - AUTH password - codeigniter

I'm a beginner with redis. And i'm quite confused with the codeigniter 3 documentation.
I just installed a redis server and used the ci session library with redis in my app. It works quite well ... but nothing is mentioned concerning a password auth.
here is my config.php :
$config['sess_driver'] = 'redis';
$config['sess_save_path'] = 'tcp://localhost:6379';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
How am i supposed to ask for an authantification ? I suppose that everybody could access to my session table in the actual way.

The session library documentation has a bunch of links at its top, the so called "table of contents".
One of these links, aptly named "Redis Driver", points to ... the "Redis Driver" section of the document, which contains barely a few short paragraphs, exactly so you don't get lost in between lots of text.
Only one of those paragraphs mentions the word "config", and it says the following:
Just as with the ‘files’ and ‘database’ drivers, you must also configure the storage location for your sessions via the $config['sess_save_path'] setting. The format here is a bit different and complicated at the same time. It is best explained by the phpredis extension’s README file, so we’ll simply link you to it:
https://github.com/phpredis/phpredis#php-session-handler
Sure, the document doesn't contain the word "authentication", but this is hardly confusing ... you only have to click a link.
For clarity and to provide a specific example:
"tcp://host:port?auth=password"

This is working to me CI3 > config.php:
$config['sess_driver'] = 'redis';
$config['sess_save_path'] = 'tcp://host*:port*?auth=password*';

Related

Codeigniter 3 session dont get loaded right - some times?

So i work on quite a large appliaction. And we have been getting reports that our login don't work as expected. I've been looking around for some time now - and every question that is similar to mine have been left unanswered.
This is my session config.
$some_other_config["sess_cookie_name"]= "the_one_i_want_session";
$some_other_config["sess_expiration"]= 2678400;
$some_other_config["sess_encrypt_cookie"]= false;
$some_other_config["sess_use_database"]= true;
$some_other_config["sess_table_name"]= "db_session";
$some_other_config["sess_match_ip"]= false;
$some_other_config["sess_match_useragent"]= false;
$some_other_config["sess_time_to_update"]= 7200;
Also, we have one more session
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'really_unimportant_session';
$config['sess_expiration'] = 2678400;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'a_non_exisiting_legacy_table';
$config['sess_save_path'] = '/path/to/the/sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_match_ip'] = FALSE;
Now here is the funny part "the_one_i_want_session" is the one keeping track of the user being logged in or not, right?
Well, if I connect to a vpn (i think it might be the IP change) and connect to whatever country, I won't be able to log in. We can log in in two ways: With a ajax post-request, or a regular form post.
They are basically the same, when you log in to the ajax, the login gives the correct login successful state, we write the session, it get stored in the database, and we give the user a successful message, and a choice to where to go next. When we do another request, the session is not updated.
With the regular form-post, the excact same happens but we do a redirect with the codeigniter framework. Again the session hits the db, but after the redirect the session is not connected to the browser.
Kicker: if i disable my vpn, it everything works, like a charm. I used Private Internet Access for this test.
I don't really know where to go next. The only thing i have seen is that in CI3 the session is supposed to work together with the $_SESSION superglobal, but my $_SESSION is always NULL. Could there be a problem with two sessions defined?
Edit:
One more thing i forgot to mention is. This only happens in production. We basically have a mirror of the site, with almost the same config (session configs are the same), and login works on the mirrored site.
Edit2:
It seems that even the setcookie-function does what it is supposed to do, and returns true. Im confused.

Creating Sugar configuration file (config.php) Creating Sugar application tables, audit tables and relationship metadata

I am getting timeout error and tried everything to change its value from 600 but now luck. Can any body help to do this for SugarCRM?
Instead of changing in SugarCRM configuration file config.php try to change in config_override.php. You can also add your custom configuration using module loader apply following code in manifest.php file.
$cfg = new Configurator();
// Your custom configuration code
$cfg->config['myaddon_setting'] = true; // This will make add-ons setting enable.
$cfg->handleOverride();
To Perform database queries use following code.
$mymodule = BeanFactory::newBean($module);
$db = DBManagerFactory::getInstance();
$query = "SELECT * FROM users WHERE 1";
$result = $db->query($query, true,"Error reading the database");
For logic hooks click on Logic Hooks. Write down in comment if you need anything else.

CodeIgniter to run from a subdirectory of another codeigniter installation

I am trying to find a way to run codeigniter from a sub-directory of another codeigniter installation. The CI from the sub-directory would be for testing and the main one is the live site. Anyone could advice on this or any other better approach ?
I believe you can just place this in the root folder and set the base url in the config :
$config['base_url'] = 'http://www.example.com/testsite/';
then it works.
There can be issues with the first application serving the 404 pages when a route is not matched however
I am posting the answer here, because is too long to use it as a comment...
I made it thru another approach: setting different $active_group in the config/database.php file.
So, first I have checked for a parameter in $_GET, if that is set we use a group, otherwise the default group (the other group is used for testing - a separate database, exact structure but without touching the main db)
if(!isset($_SESSION)){session_start();}
if (isset($_GET["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
$_SESSION['debugmode'] = true;
}elseif (isset($_SESSION["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
}elseif(!isset($_GET["debugmode"]) && !isset($_SESSION["debugmode"])){
$active_group = 'default';
$active_record = TRUE;
}
To make sure this will work on all the controllers /views, because we wont have that $_GET parameter all over the application, we can set that session value once we have that $_GET parameter present. Also, we have to make sure we destroy that session when we log out or after an amount of time.
Reason of using a Session value: by default CI is using that table to store the sessions, without using our session value, it will force somehow to use the default DB, or at least I couldn't find it to trick this step.

Modifying native module to work with other tables

I want to modify a native joomla module that display articles of a category. I want it to display articles of an other prefix tables (both joomla website are on the same server).
Notice that I already looked at available extension but none of them would fit.
I tried to modify the helper.php of the native joomla module
tables, by changing the
$com_path =
but i am getting aFatal error.
Native code:
$com_path = JPATH_SITE.'/components/com_content/';
My try :
$com_path = '/homez.420/kmxsiksf/rsc/components/com_content/helpers/route.php
To use an external database (even if it's on your server) in Joomla extensions, the proper way would be to set some options before retrieving the JDatabase-object.
Create a helperclass to handle your external db, and in every method that uses the DB-object you simply set the options of your external db before retrieving the object:
$option = array();
$option['driver']   = 'mysql';
$option['host']     = 'localhost';    // In your case probably localhost
$option['user']     = 'dbusername';       // User for database authentication $option['password'] = 'badpass12345';   // Password for database authentication $option['database'] = 'bigdatabase';      // Database name
$option['prefix']   = 'abc_';             // Database prefix (may be empty)
$db = & JDatabase::getInstance( $option );
You are now able to use your external database the same way as you would with your regular db.

Multiple Dynamic Domains Using ONE Codeigniter Installation

One of my jobs is to manage 58 sites for properties spread out across the country. They each have their own domain and are all housed in the same Dedicated Virtual Serve at Media Temple. The sites which are about 19 pages each use the exact same html/css/php code. The images are served to each site from a central repository living in different folders for each theme used.
What I want to do is to install one single installation of CI2 including the application folder because everything that is different between the sites is stored in the database. As long as I can give the controller a unique property number (which I would hope I could do when they access the index.php page in each domain), then all of my sites will work fine.
In all the answers I have read, the suggestion is to replicate the application folders and just reuse the core. What would work best for me is to also reuse the application folder. Then when I make a modification, it will cascade to all sites without me having to touch 58 pages.
Is this possible?
If all files are the same and the only thing changing between apps is the data from the database, then you can do this:
Point all domains to your docroot for the CI install
in your index.php, determine which db connection you need to use for the currently requested domain:
// index.php
$domain = $_SERVER['SERVER_NAME'];
switch ($domain)
{
case 'www.firstsite.com':
$this->load->database('firstsitedb');
break;
case 'www.secondsite.com':
$this->load->database('secondsitedb');
break;
default:
show_error('No Site Found');
break;
}
** OR **
If they each use the same database, and you need to be able to use a variable in your queries, then just set a constant based on the switch/case instead of loading a different database. Then you can use that constant throughout your application in your queries.
// index.php
$domain = $_SERVER['SERVER_NAME'];
$site_id = 0; // default
switch ($domain)
{
case 'www.firstsite.com':
$site_id = 1;
break;
case 'www.secondsite.com':
$site_id = 2;
break;
default:
show_error('No Site Found');
break;
}
define('SITE_ID', $site_id);
With Codeigniter 2.2, the index.php now allows the setting of a config array item (the feature is documented in that file). So it is possible to save the requested domain as a site variable in effect by doing this:
$assign_to_config['site_domain'] = empty($_SERVER['SERVER_NAME']) ? 'default.dev' : $_SERVER['SERVER_NAME'];
Later you could match this site_domain string against a database look-up to fetch the requisite content & theme views etc.

Resources