Always use absolute paths for includes

It's not safe to assume that the web server will always give you a sane
cwd.
This commit is contained in:
Chris Wright 2014-11-06 11:30:52 +00:00
parent b4ecd15790
commit e2ca3a39ef
2 changed files with 3 additions and 3 deletions

View file

@ -19,7 +19,7 @@ Inside the `public` folder you can now create your `index.php`. Remember that yo
```php ```php
<?php <?php
require '../src/Bootstrap.php'; require __DIR__ . '/../src/Bootstrap.php';
``` ```
The `Bootstrap.php` will be the file that wires your application together. We will get to it shortly. The `Bootstrap.php` will be the file that wires your application together. We will get to it shortly.

View file

@ -21,7 +21,7 @@ To install a new package, open up your `composer.json` and add the package to th
Now run `composer update` in your console and it will be installed. Now run `composer update` in your console and it will be installed.
But you can't use it yet. PHP won't know where to find the files for the classes. For this you will need an autoloader, ideally a [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloader. Composer already takes care of this for you, so you only have to add a `require '../vendor/autoload.php';` to your `Bootstrap.php`. But you can't use it yet. PHP won't know where to find the files for the classes. For this you will need an autoloader, ideally a [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloader. Composer already takes care of this for you, so you only have to add a `require __DIR__ . '/../vendor/autoload.php';` to your `Bootstrap.php`.
**Important:** Never show any errors in your production environment. A stack trace or even just a simple error message can help someone to gain access to your system. Always show a user friendly error page instead and send an email to yourself, write to a log or something similar. So only you can see the errors in the production environment. **Important:** Never show any errors in your production environment. A stack trace or even just a simple error message can help someone to gain access to your system. Always show a user friendly error page instead and send an email to yourself, write to a log or something similar. So only you can see the errors in the production environment.
@ -34,7 +34,7 @@ Then after the error handler registration, throw an `Exception` to test if every
namespace Example; namespace Example;
require '../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
error_reporting(E_ALL); error_reporting(E_ALL);