Solved

Parsing a cookie

Posted on 2010-08-27
12
788 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

724 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