PHP包括对索引以外的文件不起作用 [英] PHP include doesnt work on files other than index
问题描述
所以这是我的问题:
我在xampp的htdocs的根目录中有一个index.php。其目的是登录用户。登录后,他被重定向到game / index.php,其中我有两个包含:
I have an index.php in root directory in xampp's htdocs. The purpose of that is to login an user. After he loggs in, he is redirected to the game/index.php, where i have two includes:
<?php include('/game/components/language_declaration.php');
include('/game/components/currency/userdata_func.php');
?>
这是目录列表:
index.php (which redirects to index below)
---/game/index.php (includes work)
---/game/units.php (the same includes dont work)
---/game/components/language_declaration.php
---/game/components/currency/userdata_func.php
此索引中有一个指向units.php的链接。在units.php中有相同的包含,除了它们不工作的事实。这是我得到的错误:
There is a link in this index which points to units.php. And there are the same includes in units.php, except the fact that they dont work. This is the error that i get:
Warning: include(/game/components/language_declaration.php): failed to open stream: No such file or directory in E:\xampp\htdocs\game\units.php on line 7
Warning: include(): Failed opening '/game/components/language_declaration.php' for inclusion (include_path='.;\xampp\php\PEAR') in E:\xampp\htdocs\game\units.php on line 7
Warning: include(/game/components/currency/userdata_func.php): failed to open stream: No such file or directory in E:\xampp\htdocs\game\units.php on line 8
Warning: include(): Failed opening '/game/components/currency/userdata_func.php' for inclusion (include_path='.;\xampp\php\PEAR') in E:\xampp\htdocs\game\units.php on line 8
我已阅读了大约20篇有关此问题的帖子每一个人都建议改变路径,我试图添加点,斜杠等,甚至定义根目录。没有用。你可以帮我吗?
I have read about 20 posts about this problem, every single one advised to change the path, I have tried to add dots, slashes and so one, even defining the root directory. None worked. Could you help me please?
推荐答案
你的包含语句应该是这样的:
Your include statements should be like this:
--- / game / index.php
<?php
include('components/language_declaration.php');
include('components/currency/userdata_func.php');
?>
--- / game / units.php
<?php
include('components/language_declaration.php');
include('components/currency/userdata_func.php');
?>
这篇关于PHP包括对索引以外的文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!