Go Back To Code List
[Cookies]
Current Code Entry
Go Back To Code List
[Cookies]
How to get the value of a cookie when it is first created
Article Entry Date: February 7,2023 @ 06:22:05 / Last Updated On: February 25,2024 @ 06:59:34
How do you use a cookie in ASP Classic right after it is created on the page?

(Updated: 6:33 PM - February 25, 2024)

[How cookies work]
For the example of this script, we have a cookie created when the visitor loads the page.
The cookie is then used to create an entry in the database that checks every time the page is loaded to see if the cookie exists and if it matches the cookie data we have stored in the database.


The original way I was doing this was by doubling the INCLUDE FILE for the Hits.asp page. This worked but was not the correct way.
While working on the Radio site, I ran into this issue once again, but this time, instead of doing it the easy way, which was doubling the Hits.asp include file.
I decided to try something else:

    [How we do this.].
  1. Add the cookie Creation script to the top of the of the page.
  2. Then we place the Database hits counter at the bottom, FOOTER of the page.
  3. With the Cookie being created in the header of the page, the Cookie is ready to be read in the body of the page. See the demo script for an example.


First, we place our header code at the top of the page.

Next, we have our HTML script for our page.