PHP include doesnt work on files other than index

2019-09-05 05:54发布

So here is my problem:

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');
  ?>

Here is the directory list:

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

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

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?

标签: php include
1条回答
▲ chillily
2楼-- · 2019-09-05 06:51

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');
?>
查看更多
登录 后发表回答