Forum Moderators: open

Message Too Old, No Replies

Session problem, cookies blocked?

         

threebytes

7:30 am on May 8, 2004 (gmt 0)

10+ Year Member



previously i was working on cookies in my message board but then recently i changed to use session after reading the thread on the forum. but i experience the problem some time to login to the website

it said that cookies is blocked? and i have no problem login if i permit it. i would like to know why it is happening? is it because of my hosting?

thanks for the help

duckhunter

2:00 pm on May 8, 2004 (gmt 0)

10+ Year Member



Session variables require Cookies to be enabled in the client browser to function.

IIS drops a cookie for Session identification.

Krapulator

10:09 pm on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As duckhunter said, the session variable identifies a client by a unique session ID in a cookie.

A good practice when using session varaiables as logins is to perform a quick cookie test and if the client has cookies swithed off - provide them with a message explaining why cookies are needed to login.

txbakers

3:41 am on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can you post a simple cookie test so I don't have to go hunt for one again?

Thanks.

mattglet

3:13 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



response.cookies("yourtestcookie") = "checkme"

if request.cookies("yourtestcookie") <> "checkme" then
'--- user does not have cookies enabled
end if

-Matt

txbakers

9:32 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can't get any easier than that!

Thanks.

txbakers

4:31 am on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, not so easy.

I included those lines in my ASP page, and with every setting it doesn't write (or read - can't tell which) the cookie until after the page is refreshed.

The first time the page loads, it doesn't find the cookie, yet the code looks like this:

Response.Buffer = true;
var nocookies = false;
Response.Cookies("mycookie") = "test";
if (Request.Cookies("mycookie")!= "test" ) {
var nocookies = true;
}

At first load, nocookies = true, yet when I Refresh the page, nocookies is set to false.

Am I missing something here?

Krapulator

5:11 am on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The cookie is returned in the server headers, so the browser doesn't show the server the cookie you have set until the next request.Thus, you need to set the cookie, perform a redirect and then read the cookie.

txbakers

12:37 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So I'll need two pages to track this. One to set the cookie, the other to read it. If I can't read it, cookies are disabled.

Let me try.

duckhunter

1:28 pm on May 10, 2004 (gmt 0)

10+ Year Member



Yes, you need two round trips. One to Set, One to Read.

This article explains the details:
[asp101.com ]

mattglet

1:46 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



good article duckhunter - sorry about the mislead txbakers.

-Matt

txbakers

4:47 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok that script is working, however another question arises.

If a program is running under localhost, and requires cookies (Session variables) , does the browser setting still matter?

I cranked up my Privacy on IE to Block all Cookies, and the program still launched and ran successfully.

I would have thought that the blocking would have prevented the program from running.

If someone else wants to test it, sticky me and I'll send the URL for the download.

Thanks.

duckhunter

4:49 pm on May 10, 2004 (gmt 0)

10+ Year Member



Yes, I have the same result on the local box. Cookies don't appear to be affected by the IE settings when accessing the localhost.

Krapulator

11:30 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IE bug perhaps? Did you try another browser (just for curiosities sake)?

txbakers

2:49 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try another browser

There are OTHER browsers?