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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:04:08+00:00 2026-06-04T09:04:08+00:00

I’m trying to include a file but it doesn’t seem to be working –

  • 0

I’m trying to include a file but it doesn’t seem to be working – here’s the entire code:

if (file_exists('config/categories.php')) {
    include ('config/categories.php'); 
} 

foreach ($categories as $cat_sef => $cat_name) {
    echo '<a href="'.$full_domain.$cat_sef.'" alt="#">'.$cat_name.'</a><br />';
}

The contents of config/categories.php is simply an array:

$categories = array("category-1" => "Category 1", 
"category-2" => "Category 2", 
"category-3" => "Category 3")

I know the file exists because the following works:

if (file_exists('config/categories.php')) {
    echo "file exists";
}

However if I replace the array in categories.php with say:

echo "testing";

Nothing will display either. So as far as I can see, the file exists but it doesn’t seem to be including some how. If I rename the categories file to something else I will receive a ‘no such file’ error (file does not exist).

With the original code snippet, the error I get is:

Notice: Undefined variable: categories

But as you can see, it is defined in the categories.php file.

The ONLY way it works is to put the array in place of the if (file_exists) part of my code, which I don’t want to do because other parts rely on that categories.php file, so I don’t want to dupe an array in multiple files.

Does anyone have any idea what this could be? Let me know if you need any more info.

  • 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-04T09:04:10+00:00Added an answer on June 4, 2026 at 9:04 am

    You have two options here :

    • use include(dirname(__FILE__).'/config/categories.php') to make sure you are including this same file and not another ‘config/categories.php’

    • double check that categories.php includes opening php tags like this <?php. Seems obvious, but I have seen this more than once in code reviews.

    Hope this helps !

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.