#1
  1. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,566
    Rep Power
    410

    refreshing page on session


    When i loggin to the loggin page.. i created function that if the user name exists in the db and the passwd is correct then initualize a session.. but.. i have a problem.. when i hit refresh.. the session should update to the db.. but it looks like the session is being deleted on a page refresh.. and i dont understand why..
    does anyone see any errors on my code that can cause this?

    PHP Code:

    session_start
    ( );
    function 
    starting_session( ){
    global 
    $_GET$REMOTE_ADDR;

    //Start session and see if variable $ENTRYS is registered with session_register( )
    //else if it is, then just update the database with the new session info

    if( !session_is_registered"ENTRYS" )){   
          
    session_register"ENTRYS" );
          
    $ENTRYS[1] = $_GET['user_name'];
          
    $ENTRYS[2] = $REMOTE_ADDR;
          
    $ENTRYS['id'] = session_id( );
          
    print_r $ENTRYS );
                                   
          
    mysql_query ("INSERT INTO session VALUES( 0,'{$ENTRYS['id']}','$ENTRYS[1]',NULL,'$ENTRYS[2]' )")
          or die( 
    mysql_error( ));
     
    }

    if( 
    session_is_registered"ENTRYS" )){
           
    print_r $ENTRYS );
          
    mysql_query"UPDATE session SET started=NOW( ) WHERE Uname='{$ENTRYS[1]}'" ) or die( mysql_error( ));
     }

    //If user has been inactive for more then two minutes then delete the session
    //information from the session table
     
    mysql_query"DELETE FROM session WHERE started < DATE_ADD( NOW( ),INTERVAL -3 MINUTE )");
     

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    50
    Rep Power
    15
    Where are you calling the starting_session function?
  4. #3
  5. 300lb Bench!
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2001
    Location
    New York
    Posts
    2,349
    Rep Power
    65
    Is there more code? Because based on what you've posted, the function never gets called.

    when i hit refresh.. the session should update to the db
    What exactly are you trying to do?

    If you use PHP's default session handling capabilities, sessions are stored as files. They only get updated when information is added to it or taken away.

    but it looks like the session is being deleted on a page refresh
    What makes you say that? Again, if you're using php's default session handling, session info is sent to the user either as a cookie or within the url (depending on your php.ini file). You can do two things to verify the state of your session. First, check the session file and verify that once you've stored info in it, it's still there. Second, type the following in your address bar

    javascript:alert(document.cookie)

    If you see something like PHPSESSIONID (assuming defaults here) then you're session has not been deleted.

    Looking at the code you posted, it looks like you're using some type of custom session handling. My question to you would be, why not just use php's default session handling? I'm not saying that custom sessions are bad, just that you should have a valid reason for introducing extra complexity to your site.
  6. #4
  7. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,566
    Rep Power
    410
    Im calling the function on another script
    a logging script once the passwd is correct..
    then the code goes like this

    PHP Code:
    starting_session$_GET 
    i have that on the logged in script here it is

    PHP Code:

    if( isset( $_GET['submit'] )){
     if( !empty( 
    $_GET['user_name'] ) and !empty( $_GET['_pwd'] )){
         
    $S mysql_query"SELECT count( * ) FROM Users WHERE AcctName='{$_GET['user_name']}'" );
         
    $A mysql_fetch_array$S ) or die( mysql_error( ));
        
        if( 
    $A ){ 
         if( 
    $_GET['_pwd'] == $A['Passwd']){
             
    starting_session$_GET );
             print 
    "accepted";
             
    print_r$ENTRYS );
             
    //echo "<meta http-equiv=\"refresh\" content=\"0; url=/loggin.php\">";
         
    }else{
              print 
    "Password incorrect";
       }
      }else{
        print 
    "And an error was an born";
      }
     }else{
            print 
    "You did not fillin all the blanks";
        }
    }else{ 
    the problem is that it does not want to update the time in the table..and its creating a new row in the db field

IMN logo majestic logo threadwatch logo seochat tools logo