Feralheart
Feralheart

Reputation: 1940

Difficulties with alternate routing

I am working on a PHP project for myself. My folder structure is like this:

index.php
head.php
config
    config.php (database connection)
src
    the other php files (ie. nav.php, stats.php)
helpers
    the "oncerunning scripts" (ie. login.php, logout.php)
css
    style.css

In the start of index.php and almost every php's in the src and helpers directoris I included 'head.php'. If I run the index.php, everything is OK, but If I login it causes WSOD, becouse login.php gets the head.php (../head.php), but head.php don't give it the path to the config file (it forwards that the config.php is in the config/ directory, but there aren't any config directory in the helpers directory)

How I can debug this?

Upvotes: 0

Views: 24

Answers (1)

Tim Mu
Tim Mu

Reputation: 26

  1. Try use Absolute Paths and not relative paths, this because relative paths are called based on the executed php script.
  2. the other option is to allow one script manage all processes; e.g. file : index.php

    <?php
    include_once('config/config.php');
    ...//various configurations
    if ($state == $login)
    {
        include_once('src/login.php');
    }
    else if ($state == $stats)
    {
        include_once('src/stats.php');
    }
    

then you will only need to configure relative paths according to one php script, in this case script index.php

Upvotes: 1

Related Questions