ASP 替代 User-Agent PHP

发布于 2024-12-11 20:27:03 字数 983 浏览 0 评论 0原文

我一直在使用 PHP 片段来检测最终用户的用户代理并根据用户代理提供特定于设备的内容。采用的基本逻辑是……“如果您是 iPad,请访问此 URL……如果您是 iPhone,请访问此 URL……如果两者都不是,请继续您的快乐方式并加载随后的 html”。

PHP 代码片段的一切都运行良好。然而,这些文件现在需要从 ASP 服务器提供,我不知道如何在 ASP 中复制该解决方案。所以,我在这里寻求帮助。已经有一位“ASP 专家”在从事这项工作。但是,我们已经进入了没有解决方案的第二周。如果您能提供任何帮助,我们绝对不胜感激。

下面的示例显示了我一直在使用的 PHP。真正的 HTML 由于其长度已被删除。

<?php

//setting the iPhone / iPod / iPad browser variables

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");

//detecting device browser

if ($iphone == true){
header( 'Location: Webinar_iPhone.mp4' ) ;
}
if ($ipod == true){
header( 'Location: Webinar_iPhone.mp4' ) ;
}
if ($ipad == true){
header( 'Location: Webinar_iPad.mp4' ) ;
}
else {

?>

<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>
This is a test
</BODY>
</HTML>

<?php

}

?>

谢谢,

谢恩

I've been using a snippet of PHP to detect an end-user's user-agent and deliver device-specific content based on the user-agent. The basic logic employed is...."if you're an iPad, goto this URL...if you're an iPhone, goto this URL...if you're neither, continue on your merry way and load the html that follows".

Everything's been working great with the PHP snippet. However, these files now need to be served from an ASP server and I have no idea how to replicate the solution in ASP. So, I'm asking for help here. There's an 'ASP expert' on the job already. But, we're in our second week of not having a solution. Anything you can do to help is definitely appreciated.

The example below shows the PHP I've been using. The real HTML has been removed because of its length.

<?php

//setting the iPhone / iPod / iPad browser variables

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");

//detecting device browser

if ($iphone == true){
header( 'Location: Webinar_iPhone.mp4' ) ;
}
if ($ipod == true){
header( 'Location: Webinar_iPhone.mp4' ) ;
}
if ($ipad == true){
header( 'Location: Webinar_iPad.mp4' ) ;
}
else {

?>

<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>
This is a test
</BODY>
</HTML>

<?php

}

?>

Thanks,

Shayne

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扬花落满肩 2024-12-18 20:27:03

我猜你指的是经典 ASP?您可能想查看 Request.ServerVariables("HTTP_USER_AGENT")

我还没有对此进行测试,但为了模拟您想要的内容,您可以执行以下操作:

Dim iPhone
iPhone = InStr(Request.ServerVariables("HTTP_USER_AGENT"), "iPhone")

If( iPhone > 0 ) Then
     Response.Redirect("Webinar_iPhone.mp4") 
     Resonse.End()
End If

I assume you mean classic ASP? You would want to look at Request.ServerVariables("HTTP_USER_AGENT")

I haven't tested this, but to simulate what you want, you'd do something like:

Dim iPhone
iPhone = InStr(Request.ServerVariables("HTTP_USER_AGENT"), "iPhone")

If( iPhone > 0 ) Then
     Response.Redirect("Webinar_iPhone.mp4") 
     Resonse.End()
End If
一张白纸 2024-12-18 20:27:03

这是我们在主页上用来为移动用户重定向的一个小东西。您可能可以根据您的需要进行调整。

dim u,b,v
set u=Request.ServerVariables("HTTP_USER_AGENT")
set b=new RegExp
set v=new RegExp
b.Pattern="android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile|o2|opera mini|palm( os)?|plucker|pocket|pre\/|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino"
v.Pattern="1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-"

b.IgnoreCase=true
v.IgnoreCase=true
b.Global=true
v.Global=true

if b.test(u) or v.test(Left(u,4)) then response.redirect("SITE-NAME-HERE") end if

This is a little something we were using on our homepage to redirect for mobile users. You could probably adapt it for your needs.

dim u,b,v
set u=Request.ServerVariables("HTTP_USER_AGENT")
set b=new RegExp
set v=new RegExp
b.Pattern="android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile|o2|opera mini|palm( os)?|plucker|pocket|pre\/|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino"
v.Pattern="1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-"

b.IgnoreCase=true
v.IgnoreCase=true
b.Global=true
v.Global=true

if b.test(u) or v.test(Left(u,4)) then response.redirect("SITE-NAME-HERE") end if
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文