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.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Using session and cookies on cookies disabled browsers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-04, 07:30
oliflorence oliflorence is offline
Registered User
 
Join Date: Aug 2004
Posts: 96
Problem with sessions on cookies disabled browsers

Hello,
I am doing a site where I store a temporary customer ID in cookie and then pass it to a session, this is working fine on browsers with cookies enabled, however it is not if cookies are blocked, here is the logic I used:

-1. detect if there is a session variable with a customer ID

-If there is a session then this is not the first page viewed by the user and there is nothing to do but to leave the session as it is

-If there is no session, check to see if there is a cookie with the customer ID, if there is, it is a returning customer, place the customer id stored in the cookie in the session variable for this visit

-If there isn't it is a first time visitor, place a cookie with the temporary customer id for future visits and place the same customer id in a session for the time being.


The way I have done it is than if a session with the customer id already exist just leave it alone, however on cookie disabled browser it reasigned a new customer ID to the session for each page and I just can't understand why?

here is the code I am using, it is in ASP javascript:

Code:
<%
	//shopping cart
	
		//first we check if the user as a session open with a customer ID
		//to make it easy we will create a customer id which will also be used in the cart
		
		if (String(Session("custId")=="undefined"))
		{
					//the customer does not have a session open for the shopping cart
					//we check if there is a cookie to see if it is an exising customer
					
					var cookie = Request.Cookies("custId");
					if (cookie!= "" && cookie!="undefined")
					{
								//there is a cookie, it is a returning customer, we set the session to the value of the cookie
								Session("custId") = cookie;
							
					}
					else
					{
						//no cookie found, we create a new customer id and set it to both the cookie and the session
						
							var d = new Date();
							var mil = String(d.getTime());
							var custId = mil;
		
								Session("custId") = custId;
								Response.Cookies("custId") = custId;
								var d = new Date();
								var y = d.getYear()+ 2;
									var m = d.getMonth() + 1;
									var day = d.getDate();
									var ExDate =  m +" "+ day + "," + y ;
									
									Response.Cookies("custId").Expires =ExDate;
					
					}
				
		
		}
		


%>
Thanking you in advance,
olivier

Last edited by oliflorence; 10-24-04 at 07:27.
Reply With Quote
  #2 (permalink)  
Old 10-24-04, 19:32
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
from memory (this could be wrong it was ages ago that I learnt this stuff) when you use sessions you actually create a cookie on the clients machine by default. You need to in order to match the user to their session. The cookie contains a session id which is passed to the server to uniquely identify the user...

So, in short, sessions will not work without cookies...
Reply With Quote
  #3 (permalink)  
Old 10-26-04, 09:59
oliflorence oliflorence is offline
Registered User
 
Join Date: Aug 2004
Posts: 96
Yes you are right, I did find that out from the net well after posting this thread, thanks any way,
Regards,
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On