【问题标题】:Same PHP Code On Remote Website Not Working In Local Apache远程网站上的相同 PHP 代码在本地 Apache 中不起作用
【发布时间】:2012-02-09 05:50:30
【问题描述】:

我正在使用 PHP、PHPMyAdmin 和 MySQL 设置 Apache。我有 PHP: 5.3.0 阿帕奇:2.2.21(Win32) PHPMyAdmin:3.4.9 MySQL:5.5

我浏览了设置 PHP 的基本指南,但它似乎仍然无法正常工作。我已经打开了短标签,所以这是固定的,但我是 Apache 的新手,所以我可能错过了一些东西。我的代码在我拥有的 Web 主机上的远程服务器上运行良好,但在我的本地 Apache 上运行良好。我认为这与我的 header.php 有关,它从 index.php 文件链接到 header.php.html 文件。这是我认为问题所在的 header.php.html 文件。如果您没有答案,请说出一些要遵循的规则,以确保 Apache 可以读取我的文件。

我得到的错误是:致命错误:第 20 行 C:\server\www\myserver.dev\public_html\luvbid\themes\default\header.php.html 中调用未定义函数 MySQLError()

不过,如果我只是说“die”而不是“MySQLError”,那么我会得到纯文本格式的“$query =”select * from BPLA_users where”。

<?
$query = "select * from BPLA_users where     nick='".$_SESSION['BPLowbidAuction_LOGGED_IN_USERNAME']."'";
$result = @mysql_query($query);
$TPL_balance = "00.00";
if(!$result) {
MySQLError($query);
} else {
$USER = mysql_fetch_array($result);
$TPL_balance    = number_format($USER['balance'], 2, '.', '');
}
$is_pre_registration = (isset($_REQUEST['pre_registration']) &&     ($_REQUEST['pre_registration'] == "1")) ? "1" : "";
if ($HTTPS == '1' || $HTTPS == 'on') {
$SITEURL = $Https['httpsurl'];
$SETTINGS['siteurl'] = $Https['httpsurl'];
} else {
$SITEURL = $SETTINGS['siteurl'];
$SETTINGS['siteurl'] = $SETTINGS['siteurl'];
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta name="google-site-verification" content="OXR3zBD_6YDDtqAsOLw6wkb6zqVshFark-S7dMO2zNM" />
    `<? $mobile_browser = '0'; if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) { $mobile_browser++; } if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) { $mobile_browser++; } $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4)); $mobile_agents = array( 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac', 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno', 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-', 'newt','noki','oper','palm','pana','pant','phil','play','port','prox', 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar', 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp', 'wapr','webc','winw','winw','xda ','xda-'); if (in_array($mobile_ua,$mobile_agents)) { $mobile_browser++; } if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) { $mobile_browser++; } if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows') > 0) { $mobile_browser = 0; } if ($mobile_browser <= 0) { ?>`

<link href="http://www.luvbid.com/css/style.css" type="text/css" rel="stylesheet" />              <script src="http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js"></script>
<link type="text/css" rel="stylesheet"      href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-
ui.min.js"></script>
<script src="js/jquery.alerts.js"></script>
<script type="text/javascript">
$(function() {
    jQuery("#dialog-about-help").hide();
        $("#opener-about-help").click(function(event) {
            event.preventDefault();
            jQuery("#liveauctions").toggle();
            $("#dialog-about-help").slideToggle();
        });
    });
</script>
<script type="text/javascript">
$(function() {
        jQuery("#dialog-login").hide();
        $("#opener-login").click(function(event) {
            event.preventDefault();
            jQuery("#liveauctions").toggle();
            $("#dialog-login").slideToggle();
        });
    });
    </script>
    <script>
        $(function() {
            $(".mobileproductbg").remove();
        });

    </script>
    <? } else { ?>
    <link href="http://www.luvbid.com/css/mobilestyle.css" type="text/css" rel="stylesheet" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    <script>
        $('div').bind('pageinit', function() {
            $(this).find('a').bind('click', function(e) {
                e.preventDefault();
            });
        });

    </script>
    <script>
        $(function() {
            $(".productbg").remove();
        });

    </script>
    <? } ?> <title>Luv Bid</title>
    <? if($SETTINGS['descriptiontag'] != '') { print "
    <META name=\"description\" content=\"".stripslashes($SETTINGS['descriptiontag'])."\">"; } if($SETTINGS['keywordstag'] != '') { print " <META name=\"keywords\" content=\"".stripslashes($SETTINGS['keywordstag'])."\">"; } //print " <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> "; $main_page = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : "home"; $show = isset($_GET['show']) ? $_GET['show'] : ""; ?>
    <? if ($SETTINGS[currency]=="USD") $SETTINGS[currency]="$"; if ($SETTINGS[currency]=="EUR") $SETTINGS[currency]="&euro;"; ?>
    <? if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
