Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2009
    Location
    NYC (Manhattan)
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Global Flag Variable

    Hello fellow coders,

    I'm new to Javascript and PHP and stuff like that, but I have experience programming in HTML, C++, and VB.

    What I'm trying to do:
    I'm creating a login system and have the following requirement. When the user is logged in, I want the their account information displayed at all times at the top of every page. When the user is logged out, I want the login boxes displayed in that same spot on all pages.

    My Questions:
    1) How can I create a Global Flag Variable that spans across multiple pages (sessions??)
    2) Next step is I need to be able to embed HTML code into an if statement that checks this Global Flag variable when the page is opened. e.g. If flag = true, then x.html should look one way, if flag = false, then x.html should look another way.

    Thanks for your help!!!

  • #2
    New Coder
    Join Date
    Jul 2009
    Location
    NYC (Manhattan)
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    P.S. Is Javascript even the right thing to be using here??

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by easypeasy View Post
    P.S. Is Javascript even the right thing to be using here??
    Not really. Ideally you'd be handling this on the server side. You can "dress up" the behavior with javascript/jquery, but the core of the login testing should be on the back side.
    Are you a Help Vampire?

  • #4
    New Coder
    Join Date
    Jul 2009
    Location
    NYC (Manhattan)
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Tom, are you saying I should be using PHP here?

    I did figure out a pretty solid way using "document.cookie" in Javascript to track the login status...

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by easypeasy View Post
    I did figure out a pretty solid way using "document.cookie" in Javascript to track the login status...
    What about people who have Javascript disabled, or have configured their browser to reject cookies?

    As tomws says, this should be done using server-side scripting.

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Agree with Philip. I'd use PHP since it's what I know. Some prefer paying for coding privileges, though, so the dotNET family works for them.

    Forgot to mention Java, too.
    Are you a Help Vampire?


  •  

    Posting Permissions

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