• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 802
  • Last Modified:

Parsing a cookie

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
Upperdecker
Asked:
Upperdecker
  • 7
  • 5
1 Solution
 
Richard QuadlingSenior Software DeveloperCommented:
What language are you working in? Does it have a string library or a regular expression library?
0
 
UpperdeckerAuthor Commented:
ASP. Regular Expression ??
0
 
Richard QuadlingSenior Software DeveloperCommented:
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
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
UpperdeckerAuthor Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
UpperdeckerAuthor Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
UpperdeckerAuthor Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
"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
 
UpperdeckerAuthor Commented:
Thank you
0
 
Richard QuadlingSenior Software DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now