Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A way to generate a custom session ID without editing php.ini

Tags:

php

session

I'm trying to create a custom session ID generator. From what I've read across the sites you can do this by manually editing PHP's settings files, however, it will not be available until I switch from my shared servers to a fully customisable one.

What i'm trying to ask is whether it's possible to specify how session IDs are generated by inputting a PHP code to a page? My intention is to use the same mechanics as the default ID generator, but use sha512 and a few custom goodies such as salt.

like image 904
AM- Avatar asked Oct 16 '11 09:10

AM-


People also ask

How can I create session ID in PHP?

Starting a PHP Session To begin a new session, simply call the PHP session_start() function. It will create a new session and generate a unique session ID for the user.

How can you generate a session ID?

The session ID is generated using the Random Number Generator (RNG) cryptographic provider. The service provider returns a sequence of 15 randomly generated numbers (15 bytes x 8 bit = 120 bits). The array of random numbers is then mapped to valid URL characters and returned as a string.

Is PHP session ID unique?

It's not a firm uniqueness condition especially from a security perspective.

What is Session_regenerate_id ()?

session_regenerate_id() will replace the current session id with a new one, and keep the current session information. When session. use_trans_sid is enabled, output must be started after session_regenerate_id() call. Otherwise, old session ID is used.


1 Answers

If you pass a string to the session_id() function before calling session_start(), you can set the session ID yourself. For example:

function generate_id() {
  ...
  return $your_id;
}

session_id(generate_id());
session_start();
like image 110
MVS Avatar answered Sep 19 '22 16:09

MVS