Beginner Sessions Question

From: Date: Fri, 28 Jun 2002 16:54:42 +0000
Subject: Beginner Sessions Question
Groups: php.general 
Request: Send a blank email to php-general+get-104365@lists.php.net to get a copy of this message
Hello, everyone! I have been learning a little bit about sessions recently, and they seem to be an excellent tool to veer away from the statelessness of HTTP. I have a few questions about sessions though, which will seem like beginner questions to most of you, because they are. 1. I know that you initially begin the session with the session_start() function. Is this function required on all pages in order for the session variables to remain globalized? 2. If you have a "process login" page, which the user is sent to after submitting the login information, is this page ideal to hold the session_register() functions to define global variables and their values? 3. Would this piece of code be good to hold the preferences of a user that has just logged in? <?php session_start(); $link = mysql_connect("localhost", "user", "pass") or die("Could not connect to database."); $db = mysql_db_select("users", $link) or die("Could not select database."); $query = "SELECT user, pass FROM users WHERE user='$user' AND pass='$pass' LIMIT 1"; $result = mysql_query($query, $link) or die("Query was not successful. " . mysql_error()); if(mysql_num_rows($result) < 1) { "User not found. Please try again."; } else { $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass' LIMIT 1"; $result = mysql($query, $link) or die("Query was not successful. " . mysql_error()); while($row = mysql_fetch_array($result)) { $name = $row['name']; $colorpref = $row['colorpref']; $fontpref = $row['fontpref']; $sizepref = $row['sizepref']; } session_register("UserName"); $UserName = $name; session_register("Color"); $Color = $colorpref; session_register("Font"); $Font = $fontpref; session_register("Size"); $Size = $sizepref; } ?> I know it's a lengthy example, but I wrote it, and want to know whether or not that would work to load user preferences into the variables UserName, Color, Font and Size? That about does it for this installment of PHP Session Questions. Please reply directly since I'm on the digest! Thanks in advance, everyone! :o) Martin

« previous php.general (#104365) next »