View Full Version : Session Variables
Neebski
12-23-2008, 12:03 AM
Hello!
I was hoping I could get some help with the problem that I am having. Basically I have a login page created by Dreamweaver it creates the MM_Username and MM_Usergroup no problem BUT I do need to add one more variable after the log in is complete from the users database entry. I have tried messing around with a few things but have had no luck.
Please help!!
Thank you!!
Kevin Neberman
What exactly are we supposed to do with this description?
Neebski
12-23-2008, 10:07 AM
User logs in > forwarded to another page where I want to add a third session variable from their database entry. How would I call that info to add it to their session?
Currently I have the MM_Username and MM_Usergroup that dreamweaver has by default. After the user enters their username and password and successfully logs in I want them taken to a quick page that adds a bacid session variable. Sorry for the misunderstanding.
To add a variable to a session, make sure that the session has been started, then simply add an element to the autoglobal array $_SESSION.
Neebski
12-23-2008, 11:21 AM
I am not sure if I follow correctly... I currently have all the session data compiled and everything is fine but I cant get it to pull the data from the users db entry. I currently have the following code. Sorry, I just posted the whole page.
<?php require_once('../Connections/AyalaPercussion07.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "../SiteLogin/index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_bacid = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_bacid = $_SESSION['MM_Username'];
}
mysql_select_db($database_AyalaPercussion07, $AyalaPercussion07);
$query_bacid = sprintf("SELECT * FROM user_students WHERE username = %s", GetSQLValueString($colname_bacid, "text"));
$bacid = mysql_query($query_bacid, $AyalaPercussion07) or die(mysql_error());
$row_bacid = mysql_fetch_assoc($bacid);
$totalRows_bacid = mysql_num_rows($bacid);
$colname_logedinuser = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_logedinuser = $_SESSION['MM_Username'];
}
mysql_select_db($database_AyalaPercussion07, $AyalaPercussion07);
$query_logedinuser = sprintf("SELECT * FROM users WHERE username = %s", GetSQLValueString($colname_logedinuser, "text"));
$logedinuser = mysql_query($query_logedinuser, $AyalaPercussion07) or die(mysql_error());
$row_logedinuser = mysql_fetch_assoc($logedinuser);
$totalRows_logedinuser = mysql_num_rows($logedinuser);
$_SESSION["bacid"] = "$row_bacid['bacid']";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Creating Session</title>
</head>
<body>
Loged in User:
<?php echo $row_logedinuser['username']; ?>
<br />
BACID: <?php echo $row_bacid['bacid']; ?>
<br />
Session Data:
<?php echo $_SESSION['bacid']; ?>
<br />
Enviroment:
<?php echo $_ENV['bacid']; ?>
</body>
</html>
<?php
mysql_free_result($bacid);
mysql_free_result($logedinuser);
?>
JasonDFR
12-24-2008, 11:57 PM
I don't understand why anyone would ever do this:
if (!isset($_SESSION)) {
session_start();
}
Can someone explain why this was written?
Thanks.
J
Neebski
12-25-2008, 01:47 AM
I have no idea, dreamweaver did it automaticly...
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.