</head>
<body>
    <div data-role="page" data-fullscreen="true">
        <div class="ui-bar-d" data-role="header">
            <img src="http://www.luvbid.com/themes/default/img/logo.png" alt="Luv Bid" class="logo" /><h1 class="logo-text">Luv Bid</h1>
            <a class="mobileheader" data-role="button" data-icon="home" data-iconpos="notext" href="index.php?">Auctions</a>
            <div data-role="navbar">
                <ul id="mobileheader">
                    <li>
                        <a href="#dialog-about-help" data-rel="dialog" id="opener-about-help">About/Help</a>
                    </li>
                    <? if($_SESSION["BPLowbidAuction_LOGGED_IN"]) { ?>
                    <li>
                        <a data-icon="gear" href="user_menu.php">Settings</a>
                    </li>
                    <li>
                        <a href="logout.php">Logout</a>
                    </li>
                    <? } else { ?>
                    <li>
                        <a href="#dialog-login" data-rel="dialog" id="opener-login">Login</a>
                    </li>
                    <? if ($TPL_errmsg != ""){ ?>
                    <li>
                        <?echo $TPL_errmsg?>
                    </li>
                    <? } ?>
                    <li>
                        <a href="register.php">Register</a>
                    </li>
                    <? } ?>
                </ul>
            </div>
        </div>
        <div data-role="content">
            <nav id="header">
                <ul>
                    <li>
                        <a href="index.php?">Auctions</a>
                    </li>
                    <li>
                        <a id="opener-about-help">About/Help</a>
                    </li>
                    <li>
                        <a href="affiliates">Become An Affiliate!</a>
                    </li>
                    <? if($_SESSION["BPLowbidAuction_LOGGED_IN"]) { ?>
                    <li>
                        <a href="user_menu.php">Settings</a>
                    </li>
                    <li>
                        <a href="logout.php">Logout</a>
                    </li>
                    <? } else { ?>
                    <li>
                        <a id="opener-login">Login</a>
                    </li>
                    <? if ($TPL_errmsg != ""){ ?>
                    <li>
                        <?echo $TPL_errmsg?>
                    </li>
                    <? } ?>
                    <li>
                        <a href="register.php">Register</a>
                    </li>
                    <? } ?>
                </ul>
            </nav>
            <div id="dialog-about-help" data-role="dialog" style="text-align:left;">
                <? echo $MSG_33_0036 ?>
            </div>
            <div align="center" data-role="dialog" id="dialog-login">
                <form name="user_login" action="<? echo $Https['httpsurl']?>user_login.php?" method="post">
                    <label for="username"><? print $MSG_187; ?></label>
                    <input type="text" name="username" value="<? echo $TPL_nick; ?>" />
                    <br>
                    <label for="password">Password</label>
                    <input type="password" name="password" value="" />
                    <br>
                    <input type="checkbox" name="rememberme" value="1" />
                    <? echo $MSG_25_0085 ?>
                    <br>
                    <button type="submit" name="" value="<? echo $MSG_052?>"  class="button">
                        <? echo $MSG_052?>
                    </button>
                    <input type="hidden" name="action" value="login" />
                    <br>
                    <a href="forgotpasswd.php"><? print $MSG_215; ?></a>
                </form>
            </div>

【问题讨论】:

  • 什么不起作用?你遇到了什么错误?
  • 致命错误:在第 20 行调用 C:\server\www\myserver.dev\public_html\luvbid\themes\default\header.php.html 中未定义的函数 MySQLError()
  • MySQLError() 不是一个有效的函数。你可能想要:php.net/manual/en/function.mysql-error.php
  • MySQLError() 被链接到另一个文件上的 mysql_error 函数,但链接 PHP 文件将不起作用,因为 PHP 在此页面上根本无法正常工作。
  • PHP 怎么在这个页面上根本不起作用?您收到一个错误,这意味着 PHP 解析器工作正常。如果 PHP 没有解析这个页面,当你在浏览器中访问它时,你只会看到一堆代码。 PHP 正在运行,您对未定义函数 MySQLError() 的调用不起作用。

标签: php mysql html apache localhost


【解决方案1】:

好的,首先 PHP 工作正常,我们知道这一点是因为您收到了错误消息。其次,您将获得查询的纯文本,因为您可能会调用die($query),这将简单地退出进程并输出传递的任何内容,在这种情况下是您的 SQL 查询语句。您遇到此问题是因为 mysql_query 返回 false 并且您的第一个 if() 检查说如果此调用的结果为 false 则退出该过程。

PHP 正在运行,问题似乎是您的代码中没有有效的数据库连接,或者查询以其他方式失败。除了die 之外,使用mysql_error 会更有用,这实际上会为您提供有关问题所在的信息。此外,您应该从mysql_query 中删除错误抑制,我敢打赌,正在触发一个错误,它会告诉您出了什么问题。

【讨论】:

  • 好吧,我添加了这段代码。 &lt;?php $con = mysql_connect("localhost:3306","root","********"); if (!$con) { die('Could not connect: ' . mysql_error()); } ?&gt; 我用 mysql_error 替换了 MySQLError,现在我收到一条消息,上面写着“此页面不可用”和“错误 330 (net::ERR_CONTENT_DECODEDING_FAILED):未知错误。”
  • 您的响应标头显示内容是 gzip 编码的,但实际上并未在您发送之前进行编码。
  • 我删除了 gzip 代码,现在我的标题可以工作了。现在的问题是我的 index.php 内容部分不起作用。代码很长,我应该把代码贴在这里还是放在另一个问题中?
  • @CaryHartline 有点晚了,但是你在 Apache 的 php.ini 中启用了短标签吗?
猜你喜欢
  • 1970-01-01
  • 2012-08-08
  • 1970-01-01
  • 1970-01-01
  • 2015-10-31
  • 2013-05-22
  • 1970-01-01
  • 2018-11-28
  • 1970-01-01
相关资源
最近更新 更多