doushadu0901 2016-11-19 21:02
浏览 13

我如何在<php>标签中调用它?

I understand that I might not be too specific in what I want, but I'll try to explain myself as good as I can.

I want to monetize my website, and I'm pretty new to web development. I want everyone except chosen people, to get ads displayed. I have setup mysql accounts etc. and I am trying to detect what rank a session is. What I do atm., is inside of php tags, I get the session, and do

if($_SESSION['category'] == "3"){

I am just wondering, how I would be able to add this code, inside of the brackets of above code. I've tried echo 'CODE'; but I couldn't get it to work. I'd really appreciate any help I can get.

Code I want run:

<script type="text/javascript">//<![CDATA[ 
(function() {
    var configuration = {
    "token": "NOT SURE I CAN SHARE THIS",
    "excludeDomains": [
        "NONE"
    ],
    "capping": {
        "limit": 5,
        "timeout": 24
    },
    "entryScript": {
        "type": "timeout",
        "timeout": 3000,
        "capping": {
            "limit": 5,
            "timeout": 24
        }
    },
    "exitScript": {
        "enabled": true
    },
    "popUnder": {
        "enabled": true
    }
};
    var script = document.createElement('script');
    script.async = true;
    script.src = '//cdn.shorte.st/link-converter.min.js';
    script.onload = script.onreadystatechange = function () {var rs = this.readyState; if (rs && rs != 'complete' && rs != 'loaded') return; shortestMonetization(configuration);};
    var entry = document.getElementsByTagName('script')[0];
    entry.parentNode.insertBefore(script, entry);
})();
//]]></script>    

What I've tried

if ($_SESSION['category' == "3" {
echo '<script type="text/javascript">//<![CDATA[ 
    (function() {
        var configuration = {
        "token": "NOT SURE I CAN SHARE THIS",
        "excludeDomains": [
            "NONE"
        ],
        "capping": {
            "limit": 5,
            "timeout": 24
        },
        "entryScript": {
            "type": "timeout",
            "timeout": 3000,
            "capping": {
                "limit": 5,
                "timeout": 24
            }
        },
        "exitScript": {
            "enabled": true
        },
        "popUnder": {
            "enabled": true
        }
    };
        var script = document.createElement('script');
        script.async = true;
        script.src = '//cdn.shorte.st/link-converter.min.js';
        script.onload = script.onreadystatechange = function () {var rs = this.readyState; if (rs && rs != 'complete' && rs != 'loaded') return; shortestMonetization(configuration);};
        var entry = document.getElementsByTagName('script')[0];
        entry.parentNode.insertBefore(script, entry);
    })();
    //]]></script>   ';
}
  • 写回答

2条回答 默认 最新

  • dtt83024 2016-11-19 21:29
    关注

    As I am concerned you want to show some add to people except some people wo don't want to see the adds. I suggest you to store your javascript code in .js file and than call it by php. Actually it is not a calling like require or include. You need to print just the text below, of course replacing the full path/file_name.js name of your file.

    <?php
       echo "<script type="text/javascript" src="path/file_name.js"></script>";
    ?>
    

    Example:

    <?php 
       if ($_SESSION['category'] == "3" {
            echo "<script type="text/javascript" src="path/file_name.js"></script>";
       }
    ?>
    

    Aim of doing this is to get more readale, understandable, managale code.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?