If statement asp classic中是否提供通配符?

If statement asp classic中是否提供通配符?,if-statement,vbscript,asp-classic,wildcard,http-referer,If Statement,Vbscript,Asp Classic,Wildcard,Http Referer,我有一个网站与经典的asp使用vbscript。如何检查用户是否来自我网站上的某个目录?我有这个密码 <%Response.Write(Request.ServerVariables("http_referer"))%> 其中写道:。我想写一个if/else语句,首先检查引用的uri是否在目录中 所以我的代码应该如下所示。但我不确定语法。有没有通配符是asp <% Request.ServerVariables("http_referer") == "http://exa

我有一个网站与经典的asp使用vbscript。如何检查用户是否来自我网站上的某个目录?我有这个密码

<%Response.Write(Request.ServerVariables("http_referer"))%>

其中写道:。我想写一个if/else语句,首先检查引用的uri是否在目录中

所以我的代码应该如下所示。但我不确定语法。有没有通配符是asp

<% Request.ServerVariables("http_referer") == "http://example.com/mobile/*"
-1&&

screen.width本质上,您要处理的是一个字符串,因此不能以这种方式使用通配符(除非您使用正则表达式,在本例中,这就像用大锤敲钉子一样)

使用
InStr
函数检查值是否包含要查找的字符串会容易得多。例如:

<% if InStr(Request.ServerVariables("http_referer"), "http://example.com/mobile/") = 0 then
    null
elseif (screen.width <= 699) {
    document.location = "/mobile/mobile_home.asp";
} %>

请注意,我还简化了
if…else
。您不需要两种情况。

您知道要查找的固定url的长度,因此只需查看referer的前n个字符是否匹配即可:

const BASE_DIR = "http://example.com/mobile/"

dim referer: referer = lcase(Request.ServerVariables("http_referer"))

if left(referer, len(BASE_DIR)) = BASE_DIR then
    ...
else
    ...
end if

请记住,任何使用硬编码URL的方法都不是最好的主意,尤其是从维护的角度来看。如果您需要这样做,请考虑在URL中存储一个对象级别变量,这样您就可以在代码< > Global .asa < /Cord>中定义它,并在需要时调用它。所以很明显我混合了asp和javascript。InStr(Request.ServerVariables(“http_referer”)是否有javascript等价物?@user5753132我在答案底部添加了一个javascript示例
<% if InStr(Request.ServerVariables("http_referer"), "http://example.com/mobile/") = 0 then
    null
elseif (screen.width <= 699) {
    document.location = "/mobile/mobile_home.asp";
} %>
if(window.location.href.indexOf("http://example.com/mobile/") > -1 &&
    screen.width <= 699) {

    document.location = "/mobile/mobile_home.asp";
}
const BASE_DIR = "http://example.com/mobile/"

dim referer: referer = lcase(Request.ServerVariables("http_referer"))

if left(referer, len(BASE_DIR)) = BASE_DIR then
    ...
else
    ...
end if