Hudzilla.org - the homepage of Paul Hudson
Contents > Cookies and Sessions > Using sessions Wish List | Report Bug | About Me ]

10.3.1     Starting a session: session_start()

This is NOT the latest copy of this book; click here for the latest version.

bool session_start ( void )

A session is a combination of a server-side file containing all the data you wish to store, and a client-side cookie containing a reference to the server data. The file and the client-side cookie are created using the function session_start() - it has no parameters, but informs the server that sessions are going to be used.

When you call session_start(), PHP will check to see whether the visitor sent a session cookie - if it did, PHP will load the session data. Otherwise, PHP will create a new session file on the server, and send an ID back to the visitor to associate the visitor with the new file. Because each visitor has their own data locked away in their unique session file, you need to call session_start() before you try to read session variables - failing to do so will mean that you simply will not have access to their data. Furthermore, as session_start() needs to send the reference cookie to the user's computer, you need to have it before the body of your web page - even before any spaces.





<< 10.3 Using sessions   10.3.2 Adding session data >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
edvincent - 07 Sep 2008

http://myadboards.free-site-host.com

A PHP User - 07 Sep 2008

Apparently, none of these comments are, though.

A PHP User - 07 Sep 2008

This is really cool stuff for new user ..

A PHP User - 07 Sep 2008

ru guo ni shi hua ren ni jiu hui kan dong wo zai shuo shen me? ru guo ni kan dong le qing fa ge you jian dao jessewoo (at) gmail (dot) com.

A PHP User - 07 Sep 2008

ru guo ni shi hua ren ni jiu hui kan dong wo zai shuo shen me? ru guo ni kan dong le qing fa ge you jian dao jessewoo (at) gmail (dot) com.

A PHP User - 07 Sep 2008

ru guo ni shi hua ren ni jiu hui kan dong wo zai shuo shen me? ru guo ni kan dong le qing fa ge you jian dao jessewoo (at) gmail (dot) com.

A PHP User - 07 Sep 2008

ru guo ni shi hua ren ni jiu hui kan dong wo zai shuo shen me? ru guo ni kan dong le qing fa ge you jian dao jessewoo (at) gmail (dot) com.

A PHP User - 07 Sep 2008

ru guo ni shi hua ren ni jiu hui kan dong wo zai shuo shen me? ru guo ni kan dong le qing fa ge you jian dao jessewoo (at) gmail (dot) com.

A PHP User - 07 Sep 2008

ru guo ni shi hua ren ni jiu hui kan dong wo zai shuo shen me? ru guo ni kan dong le qing fa ge you jian dao jessewoo (at) gmail (dot) com.

A PHP User - 07 Sep 2008

ni shi ge wang ba dan.

A PHP User - 07 Sep 2008

asdg5ry4577ikgfjkghjghjghk6uiyuiyttyrutryuty

xyz - 07 Sep 2008

setrdgfcbvvchhfghfgh
fkhld,fghfg



hdfogphlrd,thgook,
fopk,yp;le.resdflkd,gfgoplkrymgfvogpkthmoptawmerpodsmg
kgfghf
f,gopdfgdf

xyz - 07 Sep 2008

setrdgfcbvvchhfghfgh
fkhld,fghfg



hdfogphlrd,thgook,
fopk,yp;le.resdflkd,gfgoplkrymgfvogpkthmoptawmerpodsmg
kgfghf
f,gopdfgdf

varaprasad - 07 Sep 2008

hi
this chapter clearly explains the cookies and the sessions theoritically.

varaprasad - 07 Sep 2008

hi
this chapter clearly explains the cookies and the sessions theoritically.

ieg_veeramallamma_bodireddygari@yahoo.co.in - 07 Sep 2008

hi
this chapetr clearly explains the cookies and the sessions theoritically.

ieg_veeramallamma_bodireddygari@yahoo.co.in - 07 Sep 2008

hi
this chapetr clearly explains the cookies and the sessions theoritically.



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is zero plus zero?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow