0

Currently I have this:

$time = time();
$hash = md5($key . $time);

but how do I create a $_SESSION[''] based on the the hash?

Joe Bobby
  • 2,803
  • 10
  • 40
  • 59

3 Answers3

2

Try it with:

 session_id($hash);
 session_start();

You can find the explanation in the manuals:

http://php.net/manual/en/function.session-id.php

smiggle
  • 1,259
  • 6
  • 16
  • 1
    You might consider using php's built-in session id generator; it's designed for security (difficulty to guess) by crypto folks. http://stackoverflow.com/questions/138670/how-unique-is-the-php-session-id – O. Jones Jan 24 '15 at 14:50
1

I cant see why this wont work.

$time = time();
$hash = md5($key . $time);
$_SESSION['time'] = $hash;

Then try echo it to test:

echo $_SESSION['time'];

or store in your own var

$mysession = $_SESSION['time'];
James R
  • 276
  • 5
  • 14
0

If your goal is to make session more secure against session fixation attacks, you can use session_regenerate_id and re-create a new session_id after every x requests:

$_SESSION['last_time_generated']++;

if ($_SESSION['last_time_generated'] > 10) {
    $_SESSION['last_time_generated'] = 0;
    session_regenerate_id(true);
}
Whirlwind
  • 14,286
  • 11
  • 68
  • 157