从本地(100% 工作)转移到托管时,PHP 行为异常。有些代码可以工作,有些则不能
我一直在 MacBook Pro 上使用本地安装的 MAMP 用 PHP 构建一个网站。昨天,我终于成功完成了所有工作,因此我决定购买一些网络空间并使用与 MAMP(PHP 5.3、MySQL)上本地安装完全相同的设置来托管文件。
当我将文件移过来并测试该网站时,我遇到了一个非常奇怪的错误。大部分代码都可以工作,但是,有些代码被破坏了,但是以一种非常不寻常的方式。我会尽力解释。
注意:这张图片可能很好地显示了错误。我屏蔽了一些私人内容。
第一段代码是这样的:
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT * FROM message,thumbsup_items WHERE message.id = thumbsup_items.name AND message.date BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() ORDER BY votes_down DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$dest = "http://twitter-badges.s3.amazonaws.com/t_mini-b.png";
$dest2 = "images/fb-small.png";
$url="http://dfwm.ws";
while ($row = mysql_fetch_assoc($result))
{
?>
在本地安装上 100% 有效,但是在托管网站在以下位置中断:
$totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT * FROM message,thumbsup_items WHERE message.id = thumbsup_items.name AND message.date BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() ORDER BY votes_down DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$dest = "http://twitter-badges.s3.amazonaws.com/t_mini-b.png";
$dest2 = "images/fb-small.png";
$url="http://dfwm.ws";
while ($row = mysql_fetch_assoc($result))
{
?>
这意味着该错误必须与 <<操作员?。我不确定。
下一个错误如下:
<?
/****** build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
?>
<div id = "previous">
<?
echo " <a href='?currentpage=$prevpage'>«Previous</a> ";?>
</div>
<?
} // end if
// range of num links to show
$range = 2;
?>
<div id="pagination">
<?
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo "$x";
// if not current page...
} else {
// make it a link
echo " <a href='?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
?>
</div>
<?
// echo forward link for next page
?><div id ="next"><?
echo " <a href='?currentpage=$nextpage'>Next »</a> ";?>
中断于:
1) {
我得出的结论是,如果这是与操作员有关的错误,因为它两次都发生了,那么它肯定不会显示任何内容,而不是出现PHP 标签并仅将其显示为 HTML? (该图片在问题的开头显示了这一点)。
非常感谢一些帮助,因为我已经绞尽脑汁几个小时了。
谢谢
I've been building a website in PHP using a local install of MAMP on a MacBook Pro. Yesterday I finally managed to finish it with everything working so I decided to buy some webspace and host the files using exactly the same setup as the local install on MAMP (PHP 5.3, MySQL).
When I moved the files over and tested the site I get a really strange error. Most of the code is working, however, there are parts of the code that are broken, but in a very unusual way. I'll try my best to explain..
Note: This image probably shows off the error very well. I've blocked out some of the private content.
The first bit of code is this:
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT * FROM message,thumbsup_items WHERE message.id = thumbsup_items.name AND message.date BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() ORDER BY votes_down DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$dest = "http://twitter-badges.s3.amazonaws.com/t_mini-b.png";
$dest2 = "images/fb-small.png";
$url="http://dfwm.ws";
while ($row = mysql_fetch_assoc($result))
{
?>
Which is 100% working on the local install, however on the hosted website it cuts off at:
$totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT * FROM message,thumbsup_items WHERE message.id = thumbsup_items.name AND message.date BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() ORDER BY votes_down DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$dest = "http://twitter-badges.s3.amazonaws.com/t_mini-b.png";
$dest2 = "images/fb-small.png";
$url="http://dfwm.ws";
while ($row = mysql_fetch_assoc($result))
{
?>
Meaning that the error must be to do with the < operator?. I'm unsure.
The next error is below:
<?
/****** build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
?>
<div id = "previous">
<?
echo " <a href='?currentpage=$prevpage'>«Previous</a> ";?>
</div>
<?
} // end if
// range of num links to show
$range = 2;
?>
<div id="pagination">
<?
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo "$x";
// if not current page...
} else {
// make it a link
echo " <a href='?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
?>
</div>
<?
// echo forward link for next page
?><div id ="next"><?
echo " <a href='?currentpage=$nextpage'>Next »</a> ";?>
Which cuts off at:
1) {
I've come to the conclusion that if it was an error to do with the operators, as it has happened on both times, surely it would just not show anything, instead of coming out of the PHP tag and just displaying it as HTML? (the image shows this at the start of the question).
Would really appreciate some help as I've been racking my brain over it for hours.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是短开放标记,仅适用于 PHP 安装并设置为启用它们。我建议您使用完整的
。
<?
is the short open tag, which only works on PHP installs with the setting to enable them. I suggest you use the full<?php
.您正在使用短标签(
而不是完整的
开头声明),建议不要使用短标签,原因如下:与某些服务器不兼容。
将
的任何实例重写为
并确保将来使用
。
You're using short tags (
<?
instead of the full<?php
opening declaration) which are advised against for exactly this reason: incompatibility with some servers.Re-write any instances of
<?
to<?php
and make sure you use<?php
in the future.