Problems with CodeIgniter and setting characters - codeigniter

I use CodeIgniter and MySQL. I am getting the following message:
Can't initialize character set iso 8859-15 (path: /usr/share/mysql/charsets/)
I use a hosted server and have no access to the usr directory. This is the function in the CI mysql_driver class regarding charset:
function db_set_charset($charset, $collation) {
if (!isset($this->use_set_names)) {
// mysql_set_charset() requires PHP >= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback
$this->use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE;
}
if ($this->use_set_names === TRUE) {
return #mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
} else {
return #mysql_set_charset($charset, $this->conn_id);
}
}
The CI Config has the UTF-8 setting:
$config['charset'] = 'utf-8';
My Notepad++ is set to UTF-8 respectively ANSI. How can I change the global MySQL setting to UTF-8? Do I have to add a config.php in my web server settings with MySQL character settings? Like character_set_database="utf-8".
Why does the notice with iso-8859 appear? For me, iso-8859 is good, because it can show German special chars, UTF cannot.
I have the solution: CI is set to the following in the conig.php
$config['charset'] = 'utf-8';
When I use utf8_encode before print, I hardcode the char setting to UTF 8 and it works. If I do not use the function, it will show wrong characters. I do not understand why I have to use the function because the config setting has UTF-8.
I tried to print $config['charset'] to verify, but no output.
Timo

Related

In Codeigniter 4, the URL with 'www.' is not shown in base url()

In Codeigniter 4 URL with www. not shown www in base URL().
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://". $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
This source code is also not working.
How can I solve this?
base_url([$uri = ''[, $protocol = null]])
Returns your site base URL, as specified in your config file. Example:
<?php
echo base_url();
Define your base URL in your .env file at the root of your project. Example:
app.baseURL = 'http://www.your-domain.com'
when you first setup a codeigniter project you will see a env file in your root, copy that file and rename it to .env env with a dot.
Then in that folder look at line 23 I think or just look for #app.baseURL = 'http://localhost:8080/' Then Remove the hash(#) and just add www. in front of localhost like this app.baseURL = 'http://www.yourdomain.com/'
Also Remember to change your $baseURL in app\Config\App.php to your domain.
FYI:
What is a .env file?
A .env file or dotenv file is a simple text configuration file for controlling your Applications environment constants.
I recommend you look at the codeignter official docs aswell

Hide password in Genexus beforeConnect procedure

I'm using the BeforeConnect option in Genexus. I put this code in a procedure...
&UserID = &websession.Get("db")
//select the Database depending on websession
Do Case
Case &UserID = "1"
&DataBase = "CambioDB1"
Case &UserID = "2"
&DataBase = "CambioDB2"
Otherwise
&DataBase = "CambioDB1" //default database
EndCase
//Change connection properties
&dbconn = GetDatastore("Default")
&dbconn.UserName = 'username'
&dbconn.UserPassword = 'password'
&dbconn.ConnectionData = "DATABASE=" + &DataBase.Trim() //SQLServer
... set the BeforeConnect property and it works.
But how can I avoid to put the password of the db in the code?
I was thinking to use a file to read from, but it would be an unencrypted password anyway.
How can I solve this? Is there a way to manage this or do I have to risk the password in clear text?
Nicola,
You may use the ConfigurationManager to read a value from the standard config file (client.cfg for Java, web.config for .net).
&MyPassword = ConfigurationManager.GetValue('MY_PASSWORD')
Add a value to your configuration file with the password.
For example:
MY_PASSWORD=my-db-password
You probably want to save the password encrypted for an extra layer of security.
Simple:
&EncPass = Encrypt64(&Password, &SysEncKey)
Stonger encryption:
https://wiki.genexus.com/commwiki/servlet/wiki?42682,Symmetric+Stream+Encryption
&EncPass = &SymmetricStreamCipher.DoEncrypt(symmetricStreamAlgorithm, key, iv, plainText)

Virtuemart Media files lose all meta information when downloading

