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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:57:05+00:00 2026-05-27T16:57:05+00:00

I’m building a PHP CMS, but having trouble with variables. I want to be

  • 0

I’m building a PHP CMS, but having trouble with variables. I want to be able to have all the variables in an external file, vars.php, and just include that file in every file that requires the variables. The variables all have to do with URLs and folder paths.

The problem I’m running in to is that if I set the variables to full URLs (ex: $uploadDir = "http://www.example.com/uploads/";), the scripts don’t do what they should. Same thing if I use absolute paths (ex: $uploadDir = "/uploads/"; or $uploadDir = "/full/server/path/uploads/";).

If I use full URLs, it seems like it at least tries to work, but doesn’t. If I use the full server path or absolute path, I get some error about that path not being allowed. The files are all stored in /edit/ or /edit/(sub-folder-name)/, if that helps.

I’ll look around for some code examples where I would be using this, and update this post ASAP.

Thanks.

UPDATE:

Some of the variables from this code snippet aren’t included, just didn’t think I should post a huge PHP script.

Example of $pageDir:

// The below 2 lines are actually in vars.php, which is included in this file.
$pageDir = "http://www.example.com/edit/pages/";
$url = "http://www.example.com/";

if ($_POST["page"] && $execute == TRUE) {
    $live = $_GET["p"] . ".php";
    // The below line is how this used to be set up.
    // $handle = fopen("pages/$page", "w");
    // The below line is how the new version should be set up.
    $handle = fopen("$pageDir/$page", "w");
    fwrite($handle, $_POST["page"]);
    fclose($handle);
    // The below line is how this used to be set up.
    // echo("<p>Page successfully saved. <a href=\"../$live\" target=\"_blank\">Click here to view this page.</a></p>\n");    
    // The below line is how the new version should be set up.
    echo("<p>Page successfully saved. <a href=\"$url/$live\" target=\"_blank\">Click here to view this page.</a></p>\n");    
    $execute = FALSE;
}
  • 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-27T16:57:05+00:00Added an answer on May 27, 2026 at 4:57 pm

    Don’t use URLs for file-system functions. That will make them do a HTTP request, not load the files from the filesystem.

    Also if you use /absolute paths, then that will refer to the filesystem root, not to your webservers document root. PHP filesystem functions do not operate on virtual path names, but on the real system file structure.

    You can however use:

     $pageDir = "/edit/pages/";
     readfile("$_SERVER[DOCUMENT_ROOT]/$pageDir/$page");
    

    That’s probably what you want.

    Other caveats: despite the meme, there is nothing wrong with global vars. You should however not swamp the shared scope with dozens of them. Instead define an array like $dir["page"] for folders. Or define() constants.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is 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.