473,804 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to store a class in a cookie and retrieve?

Hi,
I have the following script
<%@LANGUAGE=Jav ascript%>
<%
var myClass = new LoginInfo();
myClass.session ID = "1321312131 ";

Response.Cookie s("testingCooki es") = myClass;

var recievedCookies = new LoginInfo();
recievedCookies = LoginInfo(Respo nse.Cookies("te stingCookies")) ;

Response.Write( recievedCookies .sessionID);
Response.End();

function LoginInfo()
{var sessionID;}
%>

How to make it work?

Cheers

Mar 22 '07 #1
1 1563

<yo******@gmail .comwrote in message
news:11******** **************@ p15g2000hsd.goo glegroups.com.. .
Hi,
I have the following script
<%@LANGUAGE=Jav ascript%>
<%
var myClass = new LoginInfo();
myClass.session ID = "1321312131 ";

Response.Cookie s("testingCooki es") = myClass;

var recievedCookies = new LoginInfo();
recievedCookies = LoginInfo(Respo nse.Cookies("te stingCookies")) ;

Response.Write( recievedCookies .sessionID);
Response.End();

function LoginInfo()
{var sessionID;}
%>

How to make it work?

Cheers
You need to enable your object to serialise and deserialise the state of the
object to a string.

For example (by no means a complete implementation and is air code). :-

function LoginInfo(vsSta teIn)
{
var moState = vsStateIn ? eval(vsStateIn) : {}
vsStateIn = null

this.getSession ID = function() { return moState.session ID; }
this.putSession ID = function(value) { moState.session ID = value; }

this.serialise = function()
{
var sState = '{'
for (var key in moState)
{
if (sState.length 1) sState += ', '
if (typeof(moState[key]) == 'string')
sState += key + ": '" + moState[key].replace(/([\\|\'])/g,
'\\$1') + "'"
else
sState += key + ": " + moState[key].toString()
}
sState += '}'
return sState
}
}
To store the object:-

var oLogin = new LoginInfo()
oLogin.putSessi onID("132131213 1")

Response.Cookie s("testingCooki es") = oLogin.serialis e() ;
To retrieve the object:-

var oLogin = new LoginInfo(Reque st.Cookies("tes tingCookies").I tem)
if (oLogin.getSess ionID == "1321312131 ")
{

//is logged on

}
For further Ideas google JSON

Mar 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2585
by: Phil Powell | last post by:
URL: http://valsignalandet.com/cookiegrab.php?name=valIdentifier This page produces a cookie value and sends it back as HTML using PHP and Javascript to obtain it. This URL will be used as the value for a URLConnection object in a Java class to obtain the results of this page to get, of all things, a cookie value. Simply put: it's the ONLY way I know of where I can use Java to ultimately obtain a cookie since this is an application...
2
3749
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into the appropriate array. For instance if I receive a RCVD_MSG1, I'll copy into msg1 . Upon receipt of the next RCVD_MSG1. I'll copy into msg1 . The Retrieve function when called should retrieve the latest copy. ie. msg1 or msg1 .
3
5979
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change the value of that session cookie in response to a button click in a form, without resubmitting the page. For some reason, the following doesn't seem to work:
4
1735
by: Ziggy | last post by:
The purpose of my application is to require a website visitor to complete a form before participating in a search application. I have a specific reason for doing this with client-side javascript, but I'm not going to go into the explanation of "why." Ideally, the visitor goes to http://www.hopelandinc.com/golf-homes.html. If they haven't registered in 90 days, they'll be redirected to a registration form. Once they complete the reg form,...
3
2198
by: James Geurts | last post by:
This is probably more of an ASP.Net situation rather than c#, but since all of my code behind is in c#, maybe it fits here. I'm wondering, generally, at what point is it too inefficient to store information in a client cookie rather than retrieve it from a datastore. Now, I see the advantage of not storing it in a cookie, but a lot of programs already use cookies to store things from user credentials (roles) to specific user settings....
3
4745
by: Martin | last post by:
Dear fellow ASP.NET programmer, I stared using forms authentication and temporarily used a <credentials> tag in web.config. After I got it working I realized this wasn't really practical. I cannot write to web.config so I cannot dynamically update the credentials while the site is up. Since the FormsAuthentication.Authenticate() method's documentations claims the following: "Attempts to validate the credentials against those contained...
2
2139
by: jmensch | last post by:
Hello. I'm a reasonably new ASP.NET programmer with no prior ASP or web development experience, but a lot of general programming experience. I'm using Visual Web Developer Beta Express 2005. I'm trying to find a way to store data in the URL of my pages. I know that SessionState does this if you go cookieless, and that's useful but it's not what I want because the real data is stored on the server, and only an ID code is
5
4746
by: James | last post by:
hi, I'm trying to remember a user who has visited the page. what i found out was to use persistent cookie, is there any other way that i can remember the user next time he visit? When using cookies, I used the code below to add -----in login.aspx------ Dim aCookie As New HttpCookie("userInfo") aCookie.Values("userID") = "1" aCookie.Expires = DateTime.Now.AddYears(50)
6
1258
by: Peter Hayes | last post by:
I've tried this on another group without any resolution, so let me see if anyone here has an answer - please! ;-) I have a database with which I must communicate queries via a web-based interface. The queries are not in a standard format, but involve strings such as ....&fieldA=value1&fieldA=value2&...fieldA=valuej&fieldB=valueK... being sent to the web interface.
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.