0

The require_once statement in my code is not working on MAMP. The same code was working perfectly on WAMP earlier before I ported the project over.

require_once('class\validate_group.php');

The error I get with this is:

Warning: require_once(class\validate_group.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/validate_login.php on line 37

The phpinfo.php is showing the include path as:

.:/Applications/MAMP/htdocs

"class" is a folder inside htdocs

Strangely when I reverse the slash it starts reading the validate_group.php file. Will the reversed slashes still work in AWS where I am finally going to host this?

1
  • Simple use DIRECTORY_SEPARATOR like this require_once('class'.DIRECTORY_SEPARATOR .'validate_group.php'); Commented Aug 3, 2017 at 4:28

2 Answers 2

1

To answer your question, backslash in PHP is normally used to escape characters.

So you've escaped the \validate_group.php file in your require_once call.

You can use a pre-defined constant such as:

DIRECTORY_SEPARATOR to avoid this in future.

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

Comments

1

Simple use DIRECTORY_SEPARATOR like below

require_once('class'.DIRECTORY_SEPARATOR .'validate_group.php');

Comments

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.