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.
4 13470
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: -
-
$cookie_name = 'sessionid';
-
$value = uniqid(time());
-
$expire = time() + 60*60*24*3; // 3 days from now
-
$path = '/blog';
-
$domain = 'www.mysite.com';
-
$secure = isset($_SERVER['HTTPS']); // or use true/false
-
$httponly = true;
-
setcookie($cookie_name, $value, $expire, $path, $domain, $secure, $httponly);
-
if you want to you can also set the PHP configuration to use cookies for sessions: -
session.use_only_cookies = 1
-
session.cookie_lifetime = 0 // '0' = expire when browser closes
-
session.cookie_secure = 1
-
session.cookie_httponly = 1
-
more information in the php manual https://www.php.net/manual/en/features.cookies.php
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.
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.
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: -
-
$cookie_name = 'sessionid';
-
$value = uniqid(time());
-
$expire = time() + 60*60*24*3; // 3 days from now
-
$path = '/blog';
-
$domain = 'www.mysite.com';
-
$secure = isset($_SERVER['HTTPS']); // or use true/false
-
$httponly = true;
-
setcookie($cookie_name, $value, $expire, $path, $domain, $secure, $httponly);
-
- session.use_only_cookies = 1
-
session.cookie_lifetime = 0 // '0' = expire when browser closes
-
session.cookie_secure = 1
-
session.cookie_httponly = 1
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
...
|
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:
|
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...
|
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...
|
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...
|
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...
|
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?...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |