Advanced Search

Results 1 to 7 of 7

Thread: Session Variables

  1. #1
    Join Date
    Jan 2006
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Session Variables

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What exactly are we supposed to do with this description?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2006
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. The Following User Says Thank You to Twey For This Useful Post:

    Neebski (12-24-2008)

  6. #5
    Join Date
    Jan 2006
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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 Code:
    <?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);
    ?>

  7. #6
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I don't understand why anyone would ever do this:

    Code:
    if (!isset($_SESSION)) {
      session_start();
    }
    Can someone explain why this was written?

    Thanks.

    J

  8. #7
    Join Date
    Jan 2006
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I have no idea, dreamweaver did it automaticly...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •