Using Cookies and Session ID's

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Raman Pahwa
    New Member
    • Jul 2008
    • 43

    Using Cookies and Session ID's

    How to store username and password,cookie s

    I want to create cookies in which the text written by anyone in textbox should be stored?

    I have this code:-
    Code:
     <% 
    dim numvisits
    response.cookies("NumVisits").Expires=date+365 
    numvisits=request.cookies("NumVisits")
     
    if numvisits="" then
    response.cookies("NumVisits")=1
    response.write("Welcome! This is the first time you are visiting this Web page.")
    else
    response.cookies("NumVisits")=numvisits+1
    response.write("You have visited this ")
    response.write("Web page " & numvisits)
    if numvisits=1 then
    response.write " time before!"
    else
    response.write " times before!"
    end if
    end if
    %>
    Last edited by DrBunchman; Jul 29 '08, 11:09 AM. Reason: Added [Code] Tags - Please use the '#' button
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Then all you need to do is put a textbox in a form with a submit button. Once it's submitted you can request the contents of the textbox and assign it to the cookie variable.

    Hope this helps,

    Dr B

    Comment

    • Raman Pahwa
      New Member
      • Jul 2008
      • 43

      #3
      Originally posted by DrBunchman
      Then all you need to do is put a textbox in a form with a submit button. Once it's submitted you can request the contents of the textbox and assign it to the cookie variable.

      Hope this helps,

      Dr B
      I have both in my form, textbox as well as submt button
      Is this ok?

      response.cookie s("a")=b

      If ok, then where will be the cookie variable, in a or in b??

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Say you have the following in your html:
        Code:
         
        <form name="Form1" method="post" action="thispage.asp">
        	  <input name="b" type="text" />
        	  <input type="submit" />
        </form>
        Then you can use this to store the value typed into the text box as a cookie once the form is submitted:
        Code:
         Response.Cookies("a") = Request.Form("b")
        And you can retrieve the value of the cookie on a subsequent visit to the page using:
        Code:
         c = Request.Cookies("a")
        Does this make sense?

        Dr B

        Comment

        • Raman Pahwa
          New Member
          • Jul 2008
          • 43

          #5
          Dr B,

          Thanx,It Works.

          I also want u help in coding of session ID's. I want to create different id for every session opened by each user.

          Could u Plz help me...?

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            No problem.

            A Session ID is automatically created at the beginning of a user's Session and can be retrieved with the following code snippet:
            Code:
            Dim sSessionID
            sSessionID = Session.SessionID
            Hope this helps.

            Dr B

            Comment

            • Raman Pahwa
              New Member
              • Jul 2008
              • 43

              #7
              Your code helped me a lot.But my last question to u------

              And where could i see the Session Id??

              Thanks Dr B

              Comment

              • DrBunchman
                Recognized Expert Contributor
                • Jan 2008
                • 979

                #8
                What do you mean by where can you see it? You can retrieve it using the code above and do what you like with it, including writing it to the browser if required.

                Have I misunderstood?

                Dr B

                Comment

                • Raman Pahwa
                  New Member
                  • Jul 2008
                  • 43

                  #9
                  Thanks Dr B,

                  but one thing i want to ask, where could i check this session Id

                  Comment

                  • DrBunchman
                    Recognized Expert Contributor
                    • Jan 2008
                    • 979

                    #10
                    I don't understand what you mean by 'check' - check it against what?

                    Comment

                    • Raman Pahwa
                      New Member
                      • Jul 2008
                      • 43

                      #11
                      means where could i see that which session IDs is allotted to which session???

                      Comment

                      • DrBunchman
                        Recognized Expert Contributor
                        • Jan 2008
                        • 979

                        #12
                        Ah I see. I don't think that you can 'see' this information anywhere but you can create the facility to view the information yourself.

                        It depends what sort of information you want to store about each session. If it's just a list of session ID's then you can probably use an array but if you want to store other information about each users session then you might need to use a database.

                        Use the Session_OnStart and Session_OnEnd events in the Global.asa file to add and remove information from your session table.

                        Code:
                        Sub Session_OnStart ()
                             Application.Lock
                             ' Add some code here to store the relevant information somewhere.
                             Application.UnLock
                        End Sub
                        
                        Sub Session_OnEnd ()
                             Application.Lock
                             ' Add some code here to remove the information.
                             Application.UnLock
                        End Sub
                        Hope this helps,

                        Dr B

                        Comment

                        Working...