用户编辑的主题

发布于 2024-11-27 01:49:26 字数 754 浏览 5 评论 0 原文

我制作了一个小脚本,允许用户在我的网站中构建他们的页面或联系表单,

但一些朋友告诉我他们想要添加一些 JS 脚本!

所以我考虑允许用户编辑 header.php 文件,

文件内容是 - 示例

<head>
<title>Mysite | user_name</title>
</head>

现在我有想法,

我将从真实文件( header.php )中获取副本

并允许用户编辑它

可编辑版本将是

<title>{Mysite} | {user_name}</title>

,然后, ,我将使用( str_replace 函数)将 {mysite} 替换为我的网站标题变量

我的问题是!

如果用户发布了 php 代码

示例,

<head>
<title>{Mysite} | {user_name}</title>
<? include /// or echo 'error' or what ever ! ?>
//and some things others
</head>

那么php 代码可以工作吗?或者将被忽略并仅用作 html ?

如果有安全且好的另一种方法请告诉我!

谢谢

i have made an small script to allow users to build they page or contact form in my site

but some friends told me they want add some JS scripts !

so i thinking about allow users to edit header.php file

the file content is - Example

<head>
<title>Mysite | user_name</title>
</head>

Now i have idea

i will take a copy from the real file ( header.php )

and allow user to edit it

the editable version will be

<title>{Mysite} | {user_name}</title>

and then , i will use ( str_replace function ) to replace {mysite} by my site title varibal

MY Question is !

if the user posted a php code

example

<head>
<title>{Mysite} | {user_name}</title>
<? include /// or echo 'error' or what ever ! ?>
//and some things others
</head>

the php code will work ? or will be ignored and used as html only ?

if there is a secure and good another way please tell me !

thank you

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

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

发布评论

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

评论(2

小草泠泠 2024-12-04 01:49:26

如果您的用户可以修改的 header.php 文件包含在以下位置(使用 requireinclude)你的 PHP 代码,然后,它包含的 PHP 代码将被执行。

在你的情况下,我宁愿:

  • 使用像 header.tpl 这样的文件名,以表明该文件不包含 PHP 代码,但确实是某种模板。
  • 我不会使用 inclure/require 来获取该模板文件的内容,而是使用简单的 file_get_contents()

If the header.php file, which your users can modify, is included (using require or include) from your PHP code, then, the PHP code it contains will be executed.

In your case, I would rather :

  • Use a file name like header.tpl, to indicate that this file doesn't contain PHP code, but is indeed some kind of template.
  • And I would not use inclure/require to get the content of that template file, but a simple file_get_contents().
执笔绘流年 2024-12-04 01:49:26

如果出于某种原因您仍然想使用 .php 而不是对模板来说危险性较小的东西,那么您无论如何都应该清理用户输入,这样他们就不会利用它。

也许您可以从 strip_tags() 函数开始,并在那里使用 allowable_tags 参数

If for some reason you still want to use .php and not something less dangerous for templates, then you should sanitize user input anyway so they don't exploit it.

Perhaps you can start with strip_tags() function and using allowable_tags argument there

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