[英]Parse Error, Inserting PHP code in MyBB
我在mybb論壇的<head> </head>
插入此代碼:
<?php if(isset($_REQUEST['url'])): // <-- only include jQuery if url set ?>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
$(function() {
$( "#dialog-modal" ).dialog({
height: 140,
modal: true
});
});
</script>
<?php endif; ?>
看到頁面頂部的兩個錯誤說
Parse error: syntax error, unexpected $end in /home/content/87/9583687/html/a/global.php(524) : eval()'d code(2) : eval()'d code on line 1
Parse error: syntax error, unexpected T_ENDIF in /home/content/87/9583687/html/a/global.php(524) : eval()'d code(14) : eval()'d code on line 1
第一行代碼是否存在任何問題或語法問題? 我是說這個:
<?php if(isset($_REQUEST['url'])): // <-- only include jQuery if url set ?>
謝謝!
更新::
謝謝! 我試過但我認為我確定有些錯誤? :/
<?php if(isset($_REQUEST['url'])):
$str = <<<EOD
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
$(function() {
$( "#dialog-modal" ).dialog({
height: 140,
modal: true
});
});
</script>
EOD;
echo $str;
endif;
?>
“UPDATE”
這是名為headerinclude的實際文件:
<link rel="alternate" type="application/rss+xml" title="{$lang->latest_threads} (RSS 2.0)" href="{$mybb->settings['bburl']}/syndication.php" />
<link rel="alternate" type="application/atom+xml" title="{$lang->latest_threads} (Atom 1.0)" href="{$mybb->settings['bburl']}/syndication.php?type=atom1.0" />
<meta http-equiv="Content-Type" content="text/html; charset={$charset}" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/prototype.js?ver=1603"></script>
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/general.js?ver=1603"></script>
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/popup_menu.js?ver=1600"></script>
{$stylesheets}
<script type="text/javascript">
<!--
var cookieDomain = "{$mybb->settings['cookiedomain']}";
var cookiePath = "{$mybb->settings['cookiepath']}";
var cookiePrefix = "{$mybb->settings['cookieprefix']}";
var deleteevent_confirm = "{$lang->deleteevent_confirm}";
var removeattach_confirm = "{$lang->removeattach_confirm}";
var loading_text = '{$lang->ajax_loading}';
var saving_changes = '{$lang->saving_changes}';
var use_xmlhttprequest = "{$mybb->settings['use_xmlhttprequest']}";
var my_post_key = "{$mybb->post_code}";
var imagepath = "{$theme['imgdir']}";
// -->
</script>
{$newpmmsg}
我想在這個文件中添加以下PHP代碼:
<?php if(isset($_REQUEST['url'])): // <-- only include jQuery if url set ?>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
$(function() {
$( "#dialog-modal" ).dialog({
height: 140,
modal: true
});
});
</script>
<?php endif; ?>
這個headerinclude文件以這種方式包含在文件Global.php中:
// Set up some of the default templates
eval("\$headerinclude = \"".$templates->get("headerinclude")."\";");
eval("\$gobutton = \"".$templates->get("gobutton")."\";");
eval("\$htmldoctype = \"".$templates->get("htmldoctype", 1, 0)."\";");
eval("\$header = \"".$templates->get("header")."\";");
我想你需要這個插件: 模板/復雜模板中的PHP
因為MyBB不允許在模板中使用<?php ... ?>
。 但是如果你使用那個插件,你可以但它有一些限制(你可以在我提供的鏈接中看到)
這個插件是我見過的最強大的MyBB插件。 例如,如果我不希望訪客在forumdisplay.php中看到新主題,我只需要將模板更改為:
<if $mybb->user['uid'] != 0 then>
<a href="newthread.php?fid={$fid}>New Thread</a>
</if>
與MyBB玩得開心!
顯然,phpBB會將<?php ?>
塊中的所有內容放入eval
。 在你的情況下,這意味着它拋出
if(isset($_REQUEST['url'])):
在eval
。 這是一個未完成的if
構造。 要修復它,將整個PHP代碼放在一個 <?php ?>
塊中。 使用字符串處理或HERE文檔來執行HTML。
示例HEREDOC:
<?php
if(isset($_REQUEST['url'])):
$str = <<<EOD
... put your HTML here ...
EOD;
echo $str;
endif;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.