Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are session_id, session_regenerate_id and session_name used for?

Tags:

php

session

ok im a newbie on sessions lets imagine that we have a little login site,

heres a logic

  1. login
  2. if password right = use $_SESSION[isaloginuser] = 1
  3. check session to see menus with if $_SESSION[isaloginuser] = 1
  4. show the menus
  5. the user want to logoff
  6. unset session
  7. destroy session system

what it use

session_register
session_destroy
session_unset
session_start

where does the session_id & the session_regenerate or session_name goes in ? at php site it says

session_id() is used to get or set the session id for the current session.

i still just dont get it, why do we need them anyway ? in real environment what does it do ?

like image 891
Adam Ramadhan Avatar asked Jul 23 '10 14:07

Adam Ramadhan


People also ask

What is the purpose of session_regenerate_id?

Description ¶ session_regenerate_id() will replace the current session id with a new one, and keep the current session information.

What is the main usage of session ID?

A session ID is a unique number that a Web site's server assigns a specific user for the duration of that user's visit (session). The session ID can be stored as a cookie, form field, or URL (Uniform Resource Locator). Some Web servers generate session IDs by simply incrementing static numbers.

What is session regenerate ID?

Definition and Usage. Sessions or session handling is a way to make the data available across various pages of a web application. The session_regenerate_id() function generates a new session id and updates the current one with the newly created one.


1 Answers

No, you don’t need to use them. In general all you need is

  • session_start to start the session handling, and
  • session_destroy to destroy the stored session data (this does not modify $_SESSION), and
  • session_unset to reset the $_SESSION variable (but you can also do $_SESSION = array()).

session_id and session_name are to get and set the current session ID and session ID name (default is PHPSESSID). session_regenerate_id can be used to regenerate/change the session ID of the current session. This might be useful if, for example, you want to refresh the session ID every 10 minutes or after changing the state of authenticity of a user associated with a session.

like image 96
Gumbo Avatar answered Sep 26 '22 09:09

Gumbo