Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send variable through URL in ASCII

Status
Not open for further replies.

sndkick

Programmer
Nov 1, 2000
71
US
I want to link to a page and pass a username through the queryString but I want to send the username in ASCII rather than just normal text. So when the user clicks on my link, they'll see in the address bar something like

..mypage.asp?username=%43%48%52%49%53

rather than

..mypage.asp?username=CHRIS

This is kind of for security reasons, but not really. We just don't want to display the name in the URL. I have to link to a page on a Linux box which can parse out the username from ASCII. I am just having trouble converting to ASCII. Is there any easy way to do this?

Thanks
 
Try using the mid function to isolate each letter and the ASC function to convert it to an ascii character. Build a string(strMes) and add a '%' and the ascii equivalent like I did below. Hope this helps. Good luck.


dim x, strMes
strMes=""

For x = 1 To Len(UserID)
strMes = strMes & "%" & Asc(Mid(UserID, x, 1))
Next

You may now pass strMes along in your URL.

Doug
 
That did help... somewhat. I think I need the Hex value, not the Dec value for the number. Any idea how to derive the hex value?
 
oh I see. Just run this instead.

dim x, strMes
strMes=""

For x = 1 To Len(UserID)
strMes = strMes & "%" & Hex(Asc(Mid(UserID, x, 1)))
Next

All you gotta do is throw the Hex() function around it. After I ran that, I did get your numbers that you used in the example. Sorry for the confusion.

Doug
 
Worked... Thanks a million. I didn't know about those functions. I thought I had tried hex() after the first note, guess i must have had something else wrong too. Thanks.

Scott
 
Hey sndkick,
How are you converting back from hex?

Roj
 
Roj,

Try this...

Dim HexString
Dim i
Dim tmpString

HexString = "%43%48%52%49%53"
tmpString = ""
For i = 2 To Len(HexString) Step 3
tmpString = tmpString & Chr(Val("&H" & Mid(HexString, i, 3)))
Next

Assign your value from the URL to HexString. Then the resulting value of tmpString will be your Name. In case you're wondering what's happening here's the short explanation. You are iterating through the string taking only the numbers. Then you will convert back to a character from the Hex Value of "&H" and the hex number. Hope this helps.

Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top