SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: sessions...

  1. #1
    SitePoint Enthusiast ErikN's Avatar
    Join Date
    Jul 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sessions...

    ive got a script where someone logs in with their username, and password. now im having trouble because when they go from one page to the next, their own information(such as their real name), isn't showing up, instead some other members info is. so im trying to use sessions so that their information will show up. so far i have been successful, except i never closed the session, so that is causing a problem now, here is the more important code on the page
    PHP Code:
    session_start();

    if(!isset(
    $username)) {
    header("location: index.php");
    exit;
    }

    session_register("username");
    session_register("password");
    srand(microtime() * 1000000);

    $uniqid uniqid(rand());
    session_id($uniqid);
    session_id($username);

    if (
    $gameauth == "ok") {

    $today date("l, F jS Y");

    $db_name"hammer_time";

    $table_name "titanwarfare";

    $connection = @mysql_connect("localhost""hammer_time""pwd") or die("Couldn't connect.");

    $db = @mysql_select_db($db_name$connection) or die("Couldn't select database.");

    $sql "SELECT username
         FROM 
    $table_name
         WHERE username = \"
    $username\" and password = password(\"$password\")
    "
    ;

    $result = @mysql_query($sql$connection) or die("Couldn't execute query.");

    while (
    $row mysql_fetch_array($result)) {

    $username $row['username'];
    $belief $row['belief'];
    }

    if (
    mysql_num_rows($result) == 0) {
            
    session_unregister("username");
            
    session_unregister("password");
            
    header("location: index.php");
            exit;

    as you can see i registered two variables, their password and username. it worked the first time i went to the site after adding the session stuff, except when i made another account, and logged in on that, it showed the information from the account i logged in with before. and also, how would i close the session here? thanks in advance for any help

  2. #2
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    session_start();
    session_destroy();

    That will end your session...


    To answer your other question I'm kinda stumped... You say when you want to show the persons real name it comes up with someone else's information? You would happen to be changing your variable $username to something else at any time? Because I once had a problem with changing the variable name of what was registered in the session and it really messed up my session.

  3. #3
    SitePoint Enthusiast ErikN's Avatar
    Join Date
    Jul 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the variables are fine...but where do i put session_destroy(); ?
    now i think it shows someone else's information because i never ended the session...
    Last edited by ErikN; Jul 3, 2001 at 09:38.

  4. #4
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just put it in an if statement... Then somewhere on the page have a link that would kill the session, its just a:

    <a href=$PHP_SELF?logout=yes>Logout</a>

    Then that would execute this.

    <?
    if(isset($logout)){
    session_start();
    session_destroy();
    }
    ?>

    Either that or just have it on it's own page called something like logout.php then just link to that page. You would put on that page "You are now logged out. Or just have the page jump to another.

  5. #5
    SitePoint Enthusiast ErikN's Avatar
    Join Date
    Jul 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh, i finally gave up on sessions and got it working with cookies...thanks for all the help though


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
  •