2

I'm trying to call a PHP class in my project called connectBDD_PDO.class.php located in /wamp/www/publicClass/connectBDD_PDO.class.php, but when I use the function

require ($_SERVER["HTTP_HOST"].'/publicClass/connectBDD_PDO.class.php');

My code stops and displays a blank page, no error messages even in debugging mode. Can you help me find where the problem come from ?

Natty
  • 497
  • 1
  • 11
  • 23

1 Answers1

3

$_SERVER["HTTP_HOST"] usually is the domain name, depending on how your vhost configured.

A invalid path is causing the error.

Just give the absolute path of the directory where publicClass/connectBDD_PDO.class.php is located. You may use a relative path, but then it must be seen relatively from the script is including it.

When seeing a blank page, probably a HTTP 500 error is invoked. You may place ini_set('display_errors', true); at first line to debug in browser, but does not guarantee to show it.

Example assuming

/var/www/www.foo.com/htdocs/index.php
/var/www/publicClass/connectBDD_PDO.class.php

Then you can include this like

// absolute path
require('/var/www/publicClass/connectBDD_PDO.class.php');

or

// relative path
require('../../publicClass/connectBDD_PDO.class.php');
Markus Zeller
  • 8,516
  • 2
  • 29
  • 35
  • Since the OP is using `require` it probably won't HTTP 500 though, it'll just stop and trigger a PHP error. – CD001 Jun 15 '17 at 08:23
  • Depends on configuration of the webserver, I would say. – Markus Zeller Jun 15 '17 at 08:25
  • 1
    Thanks, putting the absolute path did the trick ! I'll try out the `ini_set() `next time :) – Natty Jun 15 '17 at 08:28
  • You might be right - but either way it's the combination of `require` and `display_errors` being off, with an invalid filepath that's causing the problem - so your answer should sort it anyway ;) @MarkusZeller – CD001 Jun 15 '17 at 08:28
  • I've refined the answer a bit. Hopefully all people are now satisfied. – Markus Zeller Jun 15 '17 at 08:38