问题描述
我要为只有一个网页的客户构建一个网站。页面只有一个可编辑内容的div;
I'm going to build a site for a client that consists of only one page. The page has only one div with editable content; the rest can be hard-coded in a template file.
客户端想要类似CMS的行为:登录网站并编辑单个文本(最好是内联)。我通常用Drupal构建更大的网站,但这将是对这样简单的过度杀戮。
The client wants CMS-like behavior: logging in on the site and editing that single piece of text (preferably inline). I usually build larger sites with Drupal, but that would be overkill for something simple like this.
有没有人知道这样的网站有一个好的(开源)解决方案?
Does anybody know of a good (open source) solution for a site like this?
推荐答案
好的,这里是我的CMS版本。您可以在zip存档中找到我的所有文件:。
Ok, here is my version of the CMS. You can find all my files here in a zip archive: 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>
这篇关于“CMS”对于一个页面的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!