PHP中的服务器端渲染脚本标签

erhoui1w  于 11个月前  发布在  PHP
关注(0)|答案(1)|浏览(111)

我想运行一个小部件,是在我的个人服务器上的脚本标签的形式,这是Ubuntu,并显示在另一个网站上。如何使用PHP做到这一点?* 考虑到我想在我的服务器上接收脚本信息(服务器端渲染),并且只在Wordpress网站上显示它。脚本:

<script type="text/javascript">
    DukascopyApplet = { 
        "type": "chart", 
        "params": { 
            "showUI": true, 
            "showTabs": true, 
            "showParameterToolbar": true, 
            "showOfferSide": true, 
            "allowInstrumentChange": true, 
            "allowPeriodChange": true, 
            "allowOfferSideChange": true, 
            "showAdditionalToolbar": true, 
            "showDetachButton": true, 
            "presentationType": "candle", 
            "axisX": true, 
            "axisY": true, 
            "legend": true, 
            "timeline": true, 
            "showDateSeparators": true, 
            "showZoom": true, "showScrollButtons": true, 
            "showAutoShiftButton": true, 
            "crosshair": true, 
            "borders": false, 
            "theme": "Pastelle", 
            "uiColor": "#000", 
            "availableInstruments": "l:", 
            "instrument": "EUR/USD", 
            "period": "7", 
            "offerSide": "BID", 
            "timezone": 0, 
            "live": true, 
            "panLock": false, 
            "width": "100%", 
            "height": "600", 
            "adv": "popup" 
        } 
    };
</script>
<script type="text/javascript" src="https://freeserv-static.dukascopy.com/2.0/core.js"></script>
mkshixfv

mkshixfv1#

你可以使用.htaccess规则。
假设您已经在php文件中编写了代码,可通过(https://example.com/my-code-in-phphttps://example.com/myphpcode.php)url访问
在添加下面的.htaccess规则后,您可以访问/呈现脚本(https://example.com/my-code-in-jshttps://example.com/myjscode.js)url
RewriteRule ^my-code-in-js$ my-code-in-php [NC,L,QSA]

RewriteRule ^myjscode.js $myphpcode. php [NC,L,QSA]
您的php文件可以访问您的php/服务器端变量,使JS对象,看起来像

<script type="text/javascript">
DukascopyApplet = { 
    "type": "chart", 
    "params": { 
        "showUI": <?php echo !empty($x) ? 'true' : 'false';?>, 
        "showTabs": <?php echo !empty($y) ? 'true' : 'false';?>, 
        "showParameterToolbar": <?php echo !empty($z) ? 'true' : 'false';?>, 
        }
    }
</script>

相关问题