473,382 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Storing session info in Local Storage?

2 2Bits
My website has a back-end admin area used by volunteers to add content to the Db which contains over 60 table. When each volunteer logs into the Admin area I store their Username and access lever in the $_SESSION associative array. This information is used in a log record when a record is updated.

At the beginning of each Admin module I test for the existence of a Session and if not started, then one is started. On the most used module I also set the timeout_duration = 21600 (6 hours).

The problem is that the volunteers will oftentimes work a couple of hours and then do some research, have lunch, take a nap, go to bed while the browser is still open and the admin page is still active. Thus, when they return to the computer, they again start working with the Admin module and when a record is updated the Username is Unknown. Unknown because the Session has expired and thus, the Session variable is not set and the Username is set to Unknown.

So the question is... Is there anyway to solve the problem using Sessions or do I need to just store the info in Local Storage?

Thanks in advance.
Oct 25 '21 #1
4 13446
Niheel
2,460 Expert Mod 2GB
The short answer is set a cookie (bits of data stored on the client by the browser).
Store the session id information in a cookie and this will allow you to let the session persist.

How to set a cookie in PHP:
Expand|Select|Wrap|Line Numbers
  1.  
  2.   $cookie_name = 'sessionid';
  3.   $value = uniqid(time());
  4.   $expire = time() + 60*60*24*3; // 3 days from now
  5.   $path = '/blog';
  6.   $domain = 'www.mysite.com';
  7.   $secure = isset($_SERVER['HTTPS']); // or use true/false
  8.   $httponly = true;
  9.  setcookie($cookie_name, $value, $expire, $path, $domain, $secure, $httponly);
  10.  
if you want to you can also set the PHP configuration to use cookies for sessions:
Expand|Select|Wrap|Line Numbers
  1. session.use_only_cookies = 1
  2. session.cookie_lifetime = 0  // '0' = expire when browser closes
  3. session.cookie_secure = 1
  4. session.cookie_httponly = 1
  5.  
more information in the php manual
https://www.php.net/manual/en/features.cookies.php
Oct 25 '21 #2
dev7060
636 Expert 512MB
My website has a back-end admin area used by volunteers to add content to the Db which contains over 60 table. When each volunteer logs into the Admin area I store their Username and access lever in the $_SESSION associative array. This information is used in a log record when a record is updated.

At the beginning of each Admin module I test for the existence of a Session and if not started, then one is started. On the most used module I also set the timeout_duration = 21600 (6 hours).

The problem is that the volunteers will oftentimes work a couple of hours and then do some research, have lunch, take a nap, go to bed while the browser is still open and the admin page is still active. Thus, when they return to the computer, they again start working with the Admin module and when a record is updated the Username is Unknown. Unknown because the Session has expired and thus, the Session variable is not set and the Username is set to Unknown.

So the question is... Is there anyway to solve the problem using Sessions or do I need to just store the info in Local Storage?
Assuming many things here. Show the relevant code.
Oct 25 '21 #3
Dormilich
8,658 Expert Mod 8TB
Is there anyway to solve the problem using Sessions
The problem here is that you have two different ways to start a session (namely with and without username). To solve that you need to require authentication whenever a session does not exist. This way you'll always have a username available.
Oct 26 '21 #4
mopufo
2 2Bits
The short answer is set a cookie (bits of data stored on the client by the browser).
Store the session id information in a cookie and this will allow you to let the session persist.

How to set a cookie in PHP:

Expand|Select|Wrap|Line Numbers
  1.  
  2.   $cookie_name = 'sessionid';
  3.   $value = uniqid(time());
  4.   $expire = time() + 60*60*24*3; // 3 days from now
  5.   $path = '/blog';
  6.   $domain = 'www.mysite.com';
  7.   $secure = isset($_SERVER['HTTPS']); // or use true/false
  8.   $httponly = true;
  9.  setcookie($cookie_name, $value, $expire, $path, $domain, $secure, $httponly);
  10.  
Expand|Select|Wrap|Line Numbers
  1. session.use_only_cookies = 1
  2. session.cookie_lifetime = 0  // '0' = expire when browser closes
  3. session.cookie_secure = 1
  4. session.cookie_httponly = 1
  5.  
more information in the php manual.
https://www.php.net/manual/en/features.cookies.php
I solved my problem using the example you gave, thank you all very much for your help.
Nov 4 '21 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Celebrate | last post by:
I'm noticing that when my homepage first starts up, all the menu links to other pages have the session info appended to the URL. For example: ...
3
by: Patrick Hoffmann | last post by:
hi folx, today I had "multithreading" trouble with the following code (MS VC++6/optimized compiling): --------------------------- class myclass { static int s_nNext; public:
0
by: Mirek Rewak | last post by:
Hi, How can I read parameters of the actual SSL session info in my ASP.NET appllication? I need to know ssl version and cipher used. Apache server gives it in server variables, but IIS doesn't so...
4
by: Le | last post by:
Hello I was wondering if there was a way to keep a user's session info across multple domains For example, company A owns website www.a.com and www.b.com. A user logs into www.a.co and later...
2
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to...
3
by: Astha | last post by:
Hello ..I am new to asp.net .I have this problem of storing session values in a variable as an array.That is ..an array should contain the session values.How am i to do this in C#?and how can I...
3
by: Atmapuri | last post by:
Hi! My dll uses Thread Local Storage because of Open MP. Is there any workaround on how this dll, can be called from ..NET? What changes would be neccessary? Will that be addressed in VS2008?...
0
by: keyser soze | last post by:
hi i have logically divided each .asp page in one or more "states" then i need to store somewhere information about what state has each client on each page i consider 3 ways: - store info in...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.