Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4027840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:08:48+00:00 2026-05-20T11:08:48+00:00

I inherited sites where previous developer used the spaghetti code below to handle relative

  • 0

I inherited sites where previous developer used the spaghetti code below to handle relative paths for nav, image, and script items.

if(substr_count($_SERVER['REQUEST_URI'], "/") <= 1){
    define('NAV', '');
    define('IMG', 'i/');
    define('INC', 'inc/');
}else{
    $z = 0;
    while($z < $i) {
        $current_pos .= '../';
        $z++;
    }
    define('NAV', $current_pos);
    define('IMG', $current_pos.'i/');
    define('INC', $current_pos.'inc/');
}

Used in the markup it would look something like this:

<a href="<? echo NAV; ?>index.php"><img src="<? echo IMG; ?>spacer.gif" alt="home" /></a>

The site is riddled with these; making it hard to move. I need a better solution without having to wade through all the pages to make changes. Was using getcwd() but it’s not proving reliable. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:08:48+00:00Added an answer on May 20, 2026 at 11:08 am

    Often it’s convenient to use the __FILE__ constant to find the location of the current file and surrounding directories:

    define('APP_PATH', dirname(__FILE__) . "/");
    $img = APP_PATH . "img/";
    $js = APP_PATH . "js/";
    // etc
    
    // For includes...
    require_once(APP_PATH . "include/file.php");
    require_once(APP_PATH . "../upperleveldir/file2.php");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I inherited an application where display:none was used to control conditional display of input
I have inherited some legacy PHP code what was written back when it was
I have inherited a web site that has all of the paths set using
I have inherited a client site which crashes every 3 or 4 days. It
I've recently inherited a fairly large web site. The project is set up as
I inherited a Windows Forms app written in VB.Net. Certain parts of the app
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited a database built with the idea that composite keys are much more
I inherited a project that uses SQL Server 200x, wherein a column that stores

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.