Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Parsing a cookie

Posted on 2010-08-27
12
781 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:Richard Quadling
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:Richard Quadling
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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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:Richard Quadling
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
 
LVL 40

Expert Comment

by:Richard Quadling
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:Richard Quadling
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:
Richard Quadling 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:Richard Quadling
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where can I find... 1 43
ASP.NET MVC 2 40
I am having a  Git   issue 6 42
ASP.NET on IIS website not sending PDF file anymore ? [IzillaFramework Cognition] 6 17
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

861 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