How to set id in session in php
I have some basic session handling in my application. In each page I check if the user is logged in. If they are then they're already identified by Show I would also like to record visits by guests (not logged in) based on a unique id. I had assumed that once
Thanks for any help...
Michel 4904 silver badges11 bronze badges asked Aug 15, 2011 at 18:11
There are 2 ways to use sessions and session id's in PHP: 1 - Auto generate the session ID and get it:
2 - Set the session ID manually and then start it:
If you intend to set the session ID, you must set it before calling session_start(); If you intend to generate a random session_id (or continue one already started in a previous page request) and then
get that id for use elsewhere, you must call
Code Lღver 15.5k16 gold badges54 silver badges74 bronze badges answered Aug 15, 2011 at 18:28
BrianBrian 3,00318 silver badges27 bronze badges 2 Here you can see it works for me (session is started silently) : http://sandbox.phpcode.eu/g/f6b6b.php You forgot to start your session, probably answered Aug 15, 2011 at 18:13
genesisgenesis 49.8k20 gold badges94 silver badges123 bronze badges 3 Well, it may be a little bit strange, but when I need unique ID I use uniqid() answered Aug 15, 2011 at 18:16
NausikNausik 7158 silver badges22 bronze badges 1 (PHP 4, PHP 5, PHP 7, PHP 8) session_id — Get and/or set the current session id Descriptionsession_id(?string The
constant Parametersid If
Return Values session_id() returns the session id for the current session or the empty string ( Changelog
See Also
Riikka K ¶ 7 years ago
gmillikan at t1shopper dot com ¶ 7 years ago
ab at ixo point ca ¶ 11 years ago
ohcc at 163 dot com ¶ 5 years ago
Igor Oliveira Ferreira ¶ 7 years ago
Anonymous ¶ 15 years ago
Shiji Jiang ¶ 7 years ago
karlhaines at comcast dot net ¶ 18 years ago
dmeweb at dibsplace dot com ¶ 11 years ago
Drugelis, Lietuva ¶ 12 years ago
hela69 ¶ 4 years ago
Colin ¶ 15 years ago
cbarnes at bfinity dot net ¶ 17 years ago
Anonymous ¶ 16 years ago
Dario Gomes ¶ 11 years ago
jpjounier at hotmail dot com ¶ 17 years ago
Axel ¶ 14 years ago
Francois ¶ 11 years ago
Andi, info at pragmaMx dot org ¶ 19 years ago
infinito84 at gmail dot com ¶ 8 years ago
get_global($key){ 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.
What is a session ID in PHP?Sessions and PHP
PHP allows us to track each visitor via a unique session ID which can be used to correlate data between connections. This id is a random string sent to the user when a session is created and is stored within the user's browser in a cookie (by default called PHPSESSID).
How is session ID generated?The SessionID value is randomly generated by ASP.NET and stored in a non-expiring session cookie in the browser. The SessionID value is then sent in a cookie with each request to the ASP.NET application.
How can I know my session ID in PHP?Check Session ID With session_id() Function
Before you can check for a session ID, you need to start a PHP session with session_start() . Afterward, you can call on the session_id() function. This function will return the current session id.
|