Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7161161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:31:13+00:00 2026-05-28T13:31:13+00:00

The principle of sessions is to save data on server side that can be

  • 0

The principle of sessions is to save data on server side that can be accessed only by the user that has the corresponding session id.

There are two kinds of data: private or public in relationship with the client. Session it’s private for public access of course.

We usually store an user id and some random data(i don’t have any concrete example).

I am thinking about not using sessions at all. Instead using a function that checks for the validity of the data sent by user. The server would have a private key that will use for hashing user data.

For example if an user has an id = 9999 we usually store it in a file associated with the session id. Every time the client is making a request we check its session id and retrieve data from the session file associated with it.

I am thinking of storing session data on client side, and every time the client makes a request it sends the hash of this data and the data.

If the user logs in it sends its credentials and the server returns its id a timestamp and a hash calculated based on the user id and the private key.
For any future request the server uses the same function and if the resulting hash is the same then the session is valid and data is previously verified.

Is this a valid way of replacing sessions?
What drawbacks there are beside not being to save server-private session data?

I was concerned by speed and I made a small test…

<?php

$session = array(
    'userId' => 999,
    'timestamp' => time()
);
$privateKey = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

$startTime = microtime(true);

for ($i = 0; $i < 1000000; $i++){
    $hash = hash_hmac('sha1', json_encode($session), $privateKey);
}

echo 'Script took ' . (microtime(true) - $startTime) . ' seconds';

…that prints

Script took 5.246542930603 seconds

I ran this on a laptop(Intel Duo).
In my opinion this is an affordable time(0.000005247 per hash).
Is the test correct?

EDIT: a timestamp is hashed along with the user id in order to ensure session expiration. So that on server side even if the session is valid but it is too old it can be considered as expired.

So to if we are hashing the data along with a timestamp using a private key is it usable in production?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:31:14+00:00Added an answer on May 28, 2026 at 1:31 pm

    I can think of a few drawbacks…

    1. All the cookie data gets transferred on each HTTP request, making the request slower.
    2. The user can see all the data.
    3. You still have to check the validity of the hash, so I do not know how much time
      or space this saves you.
    4. If it is possible to reverse-engineer the hash (that is, you aren’t using some sort of private-key encryption), the user can send anything, and you will say it is valid.
    5. If you have a hash that is not able to be reverse-engineered, it is likely somewhat slow to generate. You do say you are using a private key, so this is likely to apply. The solution may not scale well.
    6. Whoever has to maintain this code after you will wonder what you did.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's some object-oriented engineering principle that states something along the lines of a class
I am currently developing a system that has need for a session time out
The principle behind the CQS architectural pattern is that you separate your queries and
The Interface Segregation Principle (ISP) says that many client specific interfaces are better than
The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for
I thought that in principle Haskell's type system would forbid calls to impure functions
How would I save each user's 'default photo' onto a website? This same photo
I have a class that handles all of my session variables in my asp.net
In My app I am using a User bean that is Autowired to my
My C# project has repositories that are instantiated using dependency injection. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.