Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Old 06-19-2006, 02:40 PM Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
I did ask about this a while back but i still can't use it. The function..


<%
Function URLDecode(ByVal What)
'URL decode Function
'2001 Antonin Foller, PSTRUH Software, http://www.motobit.com
Dim Pos, pPos

'replace + To Space
What = Replace(What, "+", " ")

on error resume Next
Dim Stream: Set Stream = CreateObject("ADODB.Stream")
If err = 0 Then 'URLDecode using ADODB.Stream, If possible
on error goto 0
Stream.Type = 2 'String
Stream.Open

'replace all %XX To character
Pos = InStr(1, What, "%")
pPos = 1
Do While Pos > 0
Stream.WriteText Mid(What, pPos, Pos - pPos) + _
Chr(CLng("&H" & Mid(What, Pos + 1, 2)))
pPos = Pos + 3
Pos = InStr(pPos, What, "%")
Loop
Stream.WriteText Mid(What, pPos)

'Read the text stream
Stream.Position = 0
URLDecode = Stream.ReadText

'Free resources
Stream.Close
Else 'URL decode using string concentation
on error goto 0
'UfUf, this is a little slow method.
'Do Not use it For data length over 100k
Pos = InStr(1, What, "%")
Do While Pos>0
What = Left(What, Pos-1) + _
Chr(Clng("&H" & Mid(What, Pos+1, 2))) + _
Mid(What, Pos+3)
Pos = InStr(Pos+1, What, "%")
Loop
URLDecode = What
End If
End Function
%>


This sits in functions .asp but how do i call that on the page i want the url decoding?? thanks
phreakyphonez is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-19-2006, 07:58 PM Re: Decode Function Help
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
You'd call it as if it were a variable.

For example:

Some_URL = URLDecode ("http://www.yoururlhere.com") or something like that.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-20-2006, 05:24 AM Re: Decode Function Help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The code posted is for VB so needs some mods to work for ASP VbScript

here's one I made earlier URLDecode posted at snippet collection.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-20-2006, 06:18 AM Re: Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
But if i call that function in the page how does that change the address? doesnt the function have to be called in the address? I changed the code to the snippet you wrote but i still cannot get it to work? Just i just place this on my page(probably completely wrong, i know)

<% strIn = URLDecode ("http://mywebsite.com/landing.asp?p%3DMichaelJackson+Thriller%26page%3DT rance5") %>


Thankd again for any help.
phreakyphonez is offline
Reply With Quote
View Public Profile
 
Old 06-20-2006, 08:53 AM Re: Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
Ok so i have manged how to decode a string sent accroos to my landing page by doing this <%=URLDecode("mysite")%> but that will only decode what is placed within the function. The info i am sending accross to the landing page is read by a databse but i don't know how to decode it that sense, so basically i end up with errors?
phreakyphonez is offline
Reply With Quote
View Public Profile
 
Old 06-20-2006, 10:18 AM Re: Decode Function Help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
but that will only decode what is placed within the function
Yep, that's how functions work. You pass something to it, that gets processed and something gets passed back.

Quote:
The info i am sending accross to the landing page is read by a databse
Do you mean you are storing it in a database ?

Knowing what error would be a help.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-20-2006, 12:54 PM Re: Decode Function Help
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
As Chris said, the error message would help.

However, your steps would be this:

1) Read info from database.
2) Store info in variable (e.g. strIn, although that's a horrible name for a variable).
3) Process the variable using the function as you are doing now.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-20-2006, 06:56 PM Re: Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
Sorry i should be a little more clear as to what i am trying to do.

I am using a company and i can only pass the param "p" through, so, to pass more info through i would like to encode so i get something like ..

p%3DMichaelJackson+Thriller%26page%3DT rance5

But when that gets to the landing page on my server after it is passed through this company, i need it to decode so that the info that the string is carrying can be read off the database and then the chosen product(in this case a ringtone) can be displayed. At the moment the string is still being passed through as above but it needs to come through something like..

