PHP脚本适用于localhost,但不适用于Web服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP脚本适用于localhost,但不适用于Web服务器相关的知识,希望对你有一定的参考价值。

我有这个脚本。

<?php
$self=$_SERVER['PHP_SELF'];
$ipresurse='resurse.fibula.ro';
$PartnerID="travelplaza";
$SelectedAirport="ANTALYA";

function checkXmlCache($xmlQuery)   {
    $fibulabasexml="http://resurse.fibula.ro/parteneri/";    $cachedir="http://ydashopimpex.com/tmp";    $ageInSeconds = 3600;
    $xmlQuery=str_replace(array("'",'"'),"",$xmlQuery); $xmlQuery2=$xmlQuery;
      $long=array("stars=","TURKEY","bestprice=","country=", "location=","hotelcode=","prices=yes","tara=","simple=yes","rand()","sort=","limit=","price ","hotelname"," desc","desc");
      $short=array("ST-","TR","B-","C-",        "L-",       "H-",        "PY-",   "T-", "-S-",      "-R-",  "S-",   "LT-",  "PP-","HN","-D","-D");
      $xmlQuery2=str_replace($long,$short,$xmlQuery2);
      $xmlQuery2=str_replace(array("xmlhotels.php","xmllocations.php"),array("XH-","XL-"),$xmlQuery2);
      $xmlQuery2=str_replace(array("&","?"),array(""),$xmlQuery2);
      $xmlQuery2.="_.XML";
      $xmlQuery2=strip_tags($xmlQuery2);

    if(!file_exists($cachedir.$xmlQuery2) || (filemtime($cachedir.$xmlQuery2) + $ageInSeconds < (time() )) ) {
      $contents = file_get_contents($fibulabasexml.str_replace(" ","%20",$xmlQuery));
      if(strlen($contents)>200 ) {  file_put_contents($cachedir.$xmlQuery2, $contents); }
    }
    return($cachedir.$xmlQuery2);
}

function moneda($moneda)    { $numemoneda=array("EURO","USD"); $simbol=array("&euro;","$"); return str_replace($numemoneda,$simbol,$moneda); } 

$feedbpl = checkXmlCache('xmlhotels.php?airport='.$SelectedAirport.'&myid=travelplaza'.$PartnerID.'&simple=yes&sort=nume asc'); 
$bpl = simplexml_load_file($feedbpl); $sh="0"; if(isset($_GET['code'])) {   $codes=explode(",",$_GET['code']); $sh=strip_tags($codes[2]); } 
?>
<div style="padding:2px; text-align:center">

<form name="fastsearch" method="get" action="<?php print $self; ?>">
<strong>CAUTARE RAPIDA HOTEL</strong> <select name="code" onchange="submit()" style="padding:2px 1px;"><option value="">---selecteaza hotel---</option><?php
            foreach ($bpl->hotel as $h)
            {
                ?><option <?php if($h['hotelcode']==$sh) { ?> selected="selected" <?php }?> value="<?php print $h['hotelname'].",".$h['location'].",".$h['hotelcode'];?>" title="<?php print $h['hotelname']." ".$h['stars'];?>"><?php print substr($h['hotelname'],0,30)." ".$h['stars'];?></option><?php
            }
?>
</select></form>


