Browse Source

Feature #272 - session_handler class: Corrections about the encoding of the database connection used for storing php-session data.

Ivan Tcholakov 15 years ago
parent
commit
e4847d9c63
2 changed files with 17 additions and 10 deletions
  1. 4 5
      main/inc/global.inc.php
  2. 13 5
      main/inc/lib/session_handler.class.php

+ 4 - 5
main/inc/global.inc.php

@@ -144,10 +144,6 @@ if (!empty($_configuration['multiple_access_urls'])) {
 	$_configuration['access_url'] = 1;
 }
 
-// This function is moved here after the database connections was made since  api_session_start will call the api_get_path() function and this function will call a Database function
-// Start session.
-api_session_start($already_installed);
-
 // The system has not been designed to use special SQL modes that were introduced since MySQL 5.
 Database::query("set session sql_mode='';");
 
@@ -181,6 +177,9 @@ Database::query("SET SESSION character_set_server='utf8';");
 Database::query("SET SESSION collation_server='utf8_general_ci';");
 Database::query("SET CHARACTER SET '" . Database::to_db_encoding($charset) . "';");
 
+// Start session after the internationalization library has been initialized.
+api_session_start($already_installed);
+
 // access_url == 1 is the default chamilo location
 if ($_configuration['access_url'] != 1) {
 	$url_info = api_get_access_url($_configuration['access_url']);
@@ -486,7 +485,7 @@ if (is_array($language_files)) {
 		}
 	} else {
 		// if the sub-languages feature is not on, then just load the
-		// set language interface 
+		// set language interface
 		foreach ($language_files as $index => $language_file) {
 			// include English
 			include $langpath.'english/'.$language_file.'.inc.php';

+ 13 - 5
main/inc/lib/session_handler.class.php

@@ -15,7 +15,7 @@ class session_handler {
 	public $lifetime;
 	public $session_name;
 
-	public function __construct () {
+	public function __construct() {
 		global $_configuration;
 
 		$this->lifetime = 60; // 60 minutes
@@ -30,13 +30,21 @@ class session_handler {
 		$this->connection_handler = false;
 	}
 
-	public function sqlConnect () {
+	public function sqlConnect() {
 
 		if (!$this->connection_handler) {
 			$this->connection_handler = @mysql_connect($this->connection['server'], $this->connection['login'], $this->connection['password'], true);
 
 			// The system has not been designed to use special SQL modes that were introduced since MySQL 5
 			@mysql_query("set session sql_mode='';", $this->connection_handler);
+
+			@mysql_select_db($this->connection['base'], $this->connection_handler);
+
+			// Initialization of the database connection encoding to be used.
+			// The internationalization library should be already initialized.
+			@mysql_query("SET SESSION character_set_server='utf8';", $this->connection_handler);
+			@mysql_query("SET SESSION collation_server='utf8_general_ci';", $this->connection_handler);
+			@mysql_query("SET CHARACTER SET '" . Database::to_db_encoding(api_get_system_encoding()) . "';", $this->connection_handler);
 		}
 
 		return $this->connection_handler ? true : false;
@@ -65,17 +73,17 @@ class session_handler {
 		return $result;
 	}
 
-	public function open ($path, $name) {
+	public function open($path, $name) {
 
 		$this->session_name = $name;
 		return true;
 	}
 
-	public function close () {
+	public function close() {
 		return $this->garbage(0) ? true : false;
 	}
 
-	public function read ($sess_id) {
+	public function read($sess_id) {
 
 		if ($this->sqlConnect()) {
 			$result = $this->sqlQuery("SELECT session_value FROM ".$this->connection['base'].".php_session WHERE session_id='$sess_id'");