Sessions and Query String Variable Handling
| From: | Dennis Moore | Date: | Sat, 27 Apr 2002 21:37:02 +0000 |
| Subject: | Sessions and Query String Variable Handling | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-94944@lists.php.net to get a copy of this message | ||
Env: Apache 1.3.x/php4.0.6/mysql3.23.x
Scenario: I have built a system that uses PHP sessions for user access. Within the system I send
user notifications via email. Within the email are links to certain pages with variables. For
example.
http://mysite.com/view_page.htm?id=6
My system checks to see if the session is valid. Since the user is coming from an email. There is
no session. So the user is prompted for the user and password. They enter and click submit. The
authentication passes the user to right page, but losses the variables in the query string. Thus
causing errors.
Here is the authentication code...
#### set session settings from login form
if (!session_is_registered("valid_user") && $session_login=="proc") {
if ($userid && $password) {
// if the user has just tried to log in
$db_conn = mysql_connect("localhost");
mysql_select_db("$dbname", $db_conn);
$query = "select * from auth_users "
."where auth_username='$userid' "
." and auth_password='$password' ";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 ) {
// if they are in the database register the user id
$valid_user = $userid;
$valid_group=mysql_result($result,0,"auth_group");
$valid_perms=mysql_result($result,0,"auth_perms");
$valid_auth_id=mysql_result($result,0,"auth_id");
session_register("valid_user");
session_register("valid_group");
session_register("valid_perms");
session_register("valid_auth_id");
} else {
$invalid_login= "Invalid login: Could not log you in...
<!--ERROR: $dbname <P> $query-->";
}
}
}
Any Ideas on how to pass the query string variables through the authentication process?