</div>
<?php
if(!isset($_GET['code']))
{
/* 
?>
<iframe style="padding:0px; margin:0px;" src='http://<?php print $ipresurse?>/WL/?myid=travelplaza<?php print $PartnerID; ?>&small=1' frameborder='0' width='100%' height='380' scrolling='auto'></iframe>
<?php
*/
}
if(isset($_GET['code']))
{
    $feedurl =checkXmlCache("xmlhotels.php?hotelcode=".$sh."&prices=yes&myid=travelplaza".$PartnerID);  $xml = simplexml_load_file($feedurl);
    ?>
    <h1><?php print $xml->hotel['hotelname']; ?> <?php print $xml->hotel['stars']; ?></h1>
   <div class="localizare"><?php print $xml->hotel['location']; ?> / <?php print $xml->hotel['country']; ?>
<div style="float:right;  background-color:#C9F; color:white; -moz-border-radius: 10px; border-radius: 10px; font-weight:bold; padding:5px; text-align:center"><a href="#rezervare123" style="padding:0px; margin:0px;">REZERVA ACUM<br />de la <?php print floatval($xml->hotel['bestprice']). " " .moneda($xml->hotel['currency']); ?></a></div>
   </div>
  <div class="gallery" style="display:inline-table; width:100%;">
<a  href="http://<?php print $ipresurse;?>/hotel_images/<?php print $xml->hotel['hotelcode']."___".$xml->hotel['defaultimage'].".jpg"; ?>" rel="gallery"><img style="float:left" src="http://resurse.fibula.ro/hotel_images/<?php print $xml->hotel['hotelcode']."___".$xml->hotel['defaultimage'].".jpg"; ?>" alt="" width="350" /></a>
<?php
                                foreach($xml->hotel->images->image as $img)
                                {
                                    ?>
<p style="float:left; margin:0px; padding:0px;"><a title="<?php print $xml->hotel['hotelname']; ?>" href="<?php print $img['url'];?>" rel="gallery">
<img style="float:left" src="<?php print str_replace(".jpg","___small.jpg",$img['url']);?>" alt="<?php print $xml->hotel['hotelname']; ?>" title="<?php print $xml->hotel['hotelname']; ?>" width="50" height="38"/></a>
</p>
                                    <?php
                                }
                                ?>

  </div>
     <?php print html_entity_decode($xml->hotel->description); ?>
    <div style="display:inline-table; width:100%;" id="rezervare123">
<h4 >Rezerva acum ! Oferta de la  <?php print floatval($xml->hotel['bestprice']). " " .moneda($xml->hotel['currency']); ?> </h4>

    <?php /* ?>
    <iframe style="padding:0px; margin:0px;" src='http://<?php print $ipresurse?>/WL/?myid=travelplaza<?php print $PartnerID; ?>&small=1&hotelcode=<?php print $xml->hotel['hotelcode']?>&hotel=<?php print $xml->hotel['hotelname']?>' frameborder='0' width='100%' height='380' scrolling='auto'></iframe>
    <?php */ ?>
    </div>
    <?php
    /*
    foreach($xml->hotel->prices->bestPrice as $prices)
    {
        $capete[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['night'])]=trim($prices['night']);
        $tarife[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['checkin'])][trim($prices['night'])]=number_format(floatval($prices['price']),0); 
    }
    */

    //new tarife
    $DefaultDiscount=0;
    foreach($xml->hotel->prices->bestPrice as $prices) { $customprice=floatval($prices['price'])-$DefaultDiscount; $capete[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['night'])]=trim($prices['night']); $tarife[trim($prices['depAirport']."-".$prices['arrAirport'])][trim($prices['checkin'])][trim($prices['night'])]=$customprice; }

    ?>
    <!-- prices start -->
    <?php
    foreach($capete as $key=>$value){ asort($value);
        ?>
        <div id="<?php print $key; ?>" style="padding:0px;" class="content">
        <p></p>
        <table width="100%"><thead>
        <tr><td width="10%">Data plecare</td>
        <?php foreach($value as $n) { ?><td><?php print $n;?></td><?php }?>
        </tr>

        <thead><tbody>
        <tr><td colspan="<?php print count($value)+1; ?>" align="center"><span style="color: #ff6600; font-weight:bold;">
        Tarife de persoana in camera standard. (* tarifele nu includ taxele de aeroport 95&euro;/pers)
        </span>
        </td></tr>
        <?php foreach($tarife[$key] as $checkin=>$nn)   { $chk=new DateTime($checkin); ?>
        <tr><td><?php print $chk->format('d.m.Y');?></td><?php 
foreach($value as $n) { ?><td align="right">&nbsp;<?php if(array_key_exists($n,$nn)) { print $nn[$n];} ?></td><?php } ?>
        </tr><?php 
        }
        ?>
        </tbody>
        </table>
        </div>
        <?php
    }
    ?>

<?php 


/*
foreach ($tarife as $rute=>$plecari)
    {   sort($capete[$rute]); $ut=0; $i=0;
        foreach($plecari as $plecare=>$tarif)
            {   $sd=explode("-",$plecare); if($ut!=$tarif[$capete[$rute][0]]) {$i++; }
                ${str_replace("-","_",$rute)}[$tarif[$capete[$rute][0]]."|".$i][]=$sd[2].".".$sd[1];
                $ut=$tarif[$capete[$rute][0]];
            }
    }

foreach($capete as $rute=>$value)
{ 
    ?>
    <h4>Oferta <?php print $rute. " ".$value[0]." nopti"; ?></h4>
    <table style="font-size:10px; border-collapse:collapse; " border="1" width="100%"><tr><?php
    foreach(${str_replace("-","_",$rute)} as $key=>$value)
        {  ?><td valign="bottom" align="center" style=" border-collapse:collapse; "><?php foreach($value as $dep) { print $dep."<br>";}?></td><?php }
    ?></tr><tr><?php
    foreach(${str_replace("-","_",$rute)} as $key=>$value)
        { $t=explode("|",$key); ?><td style=" background-color:lightblue; border-collapse:collapse; text-align:center;"><?php print $t[0];?></td><?php  }
    ?>
    </tr></table>
    <?php unset(${str_replace("-","_",$rute)});
}

*/


