0

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?

  • don't use `/game` but `game` – Kenney Nov 27 '15 at 22:52
  • @Kenney doesnt work, not even with __DIR__, tried that – Vlade Marton Nov 27 '15 at 22:53
  • `include $_SERVER['DOCUMENT_ROOT'].'/game/components/currency/userdata_func.php';`You need to include from the root of the server. – Qirel Nov 27 '15 at 22:56
  • The errormessage says that `units.php` is in `...htdocs/views`, not in `../game`. Can you add the absolute paths of all the files to your question? Also, if `index.php` already is in `game`, you would want to include `__DIR__ . '/components/...'`. – Kenney Nov 27 '15 at 22:57
  • @Kenney sorry, my mistake, i tried many things and i imported the wrong code here... i fixed it already – Vlade Marton Nov 27 '15 at 23:02
  • @Qirel there was a third include as well, header.php. That seems to work now, language_declaration.php gives the same error and userdata_func.php seems to be loaded as well but throws bunch of errors like Use of undefined constant DB_HOST - assumed 'DB_HOST' – Vlade Marton Nov 27 '15 at 23:08
  • 1
    Basically, `$_SERVER['DOCUMENT_ROOT']."/"` gives the path up to where your index-file is located. You then need the path from there and to the appropriate files. As for the undefined constants, that's another issue, and as you read - some constants are undefined, see [Undefined Index and Variables](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index). – Qirel Nov 27 '15 at 23:18
  • http://php.net/manual/en/function.include.php says you don't want parenteses around the path. Quote: "I cannot emphasize enough knowing the active working directory. Find it by: echo getcwd(); Remember that if file A includes file B, and B includes file C; the include path in B should take into account that A, not B, is the active working directory." – Steve Nov 28 '15 at 00:52

1 Answers1

0

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');
?>
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37