开发者

Classic ASP bind input to variable

I am more of a .Net guy, but the site I currently work on has some legacy Classic ASP pages lying around. In one of the forms we have a couple of hidden inputs that get set to variables created and set by some VBScript at the beginning of the page like so:

<input name="referer" type="hidden" value="<%= oReferer %>" />

That variable is set with the following VBScript:

<script type="text/vbscript" language="vbscript" runat="server">
        dim oReferer
        dim origReferer, arrRefer1, arrRefer2
        origReferer = "self"

        'response.Write("referer - " & Request.ServerVariables("HTTP_REFERER"))
        'response.End()
        if not Request.ServerVariables("HTTP_REFERER") = "" then 
            if not Request.ServerVariables("HTTP_COOKIE") = "" then
                if not len(Request.Cookies("OrigReferer")) > 0 then
                    arrRefer1 = split(Request.ServerVariables("HTTP_REFERER"),"//")
                    if UBound(arrRefer1) > 0 then
                        arrRefer2 = split(arrRefer1(1), "/")
                        if UBound(arrRefer2) > 0 then
                            origReferer = arrRefer2(0)
                        end if
                    end if
                    Response.Cookies("OrigReferer") = origReferer
                    Response.Cookies("OrigReferer").Expires = DateAdd("d", 120, Date())
                else
                    oReferer = Request.Cookies("OrigReferer")
                end if 
            else
   开发者_高级运维             oReferer = "no cookies"
            end if
        else
            oReferer = "self"
        end if
<script>

This code works all fine, most of the time. When I try using this code in a newer version of the form I am getting two issues. First the input itself does not get set at all. I am not sure why as the code does have a default so it should always at least be "self". Second issue is that the original code, not written by me, worked using <% oReferer %> to set the value. When I do that now I get a VBScript error, "type mismatch".

Like I said I am a .Net guy and solving this in .Net is not a problem. I don't know Classic ASP as well and I am stumped. I would love to change to .Net but can't for this particular form right now, so any help to figure this out would be great.


<%
    dim oReferer
    dim origReferer, arrRefer1, arrRefer2
    origReferer = "self"

    if not Request.ServerVariables("HTTP_REFERER") = "" then 
        if not Request.ServerVariables("HTTP_COOKIE") = "" then
            if not len(Request.Cookies("OrigReferer")) > 0 then
                arrRefer1 = split(Request.ServerVariables("HTTP_REFERER"),"//")
                if UBound(arrRefer1) > 0 then
                    arrRefer2 = split(arrRefer1(1), "/")
                    if UBound(arrRefer2) > 0 then
                        origReferer = arrRefer2(0)
                    end if
                end if
                Response.Cookies("OrigReferer") = origReferer
                Response.Cookies("OrigReferer").Expires = DateAdd("d", 120, Date())

                ''// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                ''// The problems is that you are not 
                ''// setting the oReferer variable here
                ''// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            else
                oReferer = Request.Cookies("OrigReferer")
            end if 
        else
            oReferer = "no cookies"
        end if
    else
        oReferer = "self"
    end if

    response.write "----------<br>"
    response.write "oReferer=" + oReferer
 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