How to save session counts and retrieve the number of user access - codeigniter

I would like to know how to save the number of times a user access a webpage and return the session count to the user
Eg
A user opens his user profile on a web page and would be able to see
Users number of access: 20times.
I have created the page with Codeigniter and created a table in the database.
CREATE TABLE IF NOT EXISTS `ci_sessions` (
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`)
);
But I don't know how to save the number of times the user has accessed the webpage

Related

Make ajax script insert in dbase

I want to make these code insert in DBase in table chat; let's say, but I dont know how. I am bad at AJAX and I want to learn. Can you help me do it?Thank you very much.
Here is my table from DBase:
CREATE TABLE IF NOT EXISTS `legacy_chat` (
`id` int(99) NOT NULL AUTO_INCREMENT,
`chatter` int(100) NOT NULL DEFAULT '0',
`who` int(100) NOT NULL DEFAULT '0',
`timesent` int(50) NOT NULL DEFAULT '0',
`msgtext` varchar(255) NOT NULL DEFAULT '',
`rid` int(99) NOT NULL DEFAULT '0',
`exposed` char(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
codes
Indeed, you need to create a php file that takes the information you wish to add/change/delete to/from the database. You will load that file using AJAX (or jQuery) via POST or GET with the info you wish to manipulate. You may also update the requesting page using the callback to notify the user that the action was or not successfully executed.
Have a look over the following tutorials which guide you step-by-step:
Infotuts.com
Programming-free
CodeofNinja.com

Joomla migration issue

I have transferred my website to a new server after updating the files and database I am getting this issue
Table 'jimcorbe_jimcorbe.xpivg_session' doesn't exist SQL=INSERT INTO xpivg_session (session_id, client_id, time) VALUES ('18f0b96cfc5e1cb723b8405137ff36a6', 0, '1427709725')
I am very new to joomla so could not understand what it means. Can anyone provide me with the solution to get back my website live.
During the migration, it's possible that database table prefixes have changed.
Open PhpMyAdmin and look for the session table. If it doesn't exist, run the following SQL command:
CREATE TABLE IF NOT EXISTS `xpivg_session` (
`session_id` varchar(200) NOT NULL DEFAULT '',
`client_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
`guest` tinyint(4) unsigned DEFAULT '1',
`time` varchar(14) DEFAULT '',
`data` mediumtext,
`userid` int(11) DEFAULT '0',
`username` varchar(150) DEFAULT '',
`usertype` varchar(50) DEFAULT '',
PRIMARY KEY (`session_id`),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

multi level login, and restricted area on code igniter

i have problem to proces multi level log in and restristed area
there will be 2 type of user: admin and user (common), when a user register they fill form : username, email, and city. --> acces will be set as NULL. for admin acces will be st to 1 (manually)
table users:
CREATE TABLE IF NOT EXISTS users (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
acces' varchar(5),
'city varchar(25) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;
table event :
CREATE TABLE IF NOT EXISTS events (
id int(11) NOT NULL AUTO_INCREMENT,
event varchar(255) NOT NULL,
'cityvarchar(25) NOT NULL,
PRIMARY KEY (id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;
the problems are:
1. when a user want to log in, they fill 2 form : email and password.
2. how to to check if they user or admin
3. if they log in as user, they will be directed to their 'city'. the 'city' will be same to the city when they register.
i really appreciate all possible solution to my problems..
thanks all
Regards.
Simply add a third table with 'roles', that assigns a user with a role.
instead of checking for the user login, You can limit functions/controllers to rules.
if(user_has_role('admin'))
You can with some minor effort expand this to multiple roles per user, with each role having it's own permissions etc., there are also several premade libraries for this sort of functionality.
Just google around for user libraries.

spring security authentication different profiles and permissions with hibernate and jsf

i want to authenticate the users using spring security. i'm using hiebrnate and jsf.
the problem is in the different tutorials that i saw online there is just one role. but in my case i have a different database with permissions and profiles
Table User
user id
profile id
login
password
Table profile
profile_id
profile
Table action or permission
action_id
action
profile_id
I am wondering if anyone knows how to implement this or knows some good tutorials.
if you want to manage your user role, groups and permissions, you could see the Spring Security documentation about schema.
Here some snippets and details on the above link :
create table users(
username varchar_ignorecase(50) not null primary key,
password varchar_ignorecase(50) not null,
enabled boolean not null);
create table authorities (
username varchar_ignorecase(50) not null,
authority varchar_ignorecase(50) not null,
constraint fk_authorities_users foreign key(username) references users(username));
create unique index ix_auth_username on authorities (username,authority);
create table groups (
id bigint generated by default as identity(start with 0) primary key,
group_name varchar_ignorecase(50) not null);
create table group_authorities (
group_id bigint not null,
authority varchar(50) not null,
constraint fk_group_authorities_group foreign key(group_id) references groups(id));
create table group_members (
id bigint generated by default as identity(start with 0) primary key,
username varchar(50) not null,
group_id bigint not null,
constraint fk_group_members_group foreign key(group_id) references groups(id));

Can I use spring security without username or password?

I need to make sso for applications and combile user table.
I want to use spring security with email authentication, without username or password.
How can I do this?
My limittations:
Single user can authenticate with multiple emails (Like github)
User can manage all authentication state and expire specific authentication. (In profile page)
No password. No string username or id. (Because no service supports basic login)
--- EDIT ---
OAuth 2.0 / 1.0a Authentication
Generated scheme:
(Is this proper for this case?)
create table hib_authentication (
id BIGINT UNSIGNED not null auto_increment,
firstAuthenticatedTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP not null,
ip VARBINARY(16) not null,
browser VARBINARY(24) not null,
lastAuthenticatedTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP not null,
user_id INT UNSIGNED not null,
primary key (id)
) ENGINE=InnoDB;
create table hib_user (
id INT UNSIGNED not null auto_increment,
country SMALLINT UNSIGNED not null,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP not null,
locale varchar(255) not null,
timeZone varchar(255) not null,
primary key (id)
) ENGINE=InnoDB;
create table hib_user_email (
id BIGINT UNSIGNED not null auto_increment,
email varchar(255) not null,
user_id INT UNSIGNED not null,
primary key (id)
) ENGINE=InnoDB;
create index index_to_get_authentication_by_user on hib_authentication (user_id);
alter table hib_user_email
add constraint UK_isuygi7fmcwnlht8f4plckt6n unique (email);
create index index_to_search_email_by_user on hib_user_email (user_id);
alter table hib_authentication
add constraint authentication_belongs_to_user
foreign key (user_id)
references hib_user (id);
alter table hib_user_email
add constraint email_belongs_to_user
foreign key (user_id)
references hib_user (id);

Resources