Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

What am I missing?

I've searched the forums, and actually the internet for last couple of hours,
without any luck. Hopefully someone here knows. The code is below.
What I'm trying to accomplish is this.

Say user goes to http://domain.com?memberid=x
Then they will be redirected to http://domain.comindex.asp?memberid=x

But let's say they type in some extra crap like http://domain.com?memberid=x/etcetcanything.asp
then it should redirect to http://domain.com/others

So the following code just goes to the first line, so long as it detects that first "memberid" then it will not look any further. How do I tell it that it has
to be an exact match? Or alternative solutions?

Thanks for the help!

<%

Dim strMem
strMem=Request.Querystring("memberid")

If Request.QueryString("memberid") <> "" Then
Response.Redirect("http://domain.com/?memberid="&strMem&"")
Else
If Request.QueryString("memberid") <> "/etcetcanything.asp" Then
Response.Redirect("/others/Default.asp")

End If
End If
%>

...Help anyone?? I really have tried doing this myself first, for hours now. I would really really appreciate it. Thanks!
[1248 byte] By [JGalt] at [2007-11-11 7:25:26]
# 1 Re: What am I missing?
Yeah, what you're saying in that first line
If Request.QueryString("memberid") <> "" Then
Is: If the variable "memberid" isn't blank, then...

That's not really what you want; you need to make the other test first.

The logic goes something like this:

First check if there is a member ID and additional info beyond that.
If not, check if there is a member id.

The reason I inverted your logic is that, if the additional info is there, you can assume the member id is there!
But just checking the member id isn't blank first will catch ALL cases where the member id isn't blank, whether or not there is additonal info.

So...
Assuming there will always be a forward slash "/" if there is additional data, I guess I would approach this like so:

If InStr(Request.QueryString("memberid"), "/") Then
Response.Redirect("/others/Default.asp")
ElseIf Request.QueryString("memberid") <> "" Then
Response.Redirect("http://domain.com/?memberid=" & strMem)
End If

Note in that last line that I corrected the end of the string - you don't need the final: &"
that you added. You're concatenating a string with strMem; strMem is itself a string, so you don't need to "close the string", as it were.

HTH,

-Andrew
Andrew Cushen at 2007-11-11 17:26:56 >
# 2 Re: What am I missing?
Andrew,

You make perfect sense. THANK SO MUCH!

I actually had tried reversing it before but using exactly
what I posted, just in reverse using the <> instead of just a comma.

I am newbie ya know :o

Again, thanks for taking the time to explain it to me. That was very helpful!

Cheers,

JGalt
JGalt at 2007-11-11 17:28:03 >
# 3 Re: What am I missing?
Glad to help!

It seemed to me that you were having trouble conceptualizing the right approach, so I tried to explain why your code was failing. I myself find it much more useful if the REASON for something is explained to me, rather than just having someone correct my code.

Although having the correct code is better than nothing! ;-)

-Andrew
Andrew Cushen at 2007-11-11 17:29:01 >