# I need someone to explain to me the following beginner PHP Code

**URL:** <https://www.phphelp.com/t/i-need-someone-to-explain-to-me-the-following-beginner-php-code/32006>\
**Category:** Beginners - Learning PHP\
**Created:** [June 5, 2020, 6:55am UTC](https://www.phphelp.com/t/i-need-someone-to-explain-to-me-the-following-beginner-php-code/32006 "2020-06-05T06:55:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![janbaztaimoor](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/f19dbf/32.png) [@janbaztaimoor](https://www.phphelp.com/u/janbaztaimoor)\
**Post date:** [June 5, 2020, 6:55am UTC](https://www.phphelp.com/t/i-need-someone-to-explain-to-me-the-following-beginner-php-code/32006/1 "2020-06-05T06:55:26Z")

</div>

OS: Centos  
PHP: 7.3

I am following a course by Kevin Skoglund about PHP. These are a few lines from the code. I understand define() and dirname() function. I just don’t understand what is happening here.

```auto
 define("PRIVATE_PATH", dirname( __FILE__ ));
  define("PROJECT_PATH", dirname(PRIVATE_PATH));
  define("PUBLIC_PATH", PROJECT_PATH . '/public');
  define("SHARED_PATH", PRIVATE_PATH . '/shared');

```

here is another section of code.

```auto
$public_end = strpos($_SERVER['SCRIPT_NAME'], '/public') + 7;
  $doc_root = substr($_SERVER['SCRIPT_NAME'], 0, $public_end);
  define("WWW_ROOT", $doc_root);

```

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [June 5, 2020, 10:51am UTC](https://www.phphelp.com/t/i-need-someone-to-explain-to-me-the-following-beginner-php-code/32006/2 "2020-06-05T10:51:20Z")

</div>

It’s just making constants of the paths so you don’t have remember them when you need to use them. Especially helpful when working on a local server. It is also a good way to make your PHP a little more secure. I like Kevin Skoglund and have followed a couple of his tutorials.

The second section is just define the root path of you website/app.

I personally find this easier to do -\>

```
define("APP_ROOT", dirname(dirname( __FILE__ )));
define("PRIVATE_PATH", APP_ROOT . "/private");
define("PUBLIC_PATH", APP_ROOT . "/public");

```

and stick it in an initial file, BUT the tutorial you are doing there must be a reason to do it that way. Though without seeing the whole code it is kind of hard to tell, but I would guess that the WWW\_ROOT constant is easier to access in other sections of the PHP code, plus it might make the code a little more secure? Though someone else here might be able to tell right off the bat the real reason it is like that.

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [June 5, 2020, 6:05pm UTC](https://www.phphelp.com/t/i-need-someone-to-explain-to-me-the-following-beginner-php-code/32006/3 "2020-06-05T18:05:39Z")

</div>

Instead of dirname( **FILE** ) you can just use **` __DIR__ `**
