Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法在网站非根目录下运行 #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controller/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
//清除cookie
setcookie("key", $key, -(time()+7 * 24 * 60 * 60),"/");
//跳转到首页
header('location:/');
header('location:'.dirname($_SERVER['PHP_SELF']));
exit;
}

Expand Down Expand Up @@ -104,7 +104,7 @@ function check_auth($user,$password){
$cookie = $_COOKIE['key'];
//如果cookie的值和计算的key不一致,则没有权限
if( $cookie != $key ){
exit("<h3>认证失败,请<a href = 'index.php?c=login'>重新登录</a>!</h3>");
exit("<h3>认证失败,请<a href = './index.php?c=login'>重新登录</a>!</h3>");
}
}

Expand Down
2 changes: 1 addition & 1 deletion controller/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ function base64($url){

// 载入前台首页模板
require('templates/'.TEMPLATE.'/index.php');
?>
?>
4 changes: 3 additions & 1 deletion controller/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

//如果已经登录,直接跳转
if( $cookie == $key ){
header('location:index.php?c=admin');
$phpSelf = dirname($_SERVER['PHP_SELF']);
$phpSelf = ($phpSelf == "/" || $phpSelf == "\\") ? "" : $phpSelf;
header('location:'.$phpSelf.'/index.php?c=admin');
exit;
}

Expand Down
14 changes: 7 additions & 7 deletions templates/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
<div class="layui-header">
<div class="layui-logo"><a href="/index.php?c=admin" style="color:#009688;"><h2>OneNav后台管理</h1></a></div>
<div class="layui-logo"><a href="./index.php?c=admin" style="color:#009688;"><h2>OneNav后台管理</h1></a></div>
<!-- 头部区域(可配合layui已有的水平导航) -->
<ul class="layui-nav layui-layout-left">
<li class="layui-nav-item"><a href="/"><i class="layui-icon layui-icon-home"></i> 前台首页</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=category_list"><i class="layui-icon layui-icon-list"></i> 分类列表</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=add_category"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加分类</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=link_list"><i class="layui-icon layui-icon-link"></i> 我的链接</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=add_link"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加链接</a></li>
<li class="layui-nav-item"><a href="./"><i class="layui-icon layui-icon-home"></i> 前台首页</a></li>
<li class="layui-nav-item"><a href="./index.php?c=admin&page=category_list"><i class="layui-icon layui-icon-list"></i> 分类列表</a></li>
<li class="layui-nav-item"><a href="./index.php?c=admin&page=add_category"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加分类</a></li>
<li class="layui-nav-item"><a href="./index.php?c=admin&page=link_list"><i class="layui-icon layui-icon-link"></i> 我的链接</a></li>
<li class="layui-nav-item"><a href="./index.php?c=admin&page=add_link"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加链接</a></li>

</ul>
<ul class="layui-nav layui-layout-right">
Expand All @@ -27,7 +27,7 @@
<?php echo USER; ?>
</a>
<dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=logout">退出</a></dd>
<dd><a href="./index.php?c=admin&page=logout">退出</a></dd>
</dl>
</li>
</ul>
Expand Down
8 changes: 4 additions & 4 deletions templates/admin/left.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;">分类管理</a>
<dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=category_list">分类列表</a></dd>
<dd><a href="/index.php?c=admin&page=add_category">添加分类</a></dd>
<dd><a href="./index.php?c=admin&page=category_list">分类列表</a></dd>
<dd><a href="./index.php?c=admin&page=add_category">添加分类</a></dd>
</dl>
</li>

Expand All @@ -15,8 +15,8 @@
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;">链接管理</a>
<dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=link_list">我的链接</a></dd>
<dd><a href="/index.php?c=admin&page=add_link">添加链接</a></dd>
<dd><a href="./index.php?c=admin&page=link_list">我的链接</a></dd>
<dd><a href="./index.php?c=admin&page=add_link">添加链接</a></dd>
</dl>
</li>

Expand Down
32 changes: 16 additions & 16 deletions templates/admin/static/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ layui.use(['element','table','layer','form'], function(){
table.render({
elem: '#category_list'
,height: 500
,url: 'index.php?c=api&method=category_list' //数据接口
,url: './index.php?c=api&method=category_list' //数据接口
,page: true //开启分页
,cols: [[ //表头
{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
Expand Down Expand Up @@ -48,7 +48,7 @@ layui.use(['element','table','layer','form'], function(){
//console.log(obj)
if(obj.event === 'del'){
layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){
$.post('/index.php?c=api&method=del_category',{'id':obj.data.id},function(data,status){
$.post('./index.php?c=api&method=del_category',{'id':obj.data.id},function(data,status){

if(data.code == 0){
obj.del();
Expand All @@ -60,14 +60,14 @@ layui.use(['element','table','layer','form'], function(){
layer.close(index);
});
} else if(obj.event === 'edit'){
window.location.href = '/index.php?c=admin&page=edit_category&id=' + obj.data.id;
window.location.href = './index.php?c=admin&page=edit_category&id=' + obj.data.id;
}
});
//渲染链接列表
table.render({
elem: '#link_list'
,height: 520
,url: 'index.php?c=api&method=link_list' //数据接口
,url: './index.php?c=api&method=link_list' //数据接口
,page: true //开启分页
,toolbar: '#linktool'
,cols: [[ //表头
Expand Down Expand Up @@ -123,7 +123,7 @@ layui.use(['element','table','layer','form'], function(){
layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){
for (let i = 0; i < data.length; i++) {

$.post('/index.php?c=api&method=del_link',{'id':data[i].id},function(data,status){
$.post('./index.php?c=api&method=del_link',{'id':data[i].id},function(data,status){
if(data.code == 0){
console.log(obj);
obj.del();
Expand Down Expand Up @@ -160,7 +160,7 @@ layui.use(['element','table','layer','form'], function(){
//console.log(obj)
if(obj.event === 'del'){
layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){
$.post('/index.php?c=api&method=del_link',{'id':obj.data.id},function(data,status){
$.post('./index.php?c=api&method=del_link',{'id':obj.data.id},function(data,status){
if(data.code == 0){
obj.del();
}
Expand All @@ -171,17 +171,17 @@ layui.use(['element','table','layer','form'], function(){
layer.close(index);
});
} else if(obj.event === 'edit'){
window.location.href = '/index.php?c=admin&page=edit_link&id=' + obj.data.id;
window.location.href = './index.php?c=admin&page=edit_link&id=' + obj.data.id;
}
});

//登录
//添加链接
form.on('submit(login)', function(data){
$.post('/index.php?c=login&check=login',data.field,function(data,status){
$.post('./index.php?c=login&check=login',data.field,function(data,status){
//如果添加成功
if(data.code == 0) {
window.location.href = '/index.php?c=admin';
window.location.href = './index.php?c=admin';
}
else{
layer.msg(data.err_msg, {icon: 5});
Expand All @@ -193,7 +193,7 @@ layui.use(['element','table','layer','form'], function(){

//添加分类目录
form.on('submit(add_category)', function(data){
$.post('/index.php?c=api&method=add_category',data.field,function(data,status){
$.post('./index.php?c=api&method=add_category',data.field,function(data,status){
//如果添加成功
if(data.code == 0) {
layer.msg('已添加!', {icon: 1});
Expand All @@ -207,7 +207,7 @@ layui.use(['element','table','layer','form'], function(){
});
//修改分类目录
form.on('submit(edit_category)', function(data){
$.post('/index.php?c=api&method=edit_category',data.field,function(data,status){
$.post('./index.php?c=api&method=edit_category',data.field,function(data,status){
//如果添加成功
if(data.code == 0) {
layer.msg('已修改!', {icon: 1});
Expand All @@ -222,7 +222,7 @@ layui.use(['element','table','layer','form'], function(){

//添加链接
form.on('submit(add_link)', function(data){
$.post('/index.php?c=api&method=add_link',data.field,function(data,status){
$.post('./index.php?c=api&method=add_link',data.field,function(data,status){
//如果添加成功
if(data.code == 0) {
layer.msg('已添加!', {icon: 1});
Expand All @@ -236,7 +236,7 @@ layui.use(['element','table','layer','form'], function(){
});
//识别链接信息
form.on('submit(get_link_info)', function(data){
$.post('/index.php?c=api&method=get_link_info',data.field.url,function(data,status){
$.post('./index.php?c=api&method=get_link_info',data.field.url,function(data,status){
//如果添加成功
if(data.code == 0) {
console.log(data);
Expand All @@ -250,7 +250,7 @@ layui.use(['element','table','layer','form'], function(){
});
//更新链接
form.on('submit(edit_link)', function(data){
$.post('/index.php?c=api&method=edit_link',data.field,function(data,status){
$.post('./index.php?c=api&method=edit_link',data.field,function(data,status){
//如果添加成功
if(data.code == 0) {
layer.msg('已更新!', {icon: 1});
Expand All @@ -265,7 +265,7 @@ layui.use(['element','table','layer','form'], function(){
//识别链接信息
form.on('submit(get_link_info)', function(data){
//是用ajax异步加载
$.post('/index.php?c=api&method=get_link_info',data.field.url,function(data,status){
$.post('./index.php?c=api&method=get_link_info',data.field.url,function(data,status){
//如果添加成功
if(data.code == 0) {
console.log(data);
Expand All @@ -284,7 +284,7 @@ layui.use(['element','table','layer','form'], function(){
function get_link_info() {
var url = $("#url").val();
var index = layer.load(1);
$.post('/index.php?c=api&method=get_link_info',{url:url},function(data,status){
$.post('./index.php?c=api&method=get_link_info',{url:url},function(data,status){
//如果添加成功
if(data.code == 0) {
if(data.data.title != null) {
Expand Down
4 changes: 2 additions & 2 deletions templates/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
c0.9,2.2,0.3,3.9,0.2,4.3c1,1.1,1.7,2.6,1.7,4.4c0,6.3-3.8,7.6-7.4,8c0.6,0.5,1.1,1.5,1.1,3c0,2.2,0,3.9,0,4.5
c0,0.4,0.3,0.9,1.1,0.8c6.5-2.2,11.1-8.3,11.1-15.5C34.3,8.7,27,1.4,18,1.4z"></path>
</svg>
<a href="/index.php?c=login" title = "登录OneNav" target="_blank" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons">account_circle</i></a>
<a href="./index.php?c=login" title = "登录OneNav" target="_blank" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons">account_circle</i></a>
</a>
</div>
</header>
Expand Down Expand Up @@ -125,7 +125,7 @@
</div>
<?php } ?>
<!-- 角标END -->
<a href="/index.php?c=click&id=<?php echo $link['id']; ?>" target="_blank" title = "<?php echo $link['description']; ?>">
<a href="./index.php?c=click&id=<?php echo $link['id']; ?>" target="_blank" title = "<?php echo $link['description']; ?>">
<div class="mdui-card-primary" style = "padding-top:16px;">
<div class="mdui-card-primary-title link-title">
<img src="https://favicon.rss.ink/v1/<?php echo base64($link['url']); ?>" alt="HUAN" width="16" height="16">
Expand Down
8 changes: 4 additions & 4 deletions templates/default/static/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ function admin_menu() {
var link_id = $(this).attr('id');
link_id = link_id.replace('id_','');
var tempwindow=window.open('_blank');
tempwindow.location='index.php?c=click&id='+link_id;
tempwindow.location='./index.php?c=click&id='+link_id;
}},
"edit": {name: "编辑", icon: "edit",callback:function(key,opt){
var link_id = $(this).attr('id');
link_id = link_id.replace('id_','');
var tempwindow=window.open('_blank');
tempwindow.location='index.php?c=admin&page=edit_link&id='+link_id;
tempwindow.location='./index.php?c=admin&page=edit_link&id='+link_id;
}},
"delete": {name: "删除", icon: "delete",callback:function(){
var link_id = $(this).attr('id');
link_id = link_id.replace('id_','');
mdui.confirm('确认删除?',
function(){
$.post("index.php?c=api&method=del_link",{id:link_id},function(data,status){
$.post("./index.php?c=api&method=del_link",{id:link_id},function(data,status){
//如果删除成功,则移除元素
if(data.code == 0) {
$("#id_" + link_id).remove();
Expand Down Expand Up @@ -166,7 +166,7 @@ $.contextMenu({
var link_id = $(this).attr('id');
link_id = link_id.replace('id_','');
var tempwindow=window.open('_blank');
tempwindow.location='index.php?c=click&id='+link_id;
tempwindow.location='./index.php?c=click&id='+link_id;
}},
"sep1": "---------",
"qrcode": {name: "二维码", icon:"fa-qrcode",callback:function(data,status){
Expand Down