首页 技术 正文
技术 2022年11月14日
0 收藏 831 点赞 3,666 浏览 2467 个字

应热情粉丝的殷切期待,我决定从百忙之中抽出时间来完成这篇博文。(开玩笑啦)

我也是近期才接触到这种引用js的办法。例如,有这样一段js代码

<script src='http://ww.***.com/m.php?u=http://m.mumayi.com&d=http://down.***.com/a/101&i=http://m.***.com' language='JavaScript' charset='utf8'></script>

下面是这段js引用的m.php的内容:

header('Content-Type:text/html;charset=utf-8');$url = injectCheck(strip_tags(($_GET['u'])));//JS需要跳到的页面,例如:http://m.mumayi.com$download = injectCheck(strip_tags(($_GET['d'])));//推广版电子市场下载地址,例如:http://down.mumayi.com/a/101$iurl = injectCheck(strip_tags(($_GET['i'])));//JS需要跳到的页面,例如:http://m.mumayi.comif($url){    //$url = "window.open('".$url."')";    $url = 'window.location.href="'.$url.'" rel="external nofollow" ';}else{    $url = 'window.location.href="http://m.mumayi.com/?yidongtuiguang" rel="external nofollow" ';}if($iurl){    $iurl = 'window.location.href="'.$iurl.'" rel="external nofollow" ';}else{    $iurl = 'window.location.href="http://m.mumayi.com/?yidongtuiguang_ios" rel="external nofollow" ';}echo 'if((/AppleWebKit.*mobile/i.test(window.navigator.userAgent.toLowerCase())) || (/android/i.test(navigator.userAgent.toLowerCase())) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(window.navigator.userAgent.toLowerCase()))){   if(window.location.href.indexOf("?mobile")<0){            //iphone手机与ipad            if(/iphone/i.test(navigator.userAgent.toLowerCase())){';                    echo $iurl;            echo '}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){';                    echo $iurl;            echo '}else if(/android/i.test(navigator.userAgent.toLowerCase())){';                    //如果提供了下载地址,则会直接下载                    if($download){                        echo 'var download="'.$download.'";                      alert("系统检测到你还没有安装木蚂蚁安卓市场,点击确定下载木蚂蚁安卓市场,十万款免费破解版应用和游戏高速下载,并且还可以获取金蛋,赚话费兑换礼品哦~ ");window.open(self.download,\'_top\');';                    }                    echo $url;            echo '}else {';                    echo $url;            echo '}';    echo '}';echo '}';function injectCheck($data,$ignore_magic_quotes=false){    if(is_string($data))    {        $data=trim(htmlspecialchars($data));//防止被挂马,跨站攻击        if(($ignore_magic_quotes==true)||(!get_magic_quotes_gpc()))        {            $data = addslashes($data);//防止sql注入        }        return  $data;    }    else if(is_array($data))//如果是数组采用递归过滤    {        foreach($data as $key=>$value)        {            $data[$key]= injectCheck($value);        }        return $data;    }    else    {        return $data;    }}

认真看的朋友可能已经发现,虽然<script>标签中引用的地址指向m.php,但是这个php文件的输出,实际上是一段js代码,所以能起到引用js代码的作用。

但是为什么不直接使用JS,而要用PHP来输出呢?这个例子里是为了方便获取参数。

至于获取参数,如果传递的url参数本身还带参数的话,可以将参数urlencode,然后再传递就像这样:

<script src=’http://ww.mumayi.com/w.php?u=http://m.mumayi.com?seo&i=http%3A%2F%2Fm.hao123.com%2F%3Funion%3D1%26from%3D1013239a%26tn%3Dops1013239a%26qq-pf-to%3Dpcqq.discussion’ language=’JavaScript’ charset=’utf8′></script>

这样参数i后面的一大段带参数的url就可以被作为一个整体啦。

其实JS自身也可以获取参数,可能稍微麻烦一点。总之,这种JS可以跟服务器有更好的交互。在实际工作中也是用得上的。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290