关于 PHP 可能性的问题(用户、管理员/mod)

发布于 2024-10-05 23:38:05 字数 370 浏览 7 评论 0原文

首先,我对网络编程和一般编程有点陌生。 HTML/CSS + Javascript 是我在过去几年中所学到的。

现在,出于工作目的,我需要学习 PHP。

我最感兴趣的是用户注册+用户权限。

我的任务是创建一个 Web 应用程序,也就是说,一个更简单的博客版本。 我想知道是否可以从头开始构建这样的应用程序并添加具有不同权限的用户。如果是这样,最好的方法是什么? 我怀疑我是否会使用一些框架,因为我打算自己学习 PHP 编码。 如果您能给我指出一些有用的资源,我将非常感激:)

干杯

编辑: 我会尝试更具体。我的目标不是从头开始创建内容管理系统。我很想知道是否有一种方法可以构建一个类似博客的应用程序,其中包含用户注册和将应用于每个页面的不同权限。

First of all, I'm kinda new to web programming and programming in general. HTML/CSS + Javascript are as far as I've gone over the last few years.

Now, for the purpose of my work, I need to learn PHP.

What I'm most interested about is user registration + users' privileges.

My task is to create a web application that is, let's say, a simpler version of a blog.
I'd like to know is it possible to build such an application from scratch and add users with different privileges. And, if so, what is the best way to do it?
I doubt I'm gonna be using some framework as I intend to learn PHP coding on my own.
If you could point me to some useful resources I would be more than grateful :)

Cheers

EDIT:
I'll try to be more specific. My goal is not to create a content management system from scratch. I'm interested to know if there is a way to build a blog-like application with user registration and different privileges that are going to be applied on every page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音栖息无 2024-10-12 23:38:05

为了解决这个问题,您需要了解如何构建您的网站。大多数情况下,页眉和页脚应该位于不同的文件中,这些文件稍后包含在每个页面上。在标题中应该有一些用户验证代码。根据用户权限,将创建一些全局变量,该变量稍后将用作标志。

例如:假设您拥有从 5 到 1 的权限。5 是完全访问权限,1 是最受限制的访问权限。因此,稍后在代码中您应该为权限状态创建测试,这将根据数字更改页面的输出。

In order to solve that problem you need some idea about how you are going to construct your website. Most of the times header and footer should be in different files which are later included on every page. In header there should be some user validation code. Which depending on user privileges will create some global variable which will later serve as a flag.

For example: let's say you have privileges from 5 to 1. Five being full access and 1 being most restricted access. So later in the code you should create test for the privileges status which will change the output of the page depending on the number.

抠脚大汉 2024-10-12 23:38:05

好的。我这样做的方法(而且似乎效果很好)是拥有单独的类,在其中定义所有核心函数。例如,

//core.class.php 
class Core {
    public function someStuffForCore() {
    //Stuff
    }
}

//admin.class.php
class Admin {
    public function userManagement() {
    //User Management
    }
}

然后您将它们包含在您的 index.php 文件中,并创建每个类的新实例,然后将它们全局化以供以后使用,就像

require_once("/include/scripts/core.class.php");
require_once("/include/scripts/admin.class.php");
$core = new Core;
$admin = new Admin;
global $core, $admin;

timik 所说的那样,我会将您的布局保留在其他地方的另一个文件中。我喜欢将所有布局保存在一个数组中,例如

//layout.php
$layout = array (
    'header'=>'<html><head>..</head><body><div class="body">',
    'footer'=>'</div></body></html>'
    );

然后,如果需要,您可以存储帖子的格式,并使用 sprintf
这就是我的做法,你也可以采取不同的做法。

Okay. The way I do this (and it seems to work well) is to have individual classes in which you define all of the core functions. Ex,

//core.class.php 
class Core {
    public function someStuffForCore() {
    //Stuff
    }
}

//admin.class.php
class Admin {
    public function userManagement() {
    //User Management
    }
}

Then you would include them in your index.php file, and create new instances of each class, and then global them for use later, like

require_once("/include/scripts/core.class.php");
require_once("/include/scripts/admin.class.php");
$core = new Core;
$admin = new Admin;
global $core, $admin;

Like what timik said, I would keep your layout in another file somewhere else. I like to keep all of my layouts in an array like

//layout.php
$layout = array (
    'header'=>'<html><head>..</head><body><div class="body">',
    'footer'=>'</div></body></html>'
    );

Then, if you need to, you can store the format for your posts, and use sprintf
This is how I would do it, and you may do it differently.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文