?>
<!-- end of prices -->
<?php 
}
else
{
    $feedurl =checkXmlCache('xmllocations.php?country=TURKEY&myid=travelplaza'.$PartnerID); $locations = simplexml_load_file($feedurl); 
    foreach($locations->country->location as $x) {  $airs[trim($x['airport'])][]=$x; }
    $xxx=0; $HotelsPerPage=15; $pagini=ceil($bpl['offers']/$HotelsPerPage); $pc=1; $maxi=$HotelsPerPage; $mini=1; 
    if(isset($_GET['pagina'])) {$pc=intval($_GET['pagina']); $maxi=$pc*$HotelsPerPage; $mini=$maxi-$HotelsPerPage+1; }

            foreach ($bpl->hotel as $hbpl)
            {
                $xxx++;
                if( ($xxx<=$maxi) and ($xxx>=$mini) )
                {
                $locatie=$hbpl['location'];
                        $imageurl="http://".$ipresurse."/hotel_images/".$hbpl['hotelcode']."___".$hbpl['defaultimage']."___medium.jpg"; 
                $l=0; $locationLink=$self."?";
                foreach($_GET as $k=>$v)
                { $l++; $si="&"; if($l==1) { $si=""; }
                    if( ($k!='location') and ($k!='nopti') and ($k!='hotel') and ($k!='hotelcode') and ($k!='ruta') ) { $locationLink.=$si.$k."=".$v; }
                }
                if($hbpl['airport']=='ANTALYA') {$linkruta="OTP_AYT";} else {$linkruta="OTP_BJV";}
                    $hotelLink=$self."?code=".urlencode($hbpl['hotelname']).",".$hbpl['location'].",".$hbpl['hotelcode'];
                ?>

                <div class="box">
                    <div class="thumb"><a href="<?php print $hotelLink; ?>"><img width="330" height="220" src="<?php print $imageurl; ?>" class="attachment-post-thumbnail wp-post-image" alt="<?php print  $hbpl['hotelname'] ?>" title="<?php print  $hbpl['hotelname'] ?>" /></a></div>
                    <a class="box-title" href="<?php print $hotelLink; ?>"><?php print  $hbpl['hotelname'] ?> &nbsp; <?php print $hbpl['stars']; ?> <?php print  number_format(floatval($hbpl['bestprice']))." ".moneda($hbpl['currency']); ?></a>
                    <a class="button" href="<?php print $hotelLink; ?>">Afla mai multe</a>
                </div>

            <?php
                }
            }
?>
    <div style=" display: inline-block; width:100%;">&nbsp;</div>
        <div style="border-top:solid 1px #ccc; display:inline-table; width:100%;" align="center">
                    <?php 
                    if($pc>1) { ?>
                    <span style=" float:left; padding:1px; margin:1px; background-color:#ccc;"><a style="text-decoration:none" href="<?php print $self."?pagina=".($pc-1); ?>">&laquo; Inapoi</a></span><?php }
                    for($i=1; $i<=$pagini; $i++)
                    {
                        ?><span style=" float:left; padding:0px; margin:1px; border:solid 1px #ccc; <?php if($i==$pc) { ?> background-color:#ccc; <?php }?>" >
                        <a style="text-decoration:none; padding:0px 2px; margin:0px;  line-height:10px;" href="<?php if($i==$pc) { print "#"; } else { print $self."?pagina=".$i;} ?>"><?php print $i;?></a>
                        </span><?php
                    }
                    if($pc<$pagini) { ?><span style=" float:left; padding:1px; margin:1px; background-color:#ccc;"><a style="text-decoration:none" href="<?php print $self."?pagina=".($pc+1); ?>">Inainte &raquo; </a></span><?php }
                    ?> 
        </div>
<?php
}

?>

在我的localhost上它可以工作。

但是当我将它上传到服务器时,它只读取html。附图。什么可能是错的?也许服务器上的php函数可能会被禁用?我该怎么检查?我已经和我的虚拟主机说过了,他告诉我必须知道我需要哪个功能。

答案

您可以使用ini_seterror_reporting将PHP错误报告设置为ALL以及其他与错误相关的ini设置。即:

<?php 
  error_reporting(E_ALL);
  ini_set('display_errors', '1');

另外,正如评论中所提到的,创建一个包含phpinfo()命令的php文件,以查看天气是否在您的服务器上运行php。

testphp.php

<?php
  phpinfo();

如果您打开yourwebsitesdomain.com/testphp.php并且您没有看到有关php运行的信息,请联系您的webhoster并告诉他php不在服务器上运行。

以上是关于PHP脚本适用于localhost,但不适用于Web服务器的主要内容,如果未能解决你的问题,请参考以下文章

标头位置不适用于实时服务器,但适用于 localhost

Socket.io 适用于 localhost 但不适用于 Heroku 服务器

jQuery 适用于 jsFiddle 但不适用于 localhost

Web 服务 SOAP 请求适用于 SOAPUI,但不适用于 PHP

Elmah 适用于 localhost,但不适用于生产?

未找到 laravel 类(适用于 localhost 但不适用于 DO 服务器)