SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question session... can i write my code like this?

    hi, i wanna make a login column in my homepage.
    when user is not login,the column will display the login form.
    after the user login, the page will be redirected to the homepage but at the login column, it will display user id and last login date will session initialized.

    i tried to do it,however is not working.

    just wondering,what is the correct flow of this?

    can i write

    HTML Code:
    if(isset($id))
    {
    display account info
    display edit button
    other detail
    }
    
    else
    {
    display login form
    other detail
    }

    another question...

    can i make the same output with the below code?

    Code:
    if(isset($id))
    {
    display account info
    display edit button
    }
    else
    {
    }
    
    display login form
    other detail

  2. #2
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first approach is the correct logic. Are you actually just looking at $id or at $_SESSION['loggedin'] or something of that nature? Because you need to be actually polling the correct session variables.

    Also ensure you have session_start() in your code otherwise your session data won't work.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ZareMedia,

    thanks for your reply...

    oh, means i must repeat the same code (other detail) for both different part?

    for $_SESSION['loggedin'], is it a predefined variable or i need to define it on my own???

  4. #4
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your script which logs in the user should have something similiar to:

    PHP Code:
    // if the login was successful
    $_SESSION['loggedIn'] = true
    Then your main page can do:

    PHP Code:
    if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']==true) {
    // welcome username!
    }
    else
    // display login form 

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks again, ZareMedia...

    ok, i'll try on your suggestion...

    thanks!!!

  6. #6
    SitePoint Zealot backtobasics's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would also be a good idea to start indenting/formatting your code..

    Just passing comment..


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
  •