Leahcim
Leahcim

Reputation: 41999

PHP file path extra dot

in a tutorial I am doing, the code below is in index.php file. Does the second "." in the file indicate that index.php is not at the root level? what would the significance be of adding extra "." in that position?

require_once("../includes/database.php");

Upvotes: 1

Views: 1952

Answers (4)

smottt
smottt

Reputation: 3330

This is a relative path to the current directory.

  • "." indicates the current directory
  • ".." indicates one level up in the directory structure

So the answer is yes, that file is not in the root level.

Upvotes: 5

vbence
vbence

Reputation: 20333

Not necessarily. For security reasons it is recommended that your include files be placed outside the web-accessible directory (htdocs), so minimizing the possibility of someone calling the database.php directly with forged parameters.

So the directory structure should look somthing like:

user
| |
| + htdocs
|   |
|   + index.php
|
+ includes
  |
  + database.php

Upvotes: 4

Jan Zyka
Jan Zyka

Reputation: 17898

.. references to relative path one level up the current path.

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318578

.. means "one directory up"; ../.. would mean "two directories up".

Upvotes: 3

Related Questions