+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Session variables not working

  1. #1
    os242 is offline x10Hosting Member os242 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    46

    Session variables not working

    Hi there:

    I am pasing variables with session variables through pages, in the fist page (Homepage) the user input his email address and I post it and collect it in a session variable; in a 2nd page I retake the session variable value and keep it in a variable through which I perform a query and the results of such query are also kept in a session variable; This method works in my testing server but not on X10hosting server, could anyone help me wit this? Thanks alot.

    Homepage
    $loginUsername=$_POST['Username'];
    $_SESSION['GuestEMAIL']=$loginUsername;

    2nd page
    $loginUsername=$_SESSION['GuestEMAIL'];
    $result = mysql_query("SELECT * FROM guests, projects WHERE GEMAIL='$loginUsername' AND GPJID=PID");
    while($row = @mysql_fetch_array($result))
    {
    $GID=$row['GID'];
    $_SESSION['GuestID']=$GID;
    $PID=$row['PID'];
    $_SESSION['ProjectID']=$PID;
    }
    echo $_SESSION['GuestID'];
    ...

  2. #2
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: Session variables not working

    You know, you just mind need to call session_start() before calling any $_SESSION variables

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  3. #3
    os242 is offline x10Hosting Member os242 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    46

    Re: Session variables not working

    All pages have session_start() on but they do not pass variables at all.

  4. #4
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    Re: Session variables not working

    Does something simple such as the following work?

    1st page:
    <?php
    session_start();
    $_SESSION['test']="hello";
    header("Location: 2ndpage.php");
    ?>

    2nd page:
    <?php
    session_start();
    session_register(); //just in case...(should not be needed)
    echo "Result:".$_SESSION['test'];
    ?>

  5. #5
    os242 is offline x10Hosting Member os242 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    46

    Re: Session variables not working

    I tried you example and works, but I do not know why my code is not working, it simply does not register the session variables and if it does not then pages cannot be loaded, I'll put all my code, could you please give me any hints? I'll enourmously appreciate it.

    Home.php
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
    session_start();
    }
    $loginFormAction = $_SERVER['PHP_SELF'];
    if (isset($_GET['accesscheck'])) {
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }

    if (isset($_POST['Username'])) {
    $loginUsername=$_POST['Username'];
    $_SESSION['GuestEMAIL']=$loginUsername;
    $password=$_POST['Password'];
    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = "/Audit_Intro.php";
    $MM_redirectLoginFailed = "/Login_Failed.htm";
    $MM_redirecttoReferrer = false;
    include('Connections/Conex.php');
    mysql_select_db($database_Conex, $Conex);

    $LoginRS__query=sprintf("SELECT GEMAIL, GPASS FROM guests WHERE GEMAIL='%s' AND GPASS='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

    $LoginRS = mysql_query($LoginRS__query, $Conex) or die(mysql_error());
    $loginFoundUser = mysql_num_rows($LoginRS);
    if ($loginFoundUser) {
    $loginStrGroup = "";

    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;

    if (isset($_SESSION['PrevUrl']) && false) {
    $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
    }
    else {
    header("Location: ". $MM_redirectLoginFailed );
    }
    }
    include('counter.php');
    ?>

    Audit_intro.php
    <?php
    //initialize the session
    if (!isset($_SESSION))
    {
    session_start();
    session_register();
    include('Connections/Conex.php');
    }

    // ** Logout the current user. **
    $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
    if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
    $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
    //to fully log out a visitor we need to clear the session varialbles
    $_SESSION['MM_Username'] = NULL;
    $_SESSION['MM_UserGroup'] = NULL;
    $_SESSION['PrevUrl'] = NULL;
    unset($_SESSION['MM_Username']);
    unset($_SESSION['MM_UserGroup']);
    unset($_SESSION['PrevUrl']);

    $logoutGoTo = "Home.php";
    if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
    }
    }
    ?>
    <?php
    include('Connections/Conex.php');
    $loginUsername=$_SESSION['GuestEMAIL'];
    $GLLI=date("Y-m-d G:i:s");
    $_SESSION['GLLI']=$GLLI;

    $result=mysql_query("UPDATE guests SET GLLI = '$GLLI' WHERE GEMAIL = '$loginUsername'");

    $result = mysql_query("SELECT * FROM guests, projects WHERE GEMAIL='$loginUsername' AND GPJID=PID");
    while($row = @mysql_fetch_array($result))
    {
    $GID=$row['GID'];
    $_SESSION['GuestID']=$GID;
    setcookie("GuestID","$GID");

    $GNAME=$row['GNAME'];
    $_SESSION['GuestNAME']=$GNAME;

    $PID=$row['PID'];
    $_SESSION['ProjectID']=$PID;
    setcookie("ProjectID","$PID");

    $PNAME=$row['PNAME'];
    $_SESSION['ProjectNAME']=$PNAME;
    }
    ?>

  6. #6
    flinx is offline x10Hosting Member flinx is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    68

    Re: Session variables not working

    Damn... 2 posts merged in 1. At the end you find the solution.

    Just reposting your code with the PHP tags. Easier to read. ;)

    Home.php
    PHP Code:
     <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
      
    session_start();
    }
    $loginFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_GET['accesscheck'])) {
      
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }

    if (isset(
    $_POST['Username'])) {
      
    $loginUsername=$_POST['Username'];
      
    $_SESSION['GuestEMAIL']=$loginUsername;
      
    $password=$_POST['Password'];
      
    $MM_fldUserAuthorization "";
      
    $MM_redirectLoginSuccess "/Audit_Intro.php";
      
    $MM_redirectLoginFailed "/Login_Failed.htm";
      
    $MM_redirecttoReferrer false;
      include(
    'Connections/Conex.php');
      
    mysql_select_db($database_Conex$Conex);
      
      
    $LoginRS__query=sprintf("SELECT GEMAIL, GPASS FROM guests WHERE GEMAIL='%s' AND GPASS='%s'",
    get_magic_quotes_gpc() ? $loginUsername addslashes($loginUsername), get_magic_quotes_gpc() ? $password addslashes($password)); 
       
      
    $LoginRS mysql_query($LoginRS__query$Conex) or die(mysql_error());
      
    $loginFoundUser mysql_num_rows($LoginRS);
      if (
    $loginFoundUser) {
         
    $loginStrGroup "";
        
        
    //declare two session variables and assign them
        
    $_SESSION['MM_Username'] = $loginUsername;
        
    $_SESSION['MM_UserGroup'] = $loginStrGroup;          

        if (isset(
    $_SESSION['PrevUrl']) && false) {
          
    $MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
        }
        
    header("Location: " $MM_redirectLoginSuccess );
      }
      else {
        
    header("Location: "$MM_redirectLoginFailed );
      }
    }
    include(
    'counter.php');
    ?>
    Audit_intro.php
    PHP Code:
     <?php
    //initialize the session
    if (!isset($_SESSION)) 
    {
      
    session_start();
      
    session_register(); 
      include(
    'Connections/Conex.php');
    }

    // ** Logout the current user. **
    $logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
    if ((isset(
    $_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
      
    $logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_GET['doLogout'])) &&($_GET['doLogout']=="true")){
      
    //to fully log out a visitor we need to clear the session varialbles
      
    $_SESSION['MM_Username'] = NULL;
      
    $_SESSION['MM_UserGroup'] = NULL;
      
    $_SESSION['PrevUrl'] = NULL;
      unset(
    $_SESSION['MM_Username']);
      unset(
    $_SESSION['MM_UserGroup']);
      unset(
    $_SESSION['PrevUrl']);
        
      
    $logoutGoTo "Home.php";
      if (
    $logoutGoTo) {
        
    header("Location: $logoutGoTo");
        exit;
      }
    }
    ?>
    <?php
    include('Connections/Conex.php');
      
    $loginUsername=$_SESSION['GuestEMAIL'];
      
    $GLLI=date("Y-m-d G:i:s");
      
    $_SESSION['GLLI']=$GLLI;
      
      
    $result=mysql_query("UPDATE guests SET GLLI = '$GLLI' WHERE GEMAIL = '$loginUsername'");
      
      
    $result mysql_query("SELECT * FROM guests, projects WHERE GEMAIL='$loginUsername' AND GPJID=PID");
      while(
    $row = @mysql_fetch_array($result))
      {
      
    $GID=$row['GID'];
      
    $_SESSION['GuestID']=$GID;
      
    setcookie("GuestID","$GID");
      
      
    $GNAME=$row['GNAME'];
      
    $_SESSION['GuestNAME']=$GNAME;
      
      
    $PID=$row['PID'];
      
    $_SESSION['ProjectID']=$PID;
      
    setcookie("ProjectID","$PID");
      
      
    $PNAME=$row['PNAME'];
      
    $_SESSION['ProjectNAME']=$PNAME;
      }
    ?>
    Edit:
    Instead of

    PHP Code:
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
      
    session_start();

    use

    PHP Code:
    // *** Validate request to login to this site.
     
    session_start(); 
    Likewise in the second script.
    Not

    PHP Code:
    //initialize the session
    if (!isset($_SESSION)) 
    {
      
    session_start();
      
    session_register(); 
      include(
    'Connections/Conex.php');

    but

    PHP Code:
    //initialize the session
     
    session_start();
    include(
    'Connections/Conex.php'); 
    Last edited by flinx; 10-18-2007 at 05:33 AM. Reason: Automerged Doublepost

  7. #7
    os242 is offline x10Hosting Member os242 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    46

    Re: Session variables not working

    Ok, I modify accordingly (get rid of if (!isset($_SESSION)) { and leaving just session_start();) however it does not work still. What else would it be? Thanks so much for your help!!!!!!!

  8. #8
    flinx is offline x10Hosting Member flinx is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    68

    Re: Session variables not working

    What exactly isn't working?
    At the end of your first script what value is $_SESSION['GuestEMAIL'] holding?
    At the beginning of your second script (after session_start()), what value is $_SESSION['GuestEMAIL'] holding?

  9. #9
    os242 is offline x10Hosting Member os242 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    46

    Re: Session variables not working

    Users access the webpage by entering their email address and password, I gather the email address inputed by them in a session variable which help me to access user data previously registered in the DB; so $_SESSION['GuestEMAIL'] of the first script (page) records the inputed user email and I attempt to recover that info by asigning $_SESSION['GuestEMAIL'] value to a variable in the second script (page) and perform a query to access further user information.

  10. #10
    flinx is offline x10Hosting Member flinx is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    68

    Re: Session variables not working

    I know, that's what you explained in the first post. But what is happening instead?
    At the end of your first script what value is $_SESSION['GuestEMAIL'] holding?
    At the beginning of your second script (after session_start()), what value is $_SESSION['GuestEMAIL'] holding?
    Not in theory, but in reality. Do an echo. Tell me the result.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. Email forwarding now working?
    By kscott in forum Free Hosting
    Replies: 1
    Last Post: 10-01-2007, 05:45 PM
  3. Site not working
    By Immortal in forum Free Hosting
    Replies: 1
    Last Post: 09-10-2005, 02:49 PM
  4. Subdomain Not Working
    By ak007 in forum Free Hosting
    Replies: 5
    Last Post: 06-12-2005, 11:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers