Discuz!官方免费开源建站系统

 找回密码
 立即注册
搜索

[已答复] supesite的首页如何插入一段PHP代码

[复制链接]
zhoucunjie 发表于 2009-10-25 23:43:15 | 显示全部楼层 |阅读模式
我把下列这段PHP代码插入首页index.htm.php里,结果首页就什么都不显示了,请问正确的位置在那啊。






  1. <?php
  2. // THE FOLLOWING BLOCK IS USED TO RETRIEVE AND DISPLAY LINK INFORMATION.
  3. // PLACE THIS ENTIRE BLOCK IN THE AREA YOU WANT THE DATA TO BE DISPLAYED.

  4. // MODIFY THE VARIABLES BELOW:
  5. // The following variable defines whether links are opened in a new window
  6. // (1 = Yes, 0 = No)
  7. $OpenInNewWindow = "1";

  8. // # DO NOT MODIFY ANYTHING ELSE BELOW THIS LINE!
  9. // ----------------------------------------------
  10. $BLKey = "J1BI-O7K0-0DI8";

  11. if(strlen($_SERVER['SCRIPT_URI'])){
  12.     $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_URI'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
  13. }

  14. if(!strlen($_SERVER['REQUEST_URI'])){
  15.     $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].((strlen($_SERVER['QUERY_STRING']))?'?'.$_SERVER['QUERY_STRING']:'');
  16. }

  17. $QueryString  = "LinkUrl=".urlencode((($_SERVER['HTTPS']=='on')?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  18. $QueryString .= "&Key=" .urlencode($BLKey);
  19. $QueryString .= "&OpenInNewWindow=" .urlencode($OpenInNewWindow);


  20. if(intval(get_cfg_var('allow_url_fopen')) && function_exists('readfile')) {
  21.     @readfile("http://www.backlinks.com/engine.php?".$QueryString);
  22. }
  23. elseif(intval(get_cfg_var('allow_url_fopen')) && function_exists('file')) {
  24.     if($content = @file("http://www.backlinks.com/engine.php?".$QueryString))
  25.         print @join('', $content);
  26. }
  27. elseif(function_exists('curl_init')) {
  28.     $ch = curl_init ("http://www.backlinks.com/engine.php?".$QueryString);
  29.     curl_setopt ($ch, CURLOPT_HEADER, 0);
  30.     curl_exec ($ch);

  31.     if(curl_error($ch))
  32.         print "Error processing request";

  33.     curl_close ($ch);
  34. }
  35. else {
  36.     print "It appears that your web host has disabled all functions for handling remote pages and as a result the BackLinks software will not function on your web page. Please contact your web host for more information.";
  37. }
  38. ?>
复制代码
回复

使用道具 举报

@c201 发表于 2009-10-25 23:58:53 | 显示全部楼层
模板好像不能运行PHP代码的,你看模板开头就加了<?exit?>代码。
回复

使用道具 举报

 楼主| zhoucunjie 发表于 2009-10-26 02:21:45 | 显示全部楼层
点办啊。。。。。。。。。。。。
回复

使用道具 举报

lidq.jingwu 发表于 2009-10-26 09:18:24 | 显示全部楼层
这种代码在程序中已经有过判断了,没有必要再加。
这种php语句(有大括号),在模板中是加不进去的。
回复

使用道具 举报

 楼主| zhoucunjie 发表于 2009-10-26 12:56:22 | 显示全部楼层
那有什么办法呢。
回复

使用道具 举报

littlehz 发表于 2009-10-26 13:19:46 | 显示全部楼层
放index.php,而不是index.html.php
.html.php是SS的模版文件,可以直接写入SS的模版语句,但是不能直接写php
回复

使用道具 举报

lidq.jingwu 发表于 2009-10-26 14:37:00 | 显示全部楼层
5# zhoucunjie


    你上面给出的代码,在原系统中已经有过类似的判断,不用再加一遍了,有什么特殊的需求,找到那一段代码更改一下即可。
回复

使用道具 举报

 楼主| zhoucunjie 发表于 2009-10-26 23:37:45 | 显示全部楼层
据littlehz的建议
把PHP代码用记事本存为backlinks.php放到根目录下。
首页的index.php合适位置加上include(’backlinks.php’);

但我不知道那里才是合适的,我想放到首页下方的友情链接区附近或版权。
回复

使用道具 举报

黄群友 发表于 2009-10-27 00:00:29 | 显示全部楼层
谢谢分享。。
回复

使用道具 举报

littlehz 发表于 2009-10-27 10:06:48 | 显示全部楼层
你这个好像是判断URI请求什么的,如果请求的是/,然后就读取某个URL下的内容。
这样的话判断应该放在比较前的位置更好,最后不要忘了else之后才执行原来的index.php内容
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-9-15 13:07 , Processed in 0.094995 second(s), 14 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表