Symfony2.1 - New Sessions stored over and over - session

I wonder why each refresh of the page of the website I'm writing, or moving between different pages, creates new session record (I'm storing them in DB instead of using standard solution). In other words, each single click (I'm not using JS / AJAX) creates new record / new session.
Here's my configuration of sessions in config file:
session:
lifetime: 7200
domain: MY_SERVER
handler_id: session.handler.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
services:
pdo:
class: PDO
arguments:
dsn: HOST
user: USER
password: PSWD
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
arguments: [#pdo, %pdo.db_options%]
I tried to use:
auto_start: false
But I'm getting then the following error from Symfony2.1:
The auto_start setting is deprecated. Just remove it from your configuration file.
So what should I do to have normal sessions?
UPDATE I also used the following:
arguments:
- "mysql:host=%database_host%;dbname=%database_name%"
- %database_user%
- %database_password%
that is, my basic Data Base settings for whole project (stored in parameters.yml).

This can happen if you do not have session_id set as primary key. Create the session table using (from the documentation, MySQL):
CREATE TABLE `session` (
`session_id` varchar(255) NOT NULL,
`session_value` text NOT NULL,
`session_time` int(11) NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
For other databases, see How to use PdoSessionHandler to store Sessions in the Database

Related

Doctrine 2 Symfony 5 migration to an oracle database

I have
PHP 8.0
Ubuntu 20.4 running in a VM
Symfony Version 5
doctrine/orm 2.8.2
doctrine/dbal 2.12.1
doctrine/migrations 3.1.1
and oracle19c running
I have also some entities which I want now to make:migrate with doctrine. But at this point I stuck on this error:
More information:
In doctrine.yaml:
dbal:
default_connection: oracle
connections:
default:
schema_filter: ~^(?!t_cmdb_|m_cmdb_|migration_versions)~
mapping_types:
enum: string
# configure these for your database server
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
oracle:
schema_filter: ~^(?!t_cmdb_|m_cmdb_|migration_versions)~
mapping_types:
enum: string
# configure these for your database server
url: '%env(resolve:DATABASE_CUSTOMER_URL)%'
servicename: 'pdb'
service: true
driver: 'oci8'
server_version: ~
charset: AL32UTF8
I have a oracle database created with:
php bin/console doctrine:database:create --connection oracle
which goes through without any problems
Than I call
php bin/console make:migration -vvv
I got this error message:
[Doctrine\DBAL\Exception]
Unknown database type interval day(3) to second(2) requested, Doctrine\DBAL\Platforms\OraclePlatform may not support it.
All my date columns have the type datetime there is no interval in there!
I have searched for this problem but I can't come through.
Did somebody has this Problem while making migration for doctrine?
Thanks a lot for any hint.
Michael
Doctrine commands usually scan all tables in the user/schema defined in Symfony's .env file (look for DATABASE_USER). That error means that at least one of the tables in that schema has a column of type "INTERVAL...".
If you are sure that you don't have any table with an "INTERVAL..." type column, it may be that you are using directly the SYSTEM user/schema (or any other Oracle reserved user/schema). In this case, you need to create a separate user/schema for your project and move your project tables there.
Anyway, run this to check which tables under which user/schema (OWNER) have a column of type "INTERVAL...":
SELECT
OWNER,
TABLE_NAME ,
COLUMN_NAME,
DATA_TYPE,
DATA_LENGTH,
DATA_PRECISION,
DATA_SCALE
FROM ALL_TAB_COLUMNS
where
data_type like 'INTERVAL%'
-- and OWNER = 'YOUR_USER_SCHEMA' -- must be in uppercase
ORDER BY TABLE_NAME
If you do use such a column type in your project, then you must add that column type in Doctrine's configuration: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html
If you discover that you were using the SYSTEM user/schema directly (perhaps in a Docker container?), then create your separate project user/schema:
CREATE USER your_separate_user_schema IDENTIFIED BY oracle; -- oracle is the password
Grant create session to your_separate_user_schema ; -- to be able to login with the new user
ALTER USER your_separate_user_schema quota unlimited on USERS; -- give your user schema disk space
To copy only the necessary tables from SYSTEM to your_separate_user_schema: while in system/sysdba, for each table do:
create table your_separate_user_schema.table_name as select * from table_name ;

H2 in-memory database for postgresql | Error Code : 90051

Using h2 in-memory database for unit testing with Spring. The production database is PostgreSQL. I have following script which works fine on Postgres but failing on h2:
CREATE TABLE address (
address_id SERIAL NOT NULL,
province_code char(2),
created_timestamp timestamp(35) with time zone DEFAULT now() NOT NULL
)
SQL State : 90051
Error Code : 90051
Message : Scale($"35") must not be bigger than precision("23");
Do I need to specify something else in the URL or configuration. Here is the url:
database.url=jdbc:h2:mem:myDb;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS TEST

Two sites using different userdata but the same session domain in Codeigniter

I'm using Codeigniter. I have 2 sites, they look like that:
http://example.com/system/
http://example.com/system2/
These two systems have different userdata. In first site, I haven't set a parameter class, but in the second I've set it. When user first open http://example.com/system/ and then open
http://example.com/system2/ it's showing error message: undefined index class. Both sites in session domain is: example.com.
How to make to have different session? Maybe I have to set different domain in session? I haven't set it before, how to do that?
On each system use database and change the database name as well as the cookie name in config.php
$config['sess_table_name'] = 'system_x_session';
$config['sess_cookie_name'] = 'system_x_cookie';
where x is your system number or you can name it any name
don't forget to create the two tables in your database
CREATE TABLE IF NOT EXISTS `system_x_session` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
this will make your sessions independent from each other and you can check their content with phpmyadmin and the likes
hope that helps

joomla broken and can't figure it out

Transfering a Joomla site to a new server, not really experienced.
Apache is set up, MySQL is live and the DB was imported, the user/pass/path and config were updated accordingly.
The DB connected and gave me this wierd error. I did some research and someone suggested to drop the jos_ table and recreate it by doing the following:
CREATE TABLE IF NOT EXISTS `jos_session` (
`username` varchar(150) default '',
`time` varchar(14) default '',
`session_id` varchar(200) NOT NULL default '0',
`guest` tinyint(4) default '1',
`userid` int(11) default '0',
`usertype` varchar(50) default '',
`gid` tinyint(3) unsigned NOT NULL default '0',
`client_id` tinyint(3) unsigned NOT NULL default '0',
`data` longtext,
PRIMARY KEY (`session_id`(64)),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
So, now that that was done, I get the following:
404 - Component not found
You may not be able to visit this page because of:
an out-of-date bookmark/favourite
a search engine that has an out-of-date listing for this site
a mistyped address
you have no access to this page
The requested resource was not found.
An error has occurred while processing your request.
Please try one of the following pages:
Home Page
When I try to access the homepage (index.php) it does the same thing....
What the heck did I do and how do I fix this?
Any help is most appreciated -
ORIGINAL ERROR (Just restored again):
jtablesession::Store Failed
DB function failed with error number 1146
Table 'plumblev_joom347.jos_session' doesn't exist SQL=INSERT INTO jos_session ( session_id,time,username,gid,guest,client_id ) VALUES ( '9890e7d1fa915e26d17121dd4eed8004','1369667714','','0','1','0' )
You should avoid to move a Joomla! site manually, if you're not familiar with that. There are a lot of settings, which have to be adjusted.
Better use Akeeba Backup together with Kickstart for that. It even allows you to change the database prefix during transfer.
Moving shouldn't be a problem as long as you adjust the configuration.php file accordingly, especially the paths.
I would just try and move the tables from the old server again to the new one, overwriting the new tables. That is as long as you use the same Joomla version on both servers.
Can you access the administrator? If so, make sure you have a default page set and also that it is set to public.

IONIZE CMS post installation problem

I decided to try Ionize cms which is build over CodeIgnitor. I have my apache, php , mysql installed seperately. When I finished installing the cms successfully, I cannot access the website. Some weird errors occurs like
Call to a member function num_rows() on a non-object in ... \ionize-0.9\application\models\article_model.php on line 224
I got frustated and searched many places. Later I tested the CMS in WAMP, and there it worked.
Now I have no idea, what is going on, everything the CMS needs to run, is tested during the installation. I dont have any idea.... how to solve it. Please help me
For one unknown reason, all the tables of the database weren't installed. Ionize currently doesn't check that situation. If it works on one server (Wamp) and not on one other (manually LAMP installed server), compare the tables list on each system.
I had this same issue on a WAMP server and the reason was that it couldn't created the article_type table.
I'd suggest checking your database to see if that table exist.
If it doesn't take a look at the data.sql file and try to run only that create table section. It should spit out an error. In my case the description text NOT NULL default "" was throwing an error (BLOB/TEXT column 'description can't have a default value).
I fixed it by making sure description doesn't have a default value.
CREATE TABLE IF NOT EXISTS article_type (
id_type int(11) unsigned NOT NULL auto_increment,
type varchar(50) collate utf8_unicode_ci NOT NULL,
ordering int(11) default 0,
description text NOT NULL,
type_flag TINYINT( 1 ) NOT NULL default 0,
PRIMARY KEY (id_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 COMMENT='0.9.7';

Resources