Advanced Search

Results 1 to 8 of 8

Thread: session makes it dissapear

  1. #1
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default session makes it dissapear

    Hi,
    i have session like this:
    PHP Code:
    <?php
    include('db_conn.php');

    if(isset(
    $_POST['submit'])) {
        
        
    $password md5($_POST['password']);
        
    $q mysql_query("SELECT * FROM reg_users WHERE Nick='$_POST[nick]' AND Password='$password'") or die(mysql_error());
        
        if(
    $_POST['password'] == '') {
            
    $error .= "";
        }
        if(
    $_POST['nick'] == '') {
            
    $error .= "";
        }
        
        if(
    mysql_num_rows($q) == 0) {
            
    $error .= "<li></li>";
        }
        
        if(isset(
    $error)) {
            echo 
    '<font color="#ff0000">';
            echo 
    '<ol>'.$error.'</ol></font>';
            
        } else {
            
            
    $r mysql_fetch_array$q ) or die(mysql_error());
            
            
    session_start();
            
    $_SESSION['nick'] = $_POST['nick'];
            
    $_SESSION['password'] = md5($_POST['password']);
            
    $_SESSION['authID'] = $r['id'];
            
    header("Location: http://www.xz.lt/index.php");
        }
    }

    if(
    $_GET['act'] == 'logout') {
        echo 
    '<center><font color="Green">You\'re successfully logged out.</font></center>';
        
    session_unset();
        
    session_destroy(); // remove the entire session
        
    header("Location: http://www.xz.lt/login.php");
    }

    ?>
    The thing is, that i want some text be written only when session is on... when i logged i can see, when im not logged i cant. i really need help with that. THANKS
    Last edited by auriaks; 11-09-2009 at 12:19 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Before you unset the session, try giving the value NULL.
    Jeremy | jfein.net

  3. #3
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    ant what it changes?

  4. #4
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Wait, lemme see if I understand:
    When a user logs in, he makes a session, and that session is outputted to the page. When he logs out you can still see the session. You want him to NOT be able to see the session when logged out.
    Jeremy | jfein.net

  5. #5
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    yes... i done it in this way:
    i used $secret = 'this is my secret';
    and added it to if isset session. then i write somewhere in my page <?php include $secret ?> and it works. But its unsafe i think.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    I fail to see the variable $secret.
    Jeremy | jfein.net

  7. #7
    Join Date
    Jul 2009
    Location
    Coquitlam BC Canada
    Posts
    46
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    I think the code shown is the one before auriaks added the variable.

  8. #8
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    if sessiom begins there is no errors->>
    PHP Code:
    <?php 
    if ($error) {} else {
    include(
    'db_conn.php'); 
    session_start(); 

    if(isset(
    $_SESSION['authID'])) { 
    $q mysql_query("SELECT * FROM reg_users WHERE Nick='$_SESSION[nick]'") or die(mysql_error()); 
    $r mysql_fetch_array$q ) or die(mysql_error()); 
    //atsiras
    $date date("Y-m-d");
    $count1 '1';
    $nick $_SESSION['nick'];
    mysql_query("UPDATE reg_users SET date = '$date' WHERE nick = '$nick'");
    mysql_query("UPDATE reg_users SET count = '$count1' WHERE nick = '$nick'");
     
    $logas "<a href='index.php?act=logout'>Atsijungti</a>";


    } else { } 
    if(
    $_GET['act'] == 'logout') {
        echo 
    '<center><font color="Green">Sėkmingai atsijungėte.</font></center>';
        
    session_unset();
        
    session_destroy(); // remove the entire session
        
    include('db_conn.php');
        
    $count2 '0';
        
    mysql_query("UPDATE reg_users SET count = '$count2' WHERE nick = '$nick'");
    }
    }
    ?>
    <html>
    <?php echo $logas ?>
    </html>

    And If everything is good i have logout link

    If error comes this stops as i choosed if statement. THATS WHAT I MEAN THANKS YOU GUYS

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
  •