The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The article shows how to check for enabled cookies by redirecting the user. However, if you're going to check for cookies after a form submission you can simply write a cookie value (eg Response.Cookies("cookiesenabled") = "true") on the page where the form is displayed. This will allow you to check this cookie value on the form processing page. If the cookie value matches what was set on the form page then they've got cookies enabled.

Actually, I thought it had worked the first time I tested it (I guess because my current browser session was still using cookie that had been set), but it didn't. When I tried it on the browser that had cookies turned off the whole time, it just displayed the form instead of the 'cookies must be enabled' message.

I'm sure there's probably a tiny % of users out there who may go and delete the cookie but it's more difficult to get around then just opening a new browser window.

Can somebody tell me what I need to do to get this thing working? Will this work if I add it to the script instead of having the line that contains isEmpty?

Originally posted by JohnSaunders Actually, I thought it had worked the first time I tested it (I guess because my current browser session was still using cookie that had been set), but it didn't.

D'oh! Well shane's suggestion looks like your best bet. It's an interesting piece of info as well about processing order. Everyone knows the order scripts are executed in and things like that, but that's something I hadn't come across before having never tried to detect cookies. Nice one shane!

Just to clear up all the confusion about checking whether the cookie was equal to nothing or not.....

Nothing is a special VBScript keyword, which acts as an null/empty object, i.e. setting an object to Nothing calls the object's deinitialisation routine, and assigns it a null pointer, thereby releasing the previously occupied memory.

The statement "if x = 5" compares the value of the variable x with the number 5, i.e. these types of statement perform comparisons by value.

Since objects aren't simply values, they cannot be compared in this way - surely no one would attempt to compare two objects a Dictionary object with an FSO object!!!?

Likewise, we cannot compare an object with Nothing.

So how do we see if an object is Nothing? It's breathtakingly simple - use the "If [objectname] Is Nothing" statement!!! e.g.[vbs]If MyObject Is Nothing Then[/vbs]
This statement is admittedly VERY poorly documented in the VBScript help file, but that's pretty much all there is to it anyway!

However, since cookies will only ever containt a value (not an object), there is no point performing such a check. I myself set a cookie called "CookiesEnabled" to the value "true" (as a string, not the VBScript True constant), and then see if the cookie is now equal to this value.

Incidentally JohnSaunders, in your penultimate post (at this time anyway) your code is completely wrong because you appear to be interchangably using two variables called "stCount" and "Count" throughout!!! This will never work in the intended fashion!!!

(Presumably at some point you decided to change the variable name from one to the other but never finished the job?!!)

OK...I've put a lot of time in today trying to get this to work and I just can't seem to get it to do what I need to do. I have a form in an .html page that a visitor has to fill out before acessing a certain .asp page. In order for a visitor to access this page, the variables from the form need to be sent to it, or it will direct the visitor back to the .html page. Therefore, I put a code in the top of the cookies.asp file to try and pass the variable but it doesn't seem to be working. If the colEmail=request.form("colEmail") is at the top of the script, it comes up with an error, if it is at the bottom, it acts like it's not in the file and seems to ignore it.

Can somebody look at my code below and tell me what I need to do to get this to work? I am not really familiar with ASP and this whole thing is way more advanced than I ever imagined it would be and I'm stumped. It is currently going back to the .html page (form) whether cookies are turned on or off. It is supposed to go to the .asp page if they are turned on and an error.html page if they are turned off.