session_start() Creates ssesion ID if none present in request Uses session ID, if present in the request Lets you use $_SESSION http://www.php.net/manual/en/function.sess ion-start.php http://www.php.net/manual/en/function.sess ion-start.php
How is my session associated with my request Each request sends a session id in one of two ways – Cookie – GET parameter (you want to avoid parameters whenever possible)
Session IDs are numbers Hashes from random points in memory
What can I store in a session Serializable Data
What's this serialization thing all about: “It lets you take an object or group of objects, put them on a disk or send them through a wire or wireless transport mechanism, then later, perhaps on another computer, reverse the process: resurrect the original object(s). The basic mechanisms are to flatten object(s) into a one-dimensional stream of bits, and to turn that stream of bits back into the original object(s). Like the Transporter on Star Trek, it's all about taking something complicated and turning it into a flat sequence of 1s and 0s, then taking that sequence of 1s and 0s (possibly at another place, possibly at another time) and reconstructing the original complicated ‘something’.” http://www.parashift.com/c++-faq-lite/serialize- overview.html http://www.parashift.com/c++-faq-lite/serialize- overview.html
What’s serializable in PHP? Simple Data (2, “string”, [1, “a” => 2]) Objects
What’s not serializable in PHP? Resources – Network Sockets – File Handles – Database Connetions
How do I store things in $_SESSION? $_SESSION[“thing1”] = 1 $_SESSION[“my array”] = [1, 1, 2, 3, 5]
How do I retrieve things from $_SESSSION? $thing1 = $_SESSION[“thing1] $myArray = $_SESSION[“my array”]
How to destroy a session? session_destroy() http://www.php.net/manual/en/function.sess ion-destroy.php http://www.php.net/manual/en/function.sess ion-destroy.php
When do I destroy a session The most common reason to destroy a session is when a user logs out.
Where is the session store By default the PHP session backend uses files. http://www.php.net/manual/en/session.confi guration.php#ini.session.save-path http://www.php.net/manual/en/session.confi guration.php#ini.session.save-path http://www.php.net/manual/en/session.confi guration.php
Your consent to our cookies if you continue to use this website.