如果用宝塔实现dedecms织梦接口调用

2024年09月19日 建站教程

1、在宝塔配置文件中找到以下语句

access_log /www/******
error_log /www/******

替换成:

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
access_log /www/******
error_log /www/******

2、用php语句建一个接口

<?php
$cfg_NotPrintHead = false;
header("Content-Type: text/html; charset=utf-8");
include_once (dirname(__FILE__)."/include/common.inc.php");
error_reporting(E_ALL || ~E_NOTICE);
require_once(DEDEINC.'/json.class.php');
$reval = array();
$dsql->SetQuery("SELECT id,title FROM `de_kd_archives` where typeid='栏目id' and LIMIT 5");
$dsql->Execute('me');
while ($row = $dsql->GetArray('me')) {
//$row['title'] = gb2utf8($row['title']);
$reval[] = $row;
}
$json = new Services_JSON(SERVICES_JSON_SUPPRESS_ERRORS);
echo $json->encode($reval);
?>

本文链接:http://so.lmcjl.com/news/13415/

展开阅读全文