469,275 Members | 1,475 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Using Cookies and Session ID's

How to store username and password,cookies

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

I have this code:-
Expand|Select|Wrap|Line Numbers
  1.  <% 
  2. dim numvisits
  3. response.cookies("NumVisits").Expires=date+365 
  4. numvisits=request.cookies("NumVisits")
  5.  
  6. if numvisits="" then
  7. response.cookies("NumVisits")=1
  8. response.write("Welcome! This is the first time you are visiting this Web page.")
  9. else
  10. response.cookies("NumVisits")=numvisits+1
  11. response.write("You have visited this ")
  12. response.write("Web page " & numvisits)
  13. if numvisits=1 then
  14. response.write " time before!"
  15. else
  16. response.write " times before!"
  17. end if
  18. end if
  19. %>
  20.  
Jul 29 '08 #1
11 1674
DrBunchman
979 Expert 512MB
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
Jul 29 '08 #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
I have both in my form, textbox as well as submt button
Is this ok?

response.cookies("a")=b

If ok, then where will be the cookie variable, in a or in b??
Jul 29 '08 #3
DrBunchman
979 Expert 512MB
Say you have the following in your html:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <form name="Form1" method="post" action="thispage.asp">
  3.       <input name="b" type="text" />
  4.       <input type="submit" />
  5. </form>
Then you can use this to store the value typed into the text box as a cookie once the form is submitted:
Expand|Select|Wrap|Line Numbers
  1.  Response.Cookies("a") = Request.Form("b")
And you can retrieve the value of the cookie on a subsequent visit to the page using:
Expand|Select|Wrap|Line Numbers
  1.  c = Request.Cookies("a")
Does this make sense?

Dr B
Jul 30 '08 #4
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...?
Aug 4 '08 #5
DrBunchman
979 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. Dim sSessionID
  2. sSessionID = Session.SessionID
Hope this helps.

Dr B
Aug 5 '08 #6
Your code helped me a lot.But my last question to u------

And where could i see the Session Id??

Thanks Dr B
Aug 7 '08 #7
DrBunchman
979 Expert 512MB
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
Aug 7 '08 #8
Thanks Dr B,

but one thing i want to ask, where could i check this session Id
Aug 7 '08 #9
DrBunchman
979 Expert 512MB
I don't understand what you mean by 'check' - check it against what?
Aug 7 '08 #10
means where could i see that which session IDs is allotted to which session???
Aug 9 '08 #11
DrBunchman
979 Expert 512MB
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.

Expand|Select|Wrap|Line Numbers
  1. Sub Session_OnStart ()
  2.      Application.Lock
  3.      ' Add some code here to store the relevant information somewhere.
  4.      Application.UnLock
  5. End Sub
  6.  
  7. Sub Session_OnEnd ()
  8.      Application.Lock
  9.      ' Add some code here to remove the information.
  10.      Application.UnLock
  11. End Sub
  12.  
Hope this helps,

Dr B
Aug 10 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Vasu | last post: by
3 posts views Thread by Mark | last post: by
8 posts views Thread by Chuck Anderson | last post: by
3 posts views Thread by damezumari | last post: by
2 posts views Thread by StanB | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.