简体   繁体   中英

PHP: script works on some machines only

Weirdest PHP issue I have gotten. There is some PHP code that runs on some machines only.

Client called to fix the problem. The name of the file is portada.html

I had seen the website before and it worked fine. I know PHP code is usually run on .php files but this one used to run just fine on this .html file. Maybe some apache conf or something their former web developer did.

So now it runs fine when you use some machines but on others it doesn't run. Anyone has an idea of why something like this would happen?

Here's the code that doesn't run fine.

<script language="" type="text/javascript">
var so = new SWFObject("gallery.swf?xmlPath=galleries/gallery__something_<?
  $sql_conf="select galeria_something from ct_conf";
  $res_conf=mysql_query($sql_conf);
  $row_conf=mysql_fetch_assoc($res_conf);
  echo $row_conf["galeria_something"];
?>.xml", "something", "320", "238", 7, "");
so.addParam("allowScriptAccess", "sameDomain")
so.addParam("quality", "high");
so.addParam("scale", "noscale");
so.write("renta");
</script>

the code gets executed on Google Chrome, not on Firefox

You say the file name is portada.html. If that's correct and it's not saved as a .php file, then you would also need to make sure that the server recognizes .html files as needing to be processed by the PHP interpreter. You can do this from an .htaccess file by adding:

AddType application/x-httpd-php .html

Can't say for certain but it may have to do with you using short tags which is typically disabled by default. Try using <?php instead of just <? .

Also your queries may be case sensitive on Linux servers but not on windows servers.

To make you code compatible across many machines:

  1. Don't use short tags <? , use full tags <?php
  2. Don't use deprecated functions such as mysql_query , use mysqli_query etc http://www.php.net/manual/en/book.mysqli.php
  3. Turn on full error reporting to check compatibility: ini_set('display_errors', 1); error_reporting(E_ALL); ini_set('display_errors', 1); error_reporting(E_ALL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM