-2

We're having a wierd issue, we're using an online ordering platform script that we bought few months ago. It was working very fine since all these previous months, until now ! The website's page doesnt load, checking Chrome and Firefox Inspectors, we're seeing an error saying : Uncaught SyntaxError: Unexpected token ILLEGAL on file list.php

that list.php is being called from index.php , throught this line :

<script type="text/javascript" src="panel/js/list.php"></script>

I think that the browser, sees/reads the file as a JavaScript, then it finds inside the file PHP code, and this is why it throughs up that nasty error and preventing the page from loading.

I just want to know how I can make that php to work, even it is inside the <script> </script>

PS: <?php include('panel/js/list.php'); ?> nor <?php require('panel/js/list.php'); ?> didn't work

PPS: I tried to put that line right before with no posetive result aswell

Here is the code inside list.php

<?php
function GetLangFile($lang)
{
    $lang_file = 'lang.'.$lang.'.php';

    return $_SERVER['DOCUMENT_ROOT'].'/languages/'.$lang_file;
}

// Get language from get or put default as en
$lang_file;
if(isset($_GET['l']) && $_GET['l'] != '')
    $lang_file = GetLangFile($_GET['l']);
else
    $lang_file = GetLangFile('en');

// Include the selected language file
include_once $lang_file;

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))ob_start("ob_gzhandler");else ob_start();
header("Content-type: text/javascript; charset: UTF-8");
include('md5.js');
include('front.js');
include('shopping.js');
include('paypal.js');
include('mercadopago.js');
include('adsmanager.js');
include('tags.js');
include('front-visuals.js');
include('browserdetect.js');
include('popup.js');
include('social.js');
include('forms.js');
include('uploader.js');
include('googlemap.js');
include('switch.js');
include('howbox.js');
include('tip.js');
include('jCarouselLite.js');
ob_end_flush();
?>
mirek213
  • 1
  • 1
  • 2
  • 1
    `PHP` is not a `JavaScript` `script`. You can't include it like that. – Script47 Aug 08 '15 at 01:33
  • You can include PHP like that, if you put the proper header in it, works great for dynamic css file. That said, likly the error is that you have the literal `ILLEGAL` word somewhere, without that contents of that file there is no way to know. – ArtisticPhoenix Aug 08 '15 at 01:39

1 Answers1

0

PHP is not a JavaScript script. You can't include it like that.

I think that the browser, sees/reads the file as a JavaScript

Well you can't blame the browser for that can you? You're specifying it as text/javascript,

<script type="text/javascript" src="panel/js/list.php"></script>

Also please tell us what is in list.php.

Script47
  • 14,230
  • 4
  • 45
  • 66
  • if only i could run my JavaScript on the server, i would rule the world!! – WhiteHat Aug 08 '15 at 01:39
  • 1
    Yup, http://stackoverflow.com/questions/1445424/include-css-with-php-file-extension That's css but same deal. – ArtisticPhoenix Aug 08 '15 at 01:41
  • It's ok, it's not common or necessarily a good practice to do something just because you can. Although It works great for controlling image access, because you can use a php file there too. `as an image src` Pretty neat. I've done this before on a site with art and some ... ah hmm mature content .. artistic wise. – ArtisticPhoenix Aug 08 '15 at 01:44
  • php runs on the server, no good on the client. unless you you're just pushing text to the page, such as css. let me know which browsers support "`php`" – WhiteHat Aug 08 '15 at 01:45
  • @WhiteHat - um the only thing that you can pass though any request on the internet is text, why do you think they invented `XML` or `JSON` ? PDF's just text, that Image, it's just text. That video your looking at just text, some text is just more structured then other text. Some text is 1's some is 0's, some UTF, some HEX. But it really is all just text. – ArtisticPhoenix Aug 08 '15 at 01:46
  • exactly, that's why there will be no "php being called" as the question asks – WhiteHat Aug 08 '15 at 01:50
  • @WhiteHat - oh it will execute the php script that way, I have no doubt about that. Think about it, how could there be a PHP syntax error if it didn't? It wont show in the body of the page, if the call is in the head, that's all. Give it a shot. – ArtisticPhoenix Aug 08 '15 at 01:51
  • and i suppose i can use `node.js` to run my `JavaScript` on your server – WhiteHat Aug 08 '15 at 01:53
  • That's an entirely different situation. Or are you saying Node.js is Apache? The Apache sever will execute a PHP file no matter how it's called, be it in a ` – ArtisticPhoenix Aug 08 '15 at 01:54
  • no. you cannot put php on your page and run it in my browser. the same i cannot run node.js on your server from my browser. – WhiteHat Aug 08 '15 at 02:01
  • Well as I said, that was coded that way on that script we purchased, I'm not the one who've put php file in `` And as I also did say before, the script was working fine, so yes, @ArtisiticPhoenix is right. – mirek213 Aug 08 '15 at 10:28
  • @mirek213 - you should post the code as an update ( append ) to the original question. – ArtisticPhoenix Aug 08 '15 at 17:32