Jump to content

wakenbake

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Posts posted by wakenbake

  1. Again, nothing else is changing the session variables... at the link provided, you can see what they are set to on EVERY page load thanks to a handy debugging information div in the bottom right of every page..... try and login, you'll see what I'm talking about in that window...

     

    http://www.rimersoft.com/rimersoft.admin/

     

    password: doit

     

    hmmmm maybe it's because I have that sidebar function called BEFORE logging in and out...?

  2. The posted code (less the parts I don't have) logs me in. The only thing I can see from the posted code is $x[] = getSidebar($sesh); references the session object. Could the getSidebar() code be overwriting the session data or could any of the other functions or included files be overwriting the session or post data?

     

    nah, all that does is change the way the sidebar looks depending on the session vars. thats my problem. that sesh var is not there when those funcs are run until the second page load. visit the link provided... you'll see the behavior in the debug information popup as you log in

     

    its like: upon successful login (submitting of form with good password), the login is deemed true, and the session var 'loggedin' is set to 1, but it doesn't actually seem to set it. at that point, you refresh the page (resubmit the form or just visit the page again), the session var 'loggedin' is now miraculously set... same thing for logging out... if you logout, you see the successful logout message, but $_SESSION['loggedin'] still is set to 1 until you again refresh or revisit the page...

     

    session vars seem to lag one page view behind after setting???

  3. Here's the code from my main page... lotta includes though...

     

    <?php
    include_once('./classes/class.session.php');
    $sesh = new Session();
    
    include_once('./functions/commonfuncs.php');
    include_once('./functions/galleryfuncs.php');
    include_once('./classes/class.uploads.php');
    include_once('./constants/galleryconstants.php');
    include_once('./constants/siteconstants.php');
    
    
    $loggedin = $sesh->isLoggedIn();
    
    $x = array();
    
    $x[] = getHeader();
    $x[] = getArea();
    $x[] = getSidebar($sesh);
    
    $x[] = '<div id="content">';
    
    // Build the Logout link
    if (strpos($_SERVER['REQUEST_URI'],'?') == true)
    {
    $logoutLink = '<a href="'.$_SERVER['REQUEST_URI'].'&logout=true">CLICK HERE TO LOGOUT</a>';
    }
    else 
    {
    $logoutLink = '<a href="'.$_SERVER['REQUEST_URI'].'?logout=true">CLICK HERE TO LOGOUT</a>';
    }
    
    // ADMIN SWITCHBOARD
    
    if (isset($_POST['loginattempt']) && $_POST['loginattempt'] == '1') 
    // Login was attempted, security check!
    {
    if ($sesh->Login($_POST['pass']) == true)
    {
    	$x[] =  $logoutLink;
    }
    else 
    {
    	$x[] =  '<p><span class="error"><b>DENIED. TRY AGAIN?</b></span></p><br />';
    	$x[] =  $sesh->loginForm();
    }
    }
    elseif (isset($_POST['deleting']) && $_POST['deleting'] == '1') 
    // Files were selected for deletion
    {
    $x[] =  deleteImages($_REQUEST['files']);
    $x[] =  Uploads::drawUploadForm();
    $x[] =  getDeleteSelectBox();
    $x[] =  $logoutLink;
    }
    elseif (isset($_GET['logout']) &&  $_GET['logout'] == 'true') 
    // Logout was attempted, security check!
    {
    $sesh->Logout();
    $x[] =  'You have successfully been logged out...<br /><br />Would you like to:<br />';
    $x[] =  '<a href="./">Log back in</a><br />';
    $x[] =  '<a href="../">Return to '.SITE_NAME.'</a>';
    
    }
    elseif ($loggedin == true) 
    // Successful login has been detected, show upload form.
    {
    $x[] =  $logoutLink;
    } 
    else 
    // not logged in, show login form
    {
    $x[] =  ' <p>Welcome to the <em>'.SITE_NAME.'</em> Content Management System. Please log in!<br /><br /></p>';
    $x[] =  $sesh->loginForm();
    }
    
    // END ADMIN SWITCHBOARD
    
    $x[] = '</div> <!-- content -->';
    $x[] = getFooter();
    
    echo implode("\n",$x);
    ?>
    

     

    This is the class.session.php file contents

    <?php
    class Session
    {
    var $loginPassword = 'doit';
    
    function Session()
        {
            session_start();
            if (ini_get('register_globals') == true)
    	{
    	    foreach ($_SESSION as $key=>$value)
    	    {
    	        if (isset($GLOBALS[$key]))
    	            unset($GLOBALS[$key]);
    	    }
    	}
        }
        
        function set_var( $var_name, $var_val )
        {
            $_SESSION[$var_name] = $var_val;
        }
        
        function get_var( $var_name )
        {
            if (isset($_SESSION[$var_name]))
            {
            	return $_SESSION[$var_name];
            }
        	return false;
        }
        
        function del_var( $var_name )
        {
            unset( $_SESSION[$var_name] );
        }
        
        function del_vars( $arr )
        {
            if( !is_array( $arr ) )
            {
                return false;
            }
            foreach( $arr as $element )
            {
                unset( $_SESSION[$element] );
            }
            return true;
        }
        
        function end_session()
        {
            $_SESSION = array();
            session_destroy();
        }
        
        //functions for logon/logoff
            
        function isLoggedIn()
        {
        	if ($this->get_var('loggedin') == 1)
        	{
        		return true;	
        	}
        	return false;
        }
        
    function Login($pw=false)
    {
    	if ($pw == $this->loginPassword) 
    	{
    		//LOGIN SUCCEEDED
    		$this->set_var( 'loggedin', '1' );
    		return true;
    	}
    	return false;
    }
    
    function loginForm()
    {
    	$x = array();
    	$x[]='<form name="loginform" action="'.$_SERVER['REQUEST_URI'].'" method="post">';
    	$x[]='Password: <input id="login_password" name="pass" type="password" value="" />';
    	$x[]='<input name="loginattempt" type="hidden" value="1" />';
    	$x[]='<input name="sendit" type="submit" value="Login!" />';
    	return implode("\n",$x);
    }
    
    function Logout()
    {
    	$this->end_session();
    }
    }
    ?>
    

  4. *Running WAMPSERVER 2.0c latest, 5.2.6 PHP.

     

    Hey everyone. I'm learning PHP and I'm having trouble with setting and then immediately referencing session variables. I've searched the forums for a repeat post and I think I see a couple that may be describing my problem, but I'm not seeing any answers in them for fixing in it, so here goes:

     

    I've got a login form for a custom content mangement system that I'm writing that, upon submission with a good password, sets the session variable $_SESSION['loggedin'] to the integer 1. Shortly after this setting is made before the script ends, a check on the same session variable decides what to display in a contextual help window based whether or not the user is logged in (on that variable).

     

    Upon submitting the login form, the page reloads but the session variable 'loggedin' doesn't appear to be set immediately. A subsequent reload of the page and it suddenly seemingly for no reason becomes set. Why is this?

     

    I know this is occurring as described because I am print_r()'ing the the $_REQUEST and $_SESSION variables on every page load in a debug information floating div and you can see that upon form submission with a successfully entered password, the $_SESSION array remains empty despite the successful login. If i either resubmit the same form, or visit the same page by URL again, the $_SESSION array suddenly displays the 'loggedin' => 1...

     

    ???

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.