ਏਸਪੀ ਕੂਕੀ
- پچھلے پیج ایس پی فرم
- پائیدہ پیج ایس پی سیشن
ਕੂਕੀ ਮੁੱਖ ਤੌਰ 'ਤੇ ਯੂਜ਼ਰਾਂ ਨੂੰ ਪਛਾਣਣ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ।
ਉਦਾਹਰਣ
- ਵਲਕਮ ਕੂਕੀ
- ਕਿਵੇਂ ਵਲਕਮ ਕੂਕੀ ਬਣਾਓ。
ਕੂਕੀ ਕੀ ਹੈ?
ਕੂਕੀ ਮੁੱਖ ਤੌਰ 'ਤੇ ਯੂਜ਼ਰਾਂ ਨੂੰ ਪਛਾਣਣ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ। ਕੂਕੀ ਇੱਕ ਛੋਟੀ ਫਾਈਲ ਹੈ ਜੋ ਸਰਵਰ ਯੂਜ਼ਰ ਕੰਪਿਊਟਰ 'ਚ ਛੱਡਦਾ ਹੈ। ਹਰ ਵਾਰ ਜਦੋਂ ਇਸੇ ਕੰਪਿਊਟਰ ਨਾਲ ਬਰਾਊਜ਼ਰ ਰੂਪ ਵਿੱਚ ਪੇਜ਼ ਮੰਗਦਾ ਹੈ ਤਾਂ ਕੰਪਿਊਟਰ ਕੂਕੀ ਵੀ ਭੇਜਦਾ ਹੈ। ਏਸਪੀ ਰਾਹੀਂ ਤੁਸੀਂ ਕੂਕੀ ਦੀ ਕੀਮਤ ਬਣਾਉਣ ਅਤੇ ਲੈ ਸਕਦੇ ਹੋ।
ਕੋਕੀ ਕਿਵੇਂ ਬਣਾਇਆ ਜਾਵੇ?
"Response.Cookies" ਕਮਾਂਡ ਵਿੱਚ ਕੋਕੀ ਬਣਾਉਣ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ。
ਧਿਆਨ:Response.Cookies ਕਮਾਂਡ <html> ਟੈਗ ਤੋਂ ਪਹਿਲਾਂ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ。
ਹੇਠ ਦੇ ਉਦਾਹਰਣ ਵਿੱਚ, ਅਸੀਂ "firstname" ਨਾਮ ਦਾ cookie ਬਣਾਵਾਂਗੇ ਅਤੇ ਉਸ ਨੂੰ "Alex" ਵੀਚ ਮੁੱਲ ਦੇ ਰਹੇ ਹਨ:
<% Response.Cookies("firstname")="Alex" %>
ਕੋਕੀ ਨੂੰ ਅਟਰੀਬਿਊਟ ਵੰਡਣ ਵੀ ਸੰਭਵ ਹੈ, ਜਿਵੇਂ ਕਿ ਕੋਕੀ ਦੀ ਮੌਤਮੁਕਤੀ ਮਿਤੀ ਸੈਟ ਕਰਨਾ:
<% Response.Cookies("firstname")="Alex" Response.Cookies("firstname").Expires=#May 10,2020# %>
ਕੋਕੀ ਦਾ ਮੁੱਲ ਕਿਵੇਂ ਲੈਣਾ ਹੈ?
"Request.Cookies" ਕਮਾਂਡ ਵਿੱਚ ਕੋਕੀ ਦਾ ਮੁੱਲ ਲੈਣ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ。
ਹੇਠ ਦੇ ਉਦਾਹਰਣ ਵਿੱਚ, ਅਸੀਂ "firstname" ਨਾਮ ਦੇ cookie ਦਾ ਮੁੱਲ ਲੈ ਲਿਆ ਹੈ ਅਤੇ ਉਹ ਮੁੱਲ ਪੰਨੇ 'ਤੇ ਪ੍ਰਦਰਸ਼ਿਤ ਕੀਤਾ ਹੈ:
<% fname=Request.Cookies("firstname") response.write("Firstname=" & fname) %>
ਆਉਟਪੁਟ:
Firstname=Alex
ਕੀਚ ਵਾਲਾ cookie
ਜੇਕਰ ਕੋਈ cookie ਕਈ ਕੀਚ ਦਾ ਸੈਟ ਰੱਖਦਾ ਹੈ, ਤਾਂ ਅਸੀਂ ਕਹਿ ਸਕਦੇ ਹਾਂ ਕਿ cookie ਕੀਚ ਰੱਖਦਾ ਹੈ (Keys).
ਹੇਠ ਦੇ ਉਦਾਹਰਣ ਵਿੱਚ, ਅਸੀਂ "user" ਨਾਮ ਦਾ cookie ਸੈਟ ਬਣਾਵਾਂਗੇ। "user" cookie ਵਿੱਚ ਯੂਜ਼ਰ ਜਾਣਕਾਰੀ ਵਾਲੇ ਕੀਚ ਹਨ:
<% Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Adams" Response.Cookies("user")("country")="UK" Response.Cookies("user")("age")="25" %>
ਸਾਰੇ cookie ਪੜ੍ਹੋ
ਹੇਠ ਦਾ ਕੋਡ ਪੜ੍ਹੋ:
<% Response.Cookies("firstname")="Alex" Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Adams" Response.Cookies("user")("country")="UK" Response.Cookies("user")("age")="25" %>
ਇਹ ਮੰਨਿਆ ਜਾਵੇ ਕਿ ਤੁਹਾਡਾ ਸਰਵਰ ਸਾਰੇ ਇਹ cookie ਕਿਸੇ ਯੂਜ਼ਰ ਨੂੰ ਭੇਜ ਦਿੰਦਾ ਹੈ。
ਹੁਣ, ਅਸੀਂ ਇਨ੍ਹਾਂ cookie ਨੂੰ ਪੜ੍ਹਣਾ ਹੈ। ਹੇਠ ਦਾ ਉਦਾਹਰਣ ਤੁਹਾਨੂੰ ਇਹ ਦਿਖਾਵੇਗਾ ਕਿ ਕਿਵੇਂ ਇਹ ਕੀਤਾ ਜਾ ਸਕਦਾ ਹੈ (ਹੇਠ ਦਾ ਕੋਡ HasKeys ਚੈੱਕ ਕਰਕੇ cookie ਕੀ ਕੀਤੇ ਜਾਣ ਦੀ ਪ੍ਰਕਿਰਿਆ ਕਰੇਗਾ):
<html> <body> <% dim x,y ਹਰ ਕਿਸੇ x ਲਈ Request.Cookies response.write("<p>") if Request.Cookies(x).HasKeys then for each y in Request.Cookies(x) response.write(x & ":" & y & "=" & Request.Cookies(x)(y)) response.write("<br />") next else Response.Write(x & "=" & Request.Cookies(x) & "<br />") end if response.write "</p>" next %> </body> </html>
ਆਉਟਪੁਟ:
firstname=Alex user:firstname=John user:lastname=Adams user:country=UK user:age=25
ਕੂਕੀ ਨਹੀਂ ਸਹਾਰਾ ਵਾਲੇ ਬਰਾਊਜ਼ਰ ਨਾਲ ਕਿਵੇਂ ਕਾਬਲ ਹੋਵੇ?
ਅਗਰ ਤੁਹਾਡਾ ਐਪਲੀਕੇਸ਼ਨ ਕੂਕੀ ਨਹੀਂ ਸਹਾਰਾ ਵਾਲੇ ਬਰਾਊਜ਼ਰ ਨਾਲ ਕੰਮ ਕਰਨਾ ਹੈ ਤਾਂ ਤੁਹਾਨੂੰ ਤੁਹਾਡੇ ਐਪਲੀਕੇਸ਼ਨ ਦੀਆਂ ਪੰਨਿਆਂ ਵਿੱਚ ਸੂਚਨਾ ਪਾਸ ਕਰਨ ਲਈ ਹੋਰ ਤਰੀਕੇ ਵਰਤਣਾ ਪਵੇਗਾ।ਇਹ ਦੋ ਤਰੀਕੇ ਹਨ:
1. URL ਵਿੱਚ ਪੈਰਾਮੀਟਰ ਜੋੜਨਾ
ਤੁਸੀਂ URL ਵਿੱਚ ਪੈਰਾਮੀਟਰ ਜੋੜ ਸਕਦੇ ਹੋ:
<a href="welcome.asp?fname=John&lname=Adams"> ਵੈਲਕੰਮ ਪੇਜ ਜਾਓ </a>
ਫਿਰ ਇਸ ਤਰ੍ਹਾਂ ਦੇ "welcome.asp" ਫਾਇਲ ਵਿੱਚ ਇਨ੍ਹਾਂ ਮੁੱਲਾਂ ਨੂੰ ਲੈ ਲਵੇਗਾ:
<% fname=Request.querystring("fname") lname=Request.querystring("lname") response.write("<p>Hello " & fname & " " & lname & "!</p>") response.write("<p>Welcome to my Web site!</p>") %>
2. ਫਾਰਮ ਦੀ ਵਰਤੋਂ
ਤੁਸੀਂ ਇਹ ਫਾਰਮ ਵੀ ਵਰਤ ਸਕਦੇ ਹੋ।ਜਦੋਂ ਯੂਜ਼ਰ ਸੰਬੋਧਨ ਬਟਨ ਨੂੰ ਕਲਿੱਕ ਕਰੇਗਾ ਤਾਂ ਫਾਰਮ ਯੂਜ਼ਰ ਦਾ ਇਨਪੁਟ ਕੀਤਾ ਗਿਆ ਮੁੱਲ "welcome.asp" ਨੂੰ ਭੇਜੇਗਾ:
<form method="post" action="welcome.asp"> First Name: <input type="text" name="fname" value=""> Last Name: <input type="text" name="lname" value=""> <input type="submit" value="Submit"> </form>
ਫਿਰ "welcome.asp" ਫਾਇਲ ਵਿੱਚ ਇਨ੍ਹਾਂ ਮੁੱਲਾਂ ਨੂੰ ਲੈ ਲਵੇਗਾ, ਅਜਿਹਾ ਕਰਨ ਵਾਲਾ:
<% fname=Request.form("fname") lname=Request.form("lname") response.write("<p>Hello " & fname & " " & lname & "!</p>") response.write("<p>Welcome to my Web site!</p>") %>
- پچھلے پیج ایس پی فرم
- پائیدہ پیج ایس پی سیشن