Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Querystring stripping

Hi,

I have a page of results.  On the page next to each result there is a link that sends the contents of the related field to a form.  The hyperlink sends to the form correctly,  the querystring is as follows:

<a target="_blank" href="http://www.yahoo.com">Search Yahoo</a>

How can I strip that when the form receives it into:
http://www.yahoo.com

Thanks
0
hhammash
Asked:
hhammash
  • 14
  • 9
1 Solution
 
hhammashAuthor Commented:
Sorry,

This is what the querystring sends to the form:
<a target="_blank" href="http://www.yahoo.com">Search Yahoo</a>

This is saved in the form field as it is.  I just want:

http://www.yahoo.com to be saved in the field.

Thanks
0
 
fozyletCommented:
SourceStr = "<a target=""_blank"" href=""http://www.yahoo.com"">Search Yahoo</a>"
StrStart = InStr(SourceStr,"href=")+6
StrEnd = InStr(SourceStr,StrStart,"""")-1
URL = Mid(SourceStr,StrStart,StrEnd-StrStart)


i haven't tested this... so by seeing the resultant string make any fine-tunes like a +/- 1
0
 
hhammashAuthor Commented:
Hi,

Thank you for your reply.

This is the error I am getting after trying the code:

Error Type:
Microsoft VBScript compilation (0x800A0408)
Invalid character
/Pictures4/QuerystringStripping.asp, line 12, column 25
SourceStr = "<a target="_blank" href="http://www.yahoo.com">Search Yahoo</a>"
------------------------^


The querystring sends to the form. The page of the form has:

<%
MyStr=request.querystring("Weblink")
%>

The form field's value is <%=MyStr%>,  it is working fine,  but I want to strip MyStr to a plain URL address like http://www.yahoo.com.

The hyperlink is not known and it might be very long.

Thank you.
0
Technology Partners: 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!

 
fozyletCommented:
After MyStr=request.querystring("Weblink") you have MyStr initialised.

What I am trying to do is to find the starting point and the end point of the url within the form field (i.e. MyStr)

StrStart = InStr(MyStr,"href=")+6

Here StrStart should contain a numeric value pointing to the position where url starts

StrEnd = InStr(StrStart,MyStr,"""")-1

Here StrEnd would contain the end position of the url such that StrEnd-StrStart is the length of the string

URL = Mid(MyStr,StrStart,StrEnd-StrStart) should give you just the url

Please note that the statement StrSource= in my code and yours differ (note that it is "" and not ")
However, this does NOT matter when you are taking the string from a form field
0
 
hhammashAuthor Commented:
Hi,

Thank you for the explanation.

Now I tried your code as it is and got this error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "<a target="_blank" h"]'
/Pictures4/QuerystringStripping.asp, line 14


In the meantime I will try sending the querystring.

Thanks
0
 
hhammashAuthor Commented:
Hi,

When I send the querysrtign I get this error:

Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'InStr'
/Pictures4/QuerystringStripping.asp, line 14


Am I doing anything wrong?

Thanks
0
 
hhammashAuthor Commented:
Hi,

http:// will definitely start after this

<a target="_blank" href="

Counting the spaces and the  quotation marks it will be:
25

and it will end just before ">

Your solution seems logical it is only that I am getting the erros.

hh
0
 
fozyletCommented:
>Error Type:
>Microsoft VBScript runtime (0x800A0005)
>Invalid procedure call or argument: 'InStr'

this could come when the incoming string is empty. please check for this.

also, please note that i made a mistake in the first post StrEnd = InStr(SourceStr,StrStart,"""")-1

it should be InStr(StrStart,SourceStr,""">")

i.e. the point to start searching from should come first (please see the second post)
0
 
hhammashAuthor Commented:
Hi Fozylet,

This is the final code I used. It is working great:

<%
SourceStr = request.querystring("Linkage")
StrStart = InStr(SourceStr,"href=")+6
StrEnd = InStr(StrStart,SourceStr,""">")
URL = Mid(SourceStr,StrStart,StrEnd-StrStart)
response.write URL
%>

Would you please explain this line:

URL = Mid(MyStr,StrStart,StrEnd-StrStart)

Thanks a lot
hh

0
 
hhammashAuthor Commented:
Now I added more points for this part:

I have a page which has a URL in the Address bar of course.

I want to put  a hyperlink on each page,  when the hyperlink is clicked,  the URL of the current page gets sent to another page as a querystring.

i.e:

If the user in on page http://www.mywebsite.com/Products/ProductID=900, when he/she clicks the book mark,  this address get sent to another page as a querystring.  We do not need any stripping here. Just the address as it is.

Thanks lot
hh
0
 
fozyletCommented:
URL = Mid(MyStr,StrStart,StrEnd-StrStart) cuts the string MyStr

StrStart is the position where your URL starts within the MyStr
StrEnd-StrStart is the length of the URL within MyStr

The syntax is...
NewString = Mid(ParentString,StartPosition,Length)
0
 
fozyletCommented:
Are you using ASP? Then your link should look like this...


<a href="newpage.asp?<%=Request.ServerVariables("SCRIPT_NAME")%>">click here!</a>

now at newpage.asp do this...

FromPage = Trim(Request.QueryString)
0
 
hhammashAuthor Commented:
Thank you Fozylet,

What about the other question? is it possible?

Thanks
0
 
hhammashAuthor Commented:
Sorry,  we were posting at the same time.

I'll try it.

Thanks
0
 
fozyletCommented:
Just as an aside (seeing your interest in string manpulation) you could try this too...

If the string is ALWAYS going to be in the format <a target="_blank" href="http://www.yahoo.com">Search Yahoo</a>
just do this...


URLArray = Split(MyStr,"""")
Target =  URLArray(1)
URL = URLArray(3)
Title = Replace(Replace(URLArray(4),">",""),"</a>","")

0
 
hhammashAuthor Commented:
Hi Fozylet,

I tried this code:

<a href="newpage.asp?<%=Request.ServerVariables("SCRIPT_NAME")%>">click here!</a>

now at newpage.asp do this...

FromPage = Trim(Request.QueryString)

It is working fine,  but it is not giving the full URL:

Here is the page to be bookmarked:
http://residenc-9c69f0/Pictures4/BookmarkTheCurrentPage/BookMarkMe.asp

I am getting:
/Pictures4/BookmarkTheCurrentPage/BookMarkMe.asp

It is missing the :
http://residenc-9c69f0

Thanks
0
 
hhammashAuthor Commented:
Hi fozylet,

This code is working but it is giving me Yahoo instead of http://www.yahoo.com

<%
MyStr=request.querystring("Linkage")
URLArray = Split(MyStr,"""")
Target =  URLArray(1)
URL = URLArray(3)
Title = Replace(Replace(URLArray(4),">",""),"</a>","")
%>

Thank you
0
 
fozyletCommented:
<a href="newpage.asp?<%=Request.ServerVariables("SERVER_NAME")%>/<%=Request.ServerVariables("SCRIPT_NAME")%>">click here!</a>


see here for a complete list...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/servervariables.asp
0
 
fozyletCommented:
or just create a page and put this code in it to see the whole servervariables collection

<%
Option Explicit
Dim Item
Response.Write "<table>"
For Each Item in Request.Servervariables
    Response.Write "<tr><td>" & Item & "</td><td>" & Request.ServerVariables(Item) & "</td></tr>"
Next
Response.Write "</table>"
%>
0
 
hhammashAuthor Commented:
Thanks a lot.

<a href="newpage.asp?<%=Request.ServerVariables("SERVER_NAME")%>/<%=Request.ServerVariables("SCRIPT_NAME")%>">click here!</a>

What I did is:

<a href="IwasIn.asp?http//:<%=Request.ServerVariables("SERVER_NAME")%>/<%=Request.ServerVariables("SCRIPT_NAME")%>">click here!</a>


Is it OK this way or there is a solution to actually show http://


Thank you fozylet
0
 
hhammashAuthor Commented:
Hi again,

why am I getting

Yahoo

Instead of

http://www.yahoo.com

When I try this code:

<%
MyStr=request.querystring("Linkage")
URLArray = Split(MyStr,"""")
Target =  URLArray(1)
URL = URLArray(3)
Title = Replace(Replace(URLArray(4),">",""),"</a>","")
%>

Thanks a lot
0
 
fozyletCommented:
Thanks for the accept.

As I said, the second method will work only if the string is exactly the same format each time. The approach is to split the string into an array such that a quote is the delimiter. Hence I expect this to be the result...

Input:
<a target="_blank" href="http://www.yahoo.com">Search Yahoo</a>

Output:
URLArray(0) - <a target=
URLArray(1) - _blank
URLArray(2) -  href=
URLArray(3) - http://www.yahoo.com
URLArray(4) - >Search Yahoo</a>

if there is something different in the format of the incoming string this wont work (as you can evidently see).
0
 
hhammashAuthor Commented:
Thank you fozylet
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 14
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now