My media files lose all meta information when downloading. I have a website with downloadable, virtual products. It affects here Android app files, apk's.
If I want to download and install the files, I get the following error.
There was a problem parsing the package.
The Download package (apk) has not include version number, file size, package name. It shows only N/A .
Scenario:
I have downloaded apk file directly via ftp from the vmfiles file folder.
Metadata available - installation ok.
Download Website - File does not include version number, file size, package name. Installation fails with the above message.
I work with:
VirtueMart 3.2.15 Blue Corvus 9877
Joomla 3.8.7
OpenTools Virtuemart Download for sale plugin
I switched the database to utf8mb4 because I need symbols in text and description. Since then, the downloaded products are probably not usable, I think.
I modified the varchar fields, varchar (191), or changed them to text. I just do not know why, how and where the package information is lost.
Here is another phpmyadmin mysql query of variables / collation:
SHOW VARIABLES LIKE 'char%'
--------------------
Web server productive:
-------------------------------------
variable_name value
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8mb4
character_set_server utf8
character_set_system utf8
character_sets_dir / usr / share / mysql / charsets /
----------
Local Host:
-------------------------------------
Variable_name Value
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8mb4
character_set_server utf8mb4
character_set_system utf8
character_sets_dir C: \ xampp \ mysql \ share \ charsets \
I had already purchased the software from OpenTools in February 2016. The Software is not more supported. Maybe I can reach someone in the forum or by email. As I said, the uploaded files on the server are still fine. And the download software reads the file stream via readfile_chunked byte by byte for the download link.
Maybe some base64 or something has to be encoded here? Or is the error somewhere else?
Android Studio says when opening the downloaded .apk file:
Unknown chunk type: 835
java.lang.NullPointerException: Unknown chunk type: 835
Virtuemart works with utf8, mysql supports Multi (utf8 + utf8mb4). My system is set up with utf8mb_unicode_ci.
Should I switch to connection encoding utf8mb4_bin? Does Virtuemart realize that? I will definitely try it now.
I found another code snippet regarding mysql_encoding:
utf8mb4 is missing here:
switch($mysql_encoding[0])
{
case "utf8":
return "utf-8";
break;
case "latin1":
return "iso-8859-1";
break;
default:
return $mysql_encoding[0];
}
Should such a thing be taken into the Virtuemart model with me? Somewhere I have read something from Java Binary Variables specifically for utf8mb4 call handling. That you have to set up this extra. Also, attaching '? UseUnicode = true & characterEncoding = UTF-8' to the JDBC URL download link did not help.
A coding God in another forum could help me further and found the solution :-)
In the used readfile_chunked querier, whether the output buffer is deleted
here. The solution was to put ob_clean () before the while loop.
function readfile_chunked($filename, $retbytes=true)
{
$ chunksize = 1 * (1024 * 1024); // how many bytes by chunk
$ buffer = '';
$ cnt = 0;
                
$ handle = fopen ($ filename, 'rb');
if ($ handle === false)
{
return false;
}
ob_clean ();
while (! feof ($ handle))
{
$ buffer = fread ($ handle, $ chunksize);
echo $ buffer;
ob_flush ();
flush ();
                       
if ($ retbytes)
{
$ cnt + = strlen ($ buffer);
}
}                
$ status = fclose ($ handle);
if ($ retbytes && $ status)
{
return $ cnt; // return num. bytes delivered like readfile () does.
}                
return $ status;
}

.NET Core 2 + System.Data.OracleClient. Chinese characters doesn't work

