-2

So, I have been trying to use the XAMPP server as part of my school project, but I am getting an internal server error when I try to require a particular php file from another directory, here is what I mean:

I have this directory heirarchy:

directory_structure

and in my about.php file I am trying to require the about.view.php but I get an internal server error when I do that. Here is my about.php content:

about.php page

Why am I getting this error? and I tried every possible thing I can think of. Please, help me out.

Leuel Asfaw
  • 316
  • 1
  • 14
  • Please don't post [images of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question)! – brombeer Jun 06 '23 at 07:57
  • 1
    `about.php` is in a folder `controllers`. The `views` folder is on the same level as `controllers`, so you'd need to move to the parent directory (`../`) first – brombeer Jun 06 '23 at 07:59
  • @brombeer I have tried that, but I get this error `localhost is currently unable to handle this request. HTTP ERROR 500` – Leuel Asfaw Jun 06 '23 at 08:00
  • Check the PHP or Apache error log files then, to try and see exactly what caused the 500 – ADyson Jun 06 '23 at 08:21
  • @ADyson How Can I do that? Where do I find the log files? – Leuel Asfaw Jun 06 '23 at 08:23
  • That depends on your configuration. php.ini should have the PHP error log file configuration specified. Off the top of my head for Apache I forget how it's controlled, but you should be able to easily google it. – ADyson Jun 06 '23 at 08:24
  • 1
    [Where does PHP's error log reside in XAMPP?](https://stackoverflow.com/questions/3719549/where-does-phps-error-log-reside-in-xampp) – Simone Rossaini Jun 06 '23 at 08:33

1 Answers1

2

How to require file from another folder?

Your about.php file is located in the controllers folder. You want to include the views/about.view.php file according to your code. That means starting from about.php, you want to include the controller/views/about.view.php file. This is incorrect because your views folder is not inside the controllers folder. It is located outside of it.

The correct approach is to go up one level by using ../. This means starting from your interhub folder, the request should be interpreted as ../views/about.view.php. So, it starts from the controllers folder, then goes back one level to the interhub folder with ../, and then goes into the views folder with /views. After these steps, it will find the about.view.php file and your code will run correctly.

require_once "../views/about.view.php";

More information - file path

Extra - How to can view errors?

Okay, this file reference is fixed, check! If you receive further 500 error codes, it's definitely not because of this, but rather due to an error in your PHP code. You can output the errors to the screen or view them in the Apache error.log file.

// Show error message instead of "Error 500" blank page.
ini_set('display_errors', 1);
error_reporting(E_ALL);

Warning! Use it exclusively for home development purposes!
In live code, this poses a security vulnerability!

rozsazoltan
  • 2,831
  • 2
  • 7
  • 20