Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Cookies smell good!


  • From: javascript@xxxxxxxxxx (Steve Hearne)
  • Subject: [Javascript] Cookies smell good!
  • Date: Fri, 25 May 2001 09:45:00 +0100

I thought that cookies took their name from the site/page that they're =
created from - i don't want to overwrite the cookie i extracted this info. =
from.


>>> peter@xxxxxxxxxxx 05/24/01 07:20PM >>>

    Can't you just use another cookie?

----- Original Message -----
From: "Steve Hearne" <steve.hearne@xxxxxxxxxxxxx>
To: <javascript@xxxxxxxxxx>
Sent: Thursday, May 24, 2001 12:01 PM
Subject: [Javascript] Cookies smell good!


Yeah!

That works fine - i put in;

var cookiestring=3Ddocument.cookie

and i'm on my way to grabbing the portion i want.  Now, I'd like to be =
able
to save this info. so that i can use it later on.  I suppose that i can't
save it as a cookie because this document already has a cookie - the one i
grabbed the info. from.  So - can i save it, or refer to it from future
pages?  Unfortunately, i can't do any ASP stuff yet because this page MUST
be HTML - the Portal software dictates this.

Any ideas please?
Thanks again for all the help so far btw.
Steve


>>> peter@xxxxxxxxxxx 05/24/01 04:56PM >>>
Oops.

This script returns the asterisk character (change it to something else =
and
see).

<SCRIPT LANGUAGE=3D"JavaScript">

// the string to parse
var cookiestring =3D "|usrsvr*booga|";

// find the beginning of "usrsvr" and then go to the end
var position =3D cookiestring.indexOf("usrsvr") + "usrsvr".length;

 // use the substr function, feeding it the start position and the desired
length of the result
alert(cookiestring.substr(position,1));

</SCRIPT>

----- Original Message -----
From: "Steve Hearne" <steve.hearne@xxxxxxxxxxxxx>
To: <javascript@xxxxxxxxxx>
Sent: Thursday, May 24, 2001 10:28 AM
Subject: [Javascript] Half-baked cookies


Okay - i admit it, i'm cheating.  My JavaScript is a bit poor....Could you
please, please, please give me a bit of code?

I know that immediately previous to the item i want to grab in the string =
is
the value ;

....<ESC?>usrsvr<ESC?>

After this is the username of the peson who is logged into the machine =
(this
cookie is made by portal software - and this seems to be the only way =
which
i can retrieve the users name).  So, i imagine that i need the following
code;

for j=3D1 to len of the cookie string
   if mid(cookiestring,j,6)=3D"usrsvr" then
     username=3Dmid(cookiestring,j+7,10) // this assumes that the username =
is
10 chars long, i can cut it out better later on
  end if
next j

But i'm really not sure how to do this in JavaScript.

Please help if you can,
Steve






>>> peter@xxxxxxxxxxx 05/24/01 04:10PM >>>

    Can you suck in one of those unknown values by grabbing one that has a
known position in the string?  Then you could just walk your way through =
the
string based on the wacky delimiters (which I think was your objective
anyway).

----- Original Message -----
From: "Steve Hearne" <steve.hearne@xxxxxxxxxxxxx>
To: <javascript@xxxxxxxxxx>
Sent: Thursday, May 24, 2001 9:48 AM
Subject: [Javascript] Burnt cookies


Phew.  I wouldn't have thought cookies could be so haaaaaard! Please help =
me
as i am struggling.

I would like to read the 20th item in a cookie when a user hits the page
which generates that cookie.

The items appear to be separated with ''ESC' characters (they appear as
black squares in Notepad) but I am not to sure.

Any help gratefully received.
Thanks,
Steve

>>> steve.hearne@xxxxxxxxxxxxx 05/24/01 03:00PM >>>
Thanks for the help so far.  I've just realised that, because my page is
split into 3 frames, i'm not sure which of these frames will have access =
to
the URL - if any?

Steve

>>> gassinaumasis@xxxxxxxxxxx 05/23/01 04:24PM >>>
>http://servername/servlet/WebClient/main?user=3Dstevehearne&pass=3Dmypassw=
ord&s=20
erver=3D127.0.0.1
>
>Now, when a user has to,for instance fill out a form, then I'd really =
like
>to be able to know what their username is...Can i parse this URL with
>JavaScript once they've arrived at the homepage in order to discover =
their
>username?

Sure

var x =3D location.search;
var y =3Dnew Array();
y =3D x.split('&');

Now the array y contains the name/value pairs of the query string. To find
the user name, do

for (i=3D0;i<y.length;i++)
{
  if (y[i].indexOf('user') =3D=3D 0)
  {
    var z =3D new Array();
    z =3D y[i].split('=3D');
   username =3D z[1];
  }
}

and the username is in variable 'username'.

ppk
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript=20


_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript=20


_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript=20



_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript=20


_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript=20



_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript=20

_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript=20



_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx=20
http://www.LaTech.edu/mailman/listinfo/javascript