473,418 Members | 1,535 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,418 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 13470
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.