包含PHP文件的JS,Css(Include PHP file's JS, Css)

编程入门 行业动态 更新时间:2024-10-28 08:30:07
包含PHP文件的JS,Css(Include PHP file's JS, Css)

我正试图在另一个目录中包含一个PHP文件。

这是我的文件结构

settings\ manage.php website \ index.php main.js main.css

对于manage.php

echo 'Welcome to the manager! Here is your website:'; include('../website/index.php');

的index.php

<script src='main.js'></script> <link rel="stylesheet" type="text/css" href="main.css">

所以,当我加载manage.php时,我没有得到main.js或main.css。 我怎样才能使这个工作? 也许包括是不是正确的路要走? 我无法修改网站文件夹中的任何内容。

[我知道iFraming是一个可能的解决方案,但我希望能得到另一个答案]

I am trying to include a PHP file in another directory.

Here is my file structure

settings\ manage.php website \ index.php main.js main.css

For manage.php

echo 'Welcome to the manager! Here is your website:'; include('../website/index.php');

index.php

<script src='main.js'></script> <link rel="stylesheet" type="text/css" href="main.css">

So, when I load manage.php, I do not get main.js or main.css. How can I get this to work? Maybe include is not the right way to go? I cannot modify anything in the website folder.

[I know iFraming is a possible solution but I'm hoping to get another answer]

最满意答案

基于以下问题的评论:如果你想为你的用户包含一些函数/代码(而不是其他方式;你在代码中包括用户的东西),你应该查看auto_prepend_file指令。

基本上,您可以在您的php.ini文件中指定要在主文件之前预先安装(作为require )某个PHP文件。

编辑:由于你没有访问php.ini,但你可以使用.htaccess文件,你可以把它放在你的.htaccess :

php_value auto_prepend_file "/path/to/your/file.php"

Based on the comment below the question: If you want to include some functions / code for your users (instead of the other way around; you including user's stuff in your code), you should look into the auto_prepend_file directive.

Basically, you specify in your php.ini file that you want to prepend (as a require) a certain php file before the main file.

Edit: As you don't have access to php.ini but you can use a .htaccess file, you can put this in your .htaccess:

php_value auto_prepend_file "/path/to/your/file.php"

更多推荐

本文发布于:2023-08-03 02:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1383117.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   JS   PHP   file   Include

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!