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 8512121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:11:45+00:00 2026-06-11T04:11:45+00:00

I’m trying to learn a better way to go back to the root directory.

  • 0

I’m trying to learn a better way to go back to the root directory. I heard that using $_SERVER isn’t the safest way. Im wondering if there is a better way.
so i could get something like this on the url example.com/exp/my.php

here’s what i got.

include ($_SERVER['DOCUMENT_ROOT'].'/cpages/cmain/func/init.php');
include($_SERVER['DOCUMENT_ROOT'].'/cpages/toppart.php');
include($_SERVER['DOCUMENT_ROOT'].'/cpages/boxes/image.php');
include($_SERVER['DOCUMENT_ROOT'].'/cpages/bottonpart.php');

I change it to

define ('DOCUMENT_ROOT', dirname(__FILE__));
include (DOCUMENT_ROOT.'/cpages/cmain/func/init.php');
include(DOCUMENT_ROOT.'/cpages/toppart.php');
include(DOCUMENT_ROOT.'/cpages/boxes/image.php');
include(DOCUMENT_ROOT.'/cpages/bottonpart.php');

but now it’s giving me a error

Warning: include(C:\xampp\htdocs\backbone\image/cpages/cmain/func/init.php)

and ($_SERVER['DOCUMENT_ROOT'] didn’t gave it me that error is their a way to fix it ?

  • 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-06-11T04:11:47+00:00Added an answer on June 11, 2026 at 4:11 am

    The problem is that you can’t rely on anthing in the $_SERVER array, as it’s possible to you may get all sorts of values.

    So you’ll need the following rules:

    1. If writing public code, put the path in a config file. Then if $_SERVER is not right on the user’s server, they can overwrite it. You can help pre-complete their config using DOCUMENT_ROOT if you like using some simple rules (see below).

    2. If writing code for your own use that’s only going to hop between a server or two, then assume DOCUMENT_ROOT is correct, and rwwrite it if you move servers and need to.


    How to provide the default DOCUMENT_ROOT if pre-compiling a config variable.

    1. On Apache, check CONTEXT_DOCUMENT_ROOT. DOCUMENT_ROOT is nearly always safe, but there are a couple of places where it can be wrong – and that’s the case in the link you provided. If apache is using mod_alias or mod user_dir. In these cases, you need to use CONTEXT_DOCUMENT_ROOT which is safer. But note that Apache has only been adding CONTEXT_DOCUMENT_ROOT for a month or so, so unless you have the very latest install, you need to fall back on DOCUMENT_ROOT.
    2. DOCUMENT_ROOT – see above
    3. Use PATH_TRANSLATED (less the length of PHP_SELF) to contruct a path to current working directory.
    4. Use SCRIPT_FILE_NAME (less the length of PHP_SELF) to contruct a path to current working directory.
    5. Use the global variable __DIR__ to current working directory

    Then, when you have those details, check for a file you know exists in that directory – and if it does, you’ve probably got the right path. If not, try the next one along.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.