Hi, I am a newbie in PHP. I am trying to work out with PHP session id.. but there r something confuse me.. can someone explain to me please.. thanks first. as i m using this code: session_start(); if(isset($_SESSION['views'])) $_SESSION['views'] = $_SESSION['views']+ 1; else $_SESSION['views'] = 1; echo "views = ". $_SESSION['views']; As what i see here, once i refresh the browser, the session id will increase 1. the problem is, if i 1 to pass the session id from the first page till the last page, but half way the user refresh the browser, then the session id will keep on changing.. so how? besides, when i open 2 different browsers from different pc, the session id for both pc will all showing 1. If in this case, lets say i would like to save the session id into the db, then it will become 2 same session id in the table? i thought the session id will be unique? i really confuse with this session id stuff. can anyone help to explain how exactly the session id run and what is the actual purpose for this.. thanks a lot.
You are not updating the session_id, but the session variable 'views'. In fact you do not need to know the value of the session_id. The session_id never changes within a session. PHP takes care of recognizing the session_id and reconstructing all associated session-variables. The session_id is a unique number used to identify the browser/user-agent. Whenever a visitor requests a page and doesn't have a session yet, a new unique session_id is created. This session_id is given to the browser, usually in cookie. Now everytime the browser comes back, the session_id is read by PHP and all associated session-variables are reconstructed. After the PHP script finishes all session-variables are stored again with the unique session_id so they can be retrieved when the browser comes back for the next request.