Re: sessions
| From: | Tech Support | Date: | Fri, 26 Jul 2002 18:56:05 +0000 |
| Subject: | Re: sessions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109851@lists.php.net to get a copy of this message | ||
okay... if register_globals is off then your session handling is going to
change dramatically.
You can read more on it here:
http://www.php.net/manual/en/ref.session.php
Basically, You still use session_start(); at the top of your page, but you
never use session_register, session_is_registered, or session_unregister.
To register a variable in a session use:
$_SESSION['user'] = $username;
or you can use multi-dimensional arrays... recommended to help keep
organized.
$_SESSION['user']['username'] = $username;
$_SESSION['user']['pasword'] = $password;
You can also use $HTTP_SESSION_VARS. I'm not quite sure if there is any
major difference in the two except that $_SESSION is new post ver 4.0.6
To end a session simply
$_SESSION = array();
session_destroy();
Jim Grill
Support
Web-1 Hosting
http://www.web-1hosting.net
----- Original Message -----
From: "Tyler Durdin" <linuxgeek23@hotmail.com>
To: <php-general@lists.php.net>
Sent: Friday, July 26, 2002 1:35 PM
Subject: Re: [PHP] sessions
> Here is the code that starts and registers the session. It is login page
> that logs in to itself so the form that produces $_POST["username"] is
> actually on the same page, but nothing happens until the user logs in. It
> there is something in this code that is not correct or making the other
code
> from the previous mssages not work please let me know. Thanks again for
all
> of the help.
>
>
>
> <?
> session_start();
> $username = $_POST["username"];
> $password = $_POST["password"];
>
> if ($username && $password)
> {
> //user has just tried to login
>
> $db_conn = mysql_connect("server", "user", "pass");
> mysql_select_db("DB_name", $db_conn);
> $query = "SELECT * FROM members WHERE username='$username'and
> password='$password'";
> $result = mysql_query($query, $db_conn);
> if (mysql_num_rows($result) >0 )
> {
> //if they are in the db register the username
> $valid_user2 = $username;
> session_register("valid_user2");
> }
> }
> ?>
>
>
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>