I'm using .NET Core 2 with the System.Data.OracleClient package published some weeks ago here: https://www.nuget.org/packages/System.Data.OracleClient/
I can read numbers, dates and normal English characters. But not Chinese. Probably a lot of other non-western characters.
Here's a sample program to illustrate the error:
using System;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Data.OracleClient;
namespace OracleConnector
{
class Program
{
static void Main()
{
TestString();
return;
}
private static void TestString()
{
string connStr = "Data Source = XE; User ID = testuser; Password = secret";
using (OracleConnection conn = new OracleConnection(connStr))
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "select 'some text in English language' as a, '储物组合带门/抽屉, 白色 卡维肯, 因维肯 白蜡木贴面' as b from dual";
var reader = cmd.ExecuteReader();
reader.Read();
string sEnglish = reader.GetString(0);
string sChinese = reader.GetString(1);
Trace.WriteLine("English from db: " + sEnglish);
Trace.WriteLine("Chinese from db: " + sChinese);
Trace.WriteLine("Chinese from the code: 储物组合带门 / 抽屉, 白色 卡维肯, 因维肯 白蜡木贴面");
}
}
}
}
It outputs this:
English from db: some text in English languageဂ
Chinese from db: ¿¿¿¿¿¿/¿¿, ¿¿ ¿¿¿, ¿¿¿ ¿¿¿¿¿e
Chinese from the code: 储物组合带门 / 抽屉, 白色 卡维肯, 因维肯 白蜡木贴面
As you can see, Chinese characters from normal code works. But not when it comes from the database. Also, the last character in the English text is some messed up thing. I've also tried the corresponding Mono nuget package with the same result.
Anyone have any clue how to fix this?
Edit: Tried adding Unicode=True to the connection string but Chinese characters still doesn't work.
This is a problem with the System.Data.OracleClient DLL. I am having the same problem where 2, 3, or even 4-byte Unicode characters are getting tacked to the end of my strings.
Switching to Mono.Data.OracleClientCore helped slightly, but I still got some odd characters at the end of some strings (Unicode backspace and backslash).
I just tried the following library, and it seems to work for my needs (so far):
https://github.com/ericmend/oracleClientCore-2.0
You will need to re-compile for Windows (change to #define OCI_WINDOWS in OciCalls.cs). Will update this answer if I find that it doesn't continue to work.
Still, I think that we'll have to wait for Oracle to release their .NET Core supported solution for any sort of production ready library.
Please try
Environment.SetEnvironmentVariable ("NLS_LANG",".UTF8");
before creation of the connection-Object.
The System.Data.OracleClient-Implementations uses external Oracle libraries, which assumes (at least on Windows) the ANSI-Charset.
Setting the NLS_LANG-Environmentvariable informs the Oracle-Libs that you want the UTF8-Encoding.
(much) more Details on the NLS_LANG-FAQ-Page:
http://www.oracle.com/technetwork/database/database-technologies/globalization/nls-lang-099431.html
Append ";Unicode=True" to connectionstring and add Environment.SetEnvironmentVariable ("NLS_LANG",".UTF8"); before create connection
string conn = "DATA SOURCE=hostname.company.org:1521/servicename.company.org;PASSWORD=XYZ;USER ID=ABC;Unicode=True"
Environment.SetEnvironmentVariable("NLS_LANG", ".UTF8");
using (DbConnection conn = create_connection(app_conn))
{
//...
}

PHP4 including file during session

I am trying to put second language on my webpage. I decided to use different files for different languages told apart by path - language/pl/projects.ln contains Polish text, language/en/projects.ln - English. Those extensions are just to tell language files from other, the content is simple php:
$lang["desc"]["fabrics"]["title"] = "MATERIAŁY";
$lang["desc"]["fabrics"]["short_text"] = "Jakiś tam tekst na temat materiałów";
$lang["desc"]["services"]["title"] = "USŁUGI";
$lang["desc"]["services"]["short_text"] = "Jakiś tam tekst na temat usłóg";
And then on the index page I use it like so:
session_start();
if (isset($_SESSION["lang"])) {
$language = $_SESSION["lang"];
} else {
$language = "pl";
}
include_once("language/$language/projects.ln");
print $lang["desc"]["fabrics"]["title"];
The problem is that if the session variable is not set everything works fine and array item content is displayed but once I change and set $_SESSION["lang"] nothing is displayed. I tested if the include itself works as it should by putting print "sth"; at the beginning of projects.ln file and that works all right both with $_SESSION["lang"] set and unset.
Please help.
Can you test the return value of session_start() - if it's false, it failed to start the session.
Is it being called before you output anything to the browser? If headers were already sent and your error_reporting level is too low, you won't even see the error message.
Stupid, but - do you set value of $_SESSION['lang'] to valid value like "en"? Does the English translation load correctly when you use it as default value in else block instead of "pl"?
"Jakiś tam tekst na temat usłóg" -> "usług" :)
Can you tell us what does this one output:
if(session_start()) {
echo SID, '<br/>';
if(isset($_SESSION['lang'])) {
echo 'lang = "',$_SESSION['lang'], '"';
}
}
Session starts fine and accidentally I managed to fix it.
I renamed $_SESSION['lang'] to $_SESSION['curr_lang'] and it now works allright. It seams like it didn't like the array and session variable having the same name (?).

Resources