That has nothing to do with __DIR__. include/require use the file system to access files, hence it doesn’t matter if a directory is the public web directory or not. What matters are the file permissions of the executing user (for example the user for web access has usually much less permissions granted than a regular user)
My problem is that I am working on wamp on my PC at home.
When I moved the including file to a different directory or inside a new directory inside or outside the public directory. , the script didn’t work so I want to know what did I do wrong
These two words are very very vague. Typically, these two words are used “loosely”. I would recommend re-wording or elaborating on what “didn’t work” or “doesn’t work” mean.
Does it give you an error message?
Does it print a weird message that you know you didn’t write?
Does it give you a blank page?
Does it give you elephantiasis?
See how vague the two words “didn’t work” or “doesn’t work” can be? It can simply mean something entirely not even within the given parameters of IT/developing like the last bulleted question.
To phrase it another way, There can be syntax errors which should result in an error message as long as error reporting is enabled. And there can be logic errors which don’t throw error messages but are like “I expected A and B, but got A,B,C” or “I expected A and B, but got only A”.
For syntax errors it’s helpful to see the relevant code and the error message. IMHO, logic errors can be trickier to debug, but seeing the code involved is still important.