How to display login option when clicked on a button without signing in?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yateesh
    New Member
    • Dec 2012
    • 36

    #1

    How to display login option when clicked on a button without signing in?

    Suppose I have two buttons for comment and like ,
    i need to display "Please login to comment/like "
    with login button shown to users if they havn't logged in .

    How do i do that ?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    usually you do that on the server side by checking, whether the user is logged in (which is usually stored in a session variable).

    Comment

    • yateesh
      New Member
      • Dec 2012
      • 36

      #3
      Okay , but on button click it should check whether the session is set or not and display the message . That requires javascript i think .

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        it doesn’t *require* JS (though you *can* do it with JS).

        what really is required is the answer from the server. if you do that via an HTTP Request by a page (re)load or an HTTP Request by AJAX doesn’t matter to the server. and the question "is the user logged in?" can only be answered by the server.

        although, whether a session is established can be determined by JS without the server, you just need to test, whether the session cookie exists. however, that doesn’t tell you whether the user is actually logged in …

        Comment

        • yateesh
          New Member
          • Dec 2012
          • 36

          #5
          A php page needs to be executed to check if session is established. Can this be done by loading that page into a div that contains login form through js onclick function ? So that it displays login form if session isn't established .

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            you don’t need to load the page itself into a <div>. and checking for the session itself (note: session != session variable) doesn’t tell you whether you still need to log in.

            essentially, if you want to use AJAX to test for a login that’s possible and then you can use any JS means (i.e. event) to trigger the AJAX Request to the server.

            Comment

            • yateesh
              New Member
              • Dec 2012
              • 36

              #7
              Thank you . Have to deal with jquery and ajax now for that .

              Comment

              Working...