p=MichaelJackson+Thriller&page=Trance5

If i don't get that then the database will be looking for p%3DMichaelJackson+Thriller%26page%3DT rance5 and that does not exist.

I hope this is a little more clear. I am a lnewish to this so me trying to explain is probably not being much help to you.

Thanks again.
phreakyphonez is offline
Reply With Quote
View Public Profile
 
Old 06-20-2006, 07:14 PM Re: Decode Function Help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
then you need to get the querystrings only and pass that to the function

Code:
 
paramP = URLDecode(request.querystring("p"))
paramPage = URLDecode(request.querystring("page"))
If you are leaving the "+" signs in place of a space the URLDecode function will need the "replace(strIn,"+"," ")" line commenting out.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-20-2006, 08:09 PM Re: Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
It's the & sign that won't decode, that then keeps the P param as 1 string instead of say ..

p=200&tone=michael&page=2&cat=pop

I just get..

p=200%26tone=michael%26page=2%26cat=pop

in the address bar and obviosuly the database can't read that as nothing like that for the P param in the databse exists. When sending the info i am using <%=server.URLencode("&")%>

Am i just being really stupid here? starting to confuse me quite abit.
phreakyphonez is offline
Reply With Quote
View Public Profile
 
Old 06-20-2006, 11:31 PM Re: Decode Function Help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the "&" won't decode because it isn't part of the encoding. The & indicates another parameter key/value pair.

You have to get all the parameter values individually before you can decode the encoded ones

in this one
Code:
p=200&tone=michael&page=2&cat=pop
there are four parameters

p, tone, page, cat

in this
Code:
p=MichaelJackson+Thriller&page=Trance5
there are two

p, page

There is something here that is missing;
how are you getting the values for your database query ?
Do you need all the parameters?
if not which ones are actually needed?
which parameters have been URLEncoded before building into the link (so are the ones that need decoding)

BTW. based on this
Quote:
But if i call that function in the page how does that change the address? doesnt the function have to be called in the address? I changed the code to the snippet you wrote but i still cannot get it to work? Just i just place this on my page(probably completely wrong, i know)
and reading between the lines here a little so I may be in error, but the decode needs to be done on the landing page.

You retrieve the querystrings, decode the encoded one then call the DB query with the resulting variables.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-21-2006, 01:22 AM Re: Decode Function Help
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
The question that's coming to mind is...why are you passing a URL in a querystring? Can you not pass a numeric identifier which references a URL in a database?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-21-2006, 08:22 AM Re: Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
I have to pass this through a company that takes payment and then the user hits the landing page, downloads the content and then clicks continue to go back to where they were prev. If i cannot carry over the page number etc the user has to go back to the beginning and then trawl through everything.

There is no URL in the database, the params identify what tone to pick. I can do it just by passing say landing.asp?p=400 which then selets all the relevant info to give the user the correct product but like i say they have to click continue(cannot go back, its on a mobile and this is not an option) and instead of taking them to where they were prev it takes them back to the beginnin...because i cannot carry anything over other than whats in the param "p"

I just want to carry as much info as possible to the landing page and then have it decode in the address bar, not on the page itself... is that classed as server side decoding?

Last edited by phreakyphonez; 06-21-2006 at 08:25 AM..
phreakyphonez is offline
Reply With Quote
View Public Profile
 
Old 06-21-2006, 08:52 AM Re: Decode Function Help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
unless the payment processor and the landing page can accept and pass on the other parameters, you can't
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-22-2006, 03:35 PM Re: Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
Ok thanks and thanks for all the help.
phreakyphonez is offline
Reply With Quote
View Public Profile
 
Old 06-23-2006, 07:07 AM Re: Decode Function Help
Experienced Talker

Posts: 38
Trades: 0
I was being stupid and i have now found a nice way of doing it. Thanks again.
phreakyphonez is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Decode Function Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46648 seconds with 12 queries