Solved

Parsing a cookie

Posted on 2010-08-27
12
765 Views
Last Modified: 2012-05-10
Hello,

I have a CN via LDAP that I need to parse for the name between the first and second semicolin. Here is the string of the CN. Geoffrey Stephens (OSV):Geoffrey Stephens:Geoffrey Stephens 780691:780691

I am looking for an example of code for parsing a variable in a cookie?

Thanks,
0
Comment
Question by:Upperdecker
  • 7
  • 5
12 Comments
 
LVL 40

Expert Comment

by:RQuadling
ID: 33548743
What language are you working in? Does it have a string library or a regular expression library?
0
 

Author Comment

by:Upperdecker
ID: 33550732
ASP. Regular Expression ??
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33554441
I would be surprised if ASP didn't have a cookie processor built in.

Doing a google on 'ASP cookies' and selecting the first option ...

http://www.w3schools.com/ASP/asp_cookies.asp

Certainly seems to be everything I would need if I used ASP.

I'm a PHP user and we have $_COOKIE to read a cookie and setcookie to, well, set a cookie.

No need to resort to regular expressions for something with native support.
0
 

Author Comment

by:Upperdecker
ID: 33586461
The issues is that the out put is from an internal security program that is not going to be changed. Therefore I need to parse through the "ALL" string since the individual variables are not being set, and then I will pass it into a session or set a cookie.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33590695
OK. So what EXACTLY are you asking?

A cookie is just a string and is normally comprised of encoded name/value pairs.

So what does the "ALL" string look like?
0
 

Author Comment

by:Upperdecker
ID: 33627238
Sorry, I now realize I have two issues. I'll try to be more specific.

Here is the var from the session I need to parse "HTTP_SERVERNAME_CN Geoffrey Stephens (OSV):Geoffrey Stephens:Geoffrey" I need the middle section between the semi colons. I think I am looking for a command with ubound and lbound in it?

Second I need to get out the "UID ("#")" from the following;

ALL_HTTP
      
HTTP_ACCEPT:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 HTTP_ACCEPT_CHARSET:ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_ENCODING:gzip,deflate HTTP_ACCEPT_LANGUAGE:en-us,en;q=0.5 HTTP_COOKIE:fdx_cbid=22155668541282155018505240025070; ObSSOCookie=BXPXu%2BAVS0caLe5odAGf73bsJwxfAsxIA4QaARG3qxai7vPADQhsHlEFcokbFqPUx5mjqAo2Ip5ARb6UFSGQ1cFRhU3RwflKP4arufddy%2FX6kQVAx9rS3QP6Efv%2FhX2xRQ6%2FB10AfyR2XlXYMWalRjiBZCp90Cvi3%2BKm3ablKpEKKUgA2KIKLibFJEa8nnUs9NN7wzHMzuHRfIrSuNlJa80BfP3hyDrQWY7ZQlsyldkVJP4cHA4jCXqRDBLY%2FDexpd9PKCpgZixUoffIkg88oT7UdritrVaIPM8HfOexamhp6uJqfm0qhuBxQvdZoaQ%3D; WSSOLanguage=en_US; editMode=0; LeditMode=0; SERVERNAMEMailCookie=; ASPSESSIONIDCAASDDQA=BBGFIEMDEMAJLGCEMMIHKEFM; countrytabs=1 HTTP_HOST:amt.web.companyname.com HTTP_MAX_FORWARDS:10 HTTP_USER_AGENT:Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729; .NET4.0E) HTTP_X_FORWARDED_FOR:199.81.158.219, 199.82.243.71 HTTP_SERVERNAME_UID:780691 HTTP_SERVERNAME_FNAME:Geoffrey HTTP_SERVERNAME_SN:Stephens HTTP_SERVERNAME_COMATSTATIONID:MEM HTTP_SERVERNAME_JOBNUMBER:VENDR HTTP_SERVERNAME_MANAGEMENTLEVEL: HTTP_SERVERNAME_COSTCENTER:0010124020 HTTP_SERVERNAME_COMPANYCODE:001 HTTP_SERVERNAME_EMPLOYEETYPE:D HTTP_SERVERNAMEMAIL: HTTP_SERVERNAME_CN:Geoffrey Stephens (OSV):Geoffrey Stephens:Geoffrey Stephens 780691:780691 HTTP_X_FORWARDED_HOST:dev-wgproxy.corp.companyname.com HTTP_X_FORWARDED_SERVER:dev-wgproxy.corp.companyname.com  
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 40

Expert Comment

by:RQuadling
ID: 33627408
That looks like all the headers of an HTTP request. A Cookie will be one of those headers.

Is this one long string? Or do you have it as an array/structure or a set of name/value pairs?

If it is just a string ... wierd!

http://www.asp-dev.com/main.asp?page=54 shows what I think you need to look at.

<% Request.ServerVariables("HTTP_SERVERNAME_CN") %>

is the value.

I'm not a ASP fan, but the snippet below may be of use to you.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33627435
That looks like all the headers of an HTTP request. A Cookie will be one of those headers.

Is this one long string? Or do you have it as an array/structure or a set of name/value pairs?

If it is just a string ... wierd!

http://www.asp-dev.com/main.asp?page=54 shows what I think you need to look at.

<% Request.ServerVariables("HTTP_SERVERNAME_CN") %>

is the value.

I'm not a ASP fan, but the snippet below may be of use to you.
Dim ResultString As String
Try
	Dim RegexObj As New Regex("^(?<Part1>[^:]+):(?<Part2>[^:]+):(?<Part3>[^:]+):(?<Part4>[^:]+)$", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
	ResultString = RegexObj.Match(Request.ServerVariables("HTTP_SERVERNAME_CN")).Groups("Part2").Value
Catch ex As ArgumentException
	'Syntax error in the regular expression
End Try

Open in new window

0
 

Author Comment

by:Upperdecker
ID: 33627517
I'll try the ASP and let you know. Yes, that is the issue that the ALL HTTP is a long string and the var for UID is not set anywhere else, so I need to pasre is out of ALL HTTP. Thanks,
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 500 total points
ID: 33627600
"var for UID is not set anywhere else" ... not according to that link I gave. It specifically mentions unknown headers.

That is why I've used ... HTTP_SERVERNAME_CN

SERVERNAME_CN is what the header is. ASP adds HTTP_ to it and then you can use Request.ServerVariables() to retrieve the value.

In PHP...

$_SERVER['SERVERNAME_CN']

would be the same thing.
0
 

Author Closing Comment

by:Upperdecker
ID: 33630634
Thank you
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33632456
I'm slightly confused by the grade B?

What was I missing. A fully worked example was provided based upon your question, along with references to the specific issues.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Read about why website design really matters in today's demanding market.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now