SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: PHP/Sessions

  1. #1
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I Have a page, and i want to display

    "Hello Nickname, Go To My AO?" if a session with a username variable exists.

    if it dont, i want to display

    "Hello Guest, Login or Signup"

    Any ideas?

    Alex
    Nearly 7 years old!

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Create a login form on a page and call it login.php.

    Then have the form submit to itself and have something like this at the top, the $db is part of phplib's mysql db class but you can use your mysql stuff

    <?
    include("common/db.php");
    $db = new DB;
    session_start();
    sess_destroy($sess);
    session_register("SESSION");
    if ($submit) {
    $db->query("SELECT * from auth_user WHERE username = '$username' AND password = '$password'");
    if ($db->num_rows() > 0) {
    $db->next_record();
    $SESSION["username"] = $db->f(username);
    session_register($SESSION["username"]);
    $SESSION["id"] = $db->f(id);
    session_register($SESSION["id"]);
    header("Location: index.php");
    }
    else {
    $error = '<tr><td colspan=2><span class="loginerror">Sorry either your password was wrong or your username does not exist please enter it again.</span></td></tr>';
    }
    }

    ?>


    Then on your other pages simply check for the existence of $SESSION["username"]

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how wpoul i do that?
    Nearly 7 years old!

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would you do what? Check for the existence of $SESSION["username"]



    <?
    session_start();
    if ($SESSION["username"] == "") {
    print "Hello Guest, Login or Signup";
    }
    else {
    printf('Hello %s, Go To My AO?', $SESSION["username"]);
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •