Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ASP Cookies for Recently Viewed products

Featured Replies

Hi all......

 

I'm trying to figure out how to use cookies in ASP to captcha a visitors recently viewed products.

I want to take the productID from the product detail page and use this to set the cookie dictionary.

Then i want to use the dictionary values (productID's) to filter a recordset.

Can anyone help?

Andy

Something like...

Response.Cookies("productViews") = Request.Cookies("productViews") & "," & productID;

SELECT * FROM products WHERE id IN (" & Request.Cookies("productViews")  & ") LIMIT 10;

  • Author

Hi Jock -

Thanks for your reply.

I've tried to create a Dreamweaver recordset based on the method your kindly supplied and although the runs fine when testing it in DW, i get this error when i run the page.

Any ideas?

 

Thanks

 

--error-

 

Error Type:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)

[Microsoft][ODBC SQL Server Driver]

Incorrect syntax near ','.

--error-


here's my code:

[code]
<% Response.Cookies("productViews") = Request.Cookies("productViews") & "," & productID; %>

<%
Dim RSRecentViews__MMColParam
RSRecentViews__MMColParam = "1"
If (Request.Cookies("productViews") <> "") Then
RSRecentViews__MMColParam = Request.Cookies("productViews")
End If
%>
<%
Dim RSRecentViews
Dim RSRecentViews_numRows

Set RSRecentViews = Server.CreateObject("ADODB.Recordset")
RSRecentViews.ActiveConnection = MM_shoppingcart_STRING
RSRecentViews.Source = "SELECT * FROM dbo.Products WHERE ProductID = " + Replace(RSRecentViews__MMColParam, "'", "''") + ""
RSRecentViews.CursorType = 0
RSRecentViews.CursorLocation = 2
RSRecentViews.LockType = 1
RSRecentViews.Open()

RSRecentViews_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
RSRecentViews_numRows = RSRecentViews_numRows + Repeat1__numRows
%>
[/code]

 

 

 

Something like...

[code]
Response.Cookies("productViews") = Request.Cookies("productViews") & "," & productID;

SELECT * FROM products WHERE id IN (" & Request.Cookies("productViews") & ") LIMIT 10;
[/code]

You need to use a WHERE IN clause in your query, then supply it with a comma separated list of id's which it will get from the cookie.

Don't forget to validate the input into the SQL query for SQL/XSS injections.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.