www.webdeveloper.com
Results 1 to 8 of 8

Thread: After and Before Login : About PHP & Sessions

  1. #1
    Join Date
    Oct 2012
    Location
    Gujarat, India.
    Posts
    35

    After and Before Login : About PHP & Sessions

    Well, after much work, at last, i have created members system. Well its not completed yet, reason is when i open page it works - it can register new peoples, can login but (till my website doesn't have any memberr-only page.) I don't know how to make "Sign Up" button disappear while user has logged-in and show "Log out" and "User Name" instead. Means, IDK how to tell website that user has logged in. I know it is not big deal, i just don't get how... please help me. Hear my codes...

    1. This part is at end of my login script....
    I think problem is here....
    PHP Code:
    {
    $_SESSION['userName'] = $userName;
    $_SESSION['password'];
    echo 
    'Successfuly logged-in!';
    include 
    'index.php';


    2. This is part of index.php , in that empty division with id "systemTarget", i want to show buttons... like "Sign Up" and "Sign In" if user is not signed in, and "Username" & "Log out" if user isn't signed in.
    HTML Code:
    <div id="wrap_h"><img src="images/jsk_logo_pfc.jpg" style="float:left"/><div id="systemTarget"></div>
    Hope i am clear, In addition: It would be great if somebody also tells me that how to make some pages "members-only" (if i not get from the answer of above)...! :P

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,227
    You'll need some sort of conditional logic in each page where you want the login/sign-out links to appear. This may be a good candidate for something to put into a function so you can call it as/where needed if it will appear on multiple different pages.
    PHP Code:
    if(empty($_SESSION['userName'])) {
        
    // display log-in and sign-up options here
    }
    else {
        
    // display log-out option here

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2012
    Location
    Gujarat, India.
    Posts
    35

    Some more help....

    can i know what i shall do to logout? And in anywhere shall i include ...
    PHP Code:
    session_start(); 
    ?

  4. #4
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    100
    I use this at the top of every page that I'm using sessions on or wanting to carry sessions over on:
    <?php
    ob_start();
    session_start();

    and this on the bottom of every page:

    ob_end_flush();
    ?>

  5. #5
    Join Date
    Oct 2012
    Location
    Gujarat, India.
    Posts
    35
    what does "ob" mean?

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,227
    "ob" = output buffering, something I personally would not bother with unless you have a specific reason to use it. (It's going to add a little bit of processing/memory overhead which, while probably fairly trivial, why bother if you don't actually need it? (There are valid reasons why you might need it, in which case, no big deal.)

    ob_start()
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    100
    It depends on how you make your website and pages. If you start getting "headers already sent" error messages then you may want to consider using ob_start and ob_end_flush.

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,227
    Quote Originally Posted by Alan P View Post
    It depends on how you make your website and pages. If you start getting "headers already sent" error messages then you may want to consider using ob_start and ob_end_flush.
    If things are well designed and properly configured, you shouldn't get those sorts of errors -- but sometimes if I'm using 3rd-party classes, packages, etc., that are not so well designed, it can be useful to add buffering rather than spending time to fix them.

    It can also be useful if you want to compress your output (by using the ob_gzhandler() function as the optional callback parameter in ob_start()).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles