1

I want to run a widget that is in the form of script tag on my personal server, which is Ubuntu, and show it on another site. How to do this with PHP? *Consider that I want to receive script information on my server (server side render) and only display it on a Wordpress site. the script:

<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>
Progman
  • 16,827
  • 6
  • 33
  • 48
Brad1
  • 11
  • 1
  • What does the javascript code do and can you do it with PHP directly instead? Do you have a web browser available on the server which you can use/start/control to run your javascript code? – Progman Jun 24 '23 at 20:16
  • It's a financial chart and no i haven't. – Brad1 Jun 24 '23 at 20:31

1 Answers1

0

You can do it using .htaccess rule.

suppose you have written your code in php file accessible at (https://example.com/my-code-in-php or https://example.com/myphpcode.php) url

after adding below .htaccess rule, you can access/render the script at (https://example.com/my-code-in-js or https://example.com/myjscode.js) url

RewriteRule ^my-code-in-js$ my-code-in-php [NC,L,QSA]

OR

RewriteRule ^myjscode.js$ myphpcode.php [NC,L,QSA]

Your php file can access your php/server side variables, to make JS object and would look like

<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>