0

at the moment a friend and I are working through a PHP tutorial. We are both new to php, but have some general experience in other languages.

We want to include "testseite.php" into our index.php The "testseite.php" is in the folder content/articles

The way the tutorial does it is to use

include("content/articles/".$_GET['include']);

but if we do that there is the following error:

Warning: include(/users/xxx/www/users/xxx/www/myCms/content/articles) [function.include]: failed to open stream: No such file or directory in /users/flateric/www/users/flateric/www/myCms/index.php on line 5

Warning: include() [function.include]: Failed opening 'content/articles/' for inclusion (include_path='.') in /users/xxx/www/users/xxx/www/myCms/index.php on line 5

We thought ourselves that the problem might be, that it doubles the username (i changed it to xxx) and "users" and "www" in the path. Thanks for your help

6
  • The error says, there is no directory 'content/articles/' Commented Oct 2, 2016 at 21:24
  • 1
    This is such a bad idea... You're trusting user input to access files Commented Oct 2, 2016 at 21:25
  • if we manually include it via include("content/articles/testseite.php"); it is correctly displayed Commented Oct 2, 2016 at 21:25
  • 1
    A tutorial showing usage of include() based on a GET variable should be abandoned as soon as possible. Commented Oct 2, 2016 at 22:02
  • 1
    Possible duplicate of PHP - Failed to open stream : No such file or directory Commented Oct 3, 2016 at 15:54

2 Answers 2

2

In PHP, include means to load the file into the arguments, like loading a library. So, this error means the file /users/flateric/www/users/flateric/www/myCms/index.php does not exist. You should evaluate if the $_GET value points to a physical file.

Sign up to request clarification or add additional context in comments.

Comments

1

It appears that $_GET['include'] is empty (or the include key is non-existent). This is causing the filename to include to be wrong. You're expecting to include a file named this:

content/articles/testseite.php

but actually getting an include for this:

content/articles/

Clearly, this is incorrect and causes the error. If the $_GET params don't include the include value (or it's blank), you should probably consider another approach, such as providing a default value or generating an error to the user.

1 Comment

There is a troubleshooting checklist for this frequent error message : stackoverflow.com/questions/36577020/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.