mar*_*end 18 content-management-system
我打算为只包含一个页面的客户端构建一个站点.该页面只有一个包含可编辑内容的div; 其余的可以在模板文件中进行硬编码.
客户端需要类似CMS的行为:登录网站并编辑单个文本(最好是内联).我通常使用Drupal构建更大的站点,但对于像这样简单的东西来说,这样做会有点过分.
有没有人知道这样一个网站的好(开源)解决方案?
Tat*_*nen 16
从头开始编写代码应该不是一件大事.您只需要admin.php,其中包含某种身份验证和一种表单.我定时自己并在7分钟内做到了这一点:
if(isset($_GET['login'])) {
// Check user credentials from db or hardcoded variables
if($_POST['username'] == 'user123' && $_POST['password'] == 'pass123') {
$_SESSION['logged'] = true;
} else {
$loginerror = 'Invalid credentials';
}
}
if(isset($_GET['logout'])) {
$_SESSION = array();
session_destroy();
}
Run Code Online (Sandbox Code Playgroud)
if(!isset($_SESSION['logged']) || $_SESSION['logged'] !== true): ?>
<form method="post" action="admin.php?login">
<?php if(isset($loginerror)) echo '<p>'.$loginerror.'</p>'; ?>
<input type="username" name="username" value="<?php isset($_POST['username']) echo $_POST['username']; ?>" />
<input type="password" name="password" />
<input type="submit" value="Login" />
</form>
<?php endif;
Run Code Online (Sandbox Code Playgroud)
if(isset($_SESSION['logged']) && $_SESSION['logged'] === true):
// Save contents
if(isset($_GET['save'])) {
file_put_contents('contents.txt', $_POST['contents']);
}
// Get contents from db or file
$contents = file_get_contents('contents.txt');
?>
<a href="admin.php?logout">Logout</a>
<form method="post" action="admin.php?save">
<textarea name="contents"><?php echo $contents; ?></textarea>
<input type="submit" value="Save" />
</form>
<?php endif;
Run Code Online (Sandbox Code Playgroud)
只需将这些段组合起来即可获得完整的代码.此代码段具有身份验证,注销功能,并将textarea的内容保存在文件中.或者,您可以更改此设置,以便用户和内容驻留在数据库中.
就个人而言,我需要更长的时间才能找到合适的轻量级CMS并将其配置为可行.
Mid*_*das 13
好的,这是我的CMS版本.您可以在zip存档中找到我的所有文件:http://chechi.be/midas/simple-cms.zip.
这是管理页面:
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CMS</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="main">
<h1>CMS</h1>
<?php
if (empty($_POST) && isset($_GET['action'])) {
$action = $_GET['action'];
switch ($action) {
case 'logout':
session_unset();
session_destroy();
break;
}
}
if (!isset($_SESSION['user'])) {
$user = '';
$pass = '';
if (isset($_POST['login'])) {
$user = strtolower(trim($_POST['user']));
$pass = $_POST['pass'];
$errors = array();
if ($user == '' || $user != 'admin') {
$errors['user'] = '';
}
if ($pass == '' || $pass != '123456') {
$errors['pass'] = '';
}
if (empty($errors)) {
$_SESSION['user'] = $user;
} else {
echo '<p class="error">Please fill in your correct ';
if (isset($errors['user']))
echo 'username';
if (count($errors) == 2)
echo ' and ';
if (isset($errors['pass']))
echo 'password';
echo '.</p>', "\n";
}
}
}
if (isset($_SESSION['user'])) {
$user = $_SESSION['user'];
?>
<div id="headertext">
<p class="l">You are logged in as <strong><?php echo $user?></strong>.</p>
<p class="r"><a href="?action=logout">Logout</a></p>
</div>
<?php
if (isset($_POST['edit'])) {
if (file_put_contents('homecontent.txt', $_POST['homecontent']) !== FALSE)
echo '<p class="succes">Your changes are saved.</p>', "\n";
}
$homecontent = file_get_contents('homecontent.txt');
?>
<form method="post" action="">
<p>Here you can edit your homepage text:</p>
<textarea name="homecontent" id="homecontent" rows="20" cols="55"><?php echo $homecontent?></textarea>
<p><button type="submit" name="edit">Save changes</button></p>
</form>
<?php } else {?>
<form method="post" action="" id="login">
<p>
<label for="user">Username:</label><input type="text" name="user" id="user" value="<?php echo $user?>" />
</p>
<p>
<label for="pass">Password:</label><input type="password" name="pass" id="pass" value="<?php echo $pass?>" />
</p>
<p>
<button type="submit" name="login">Login</button>
</p>
</form>
<?php }?>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)