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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:30:09+00:00 2026-06-12T05:30:09+00:00

I am in a situation . My php folder structure is like UI user

  • 0

I am in a situation .

My php folder structure is like

UI
  user
    login.php
    logout.php
  jquery
    somejs

  css
    somecss
blah.php
blah.php

Now to import any css ,js or any php file i am using the file path like

localhost/UI/user/index.php  // example  

Now i am trying to define a global variable on any page like

 <?php
    $somevar = "localhost";
    GLOBAL $somevar;
    ?>   

So that i could import any css js like

<?php echo $somevar ;?>/UI/user/index.php  // example  

Problem : It is working on that page only where i declared the variable as GLOBAL

I want to use the variable on each page and don’t want to use include

Is there any other alternative to define a variable for files folder in php ?

  • 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-12T05:30:10+00:00Added an answer on June 12, 2026 at 5:30 am

    You do not declare variable with global. You just make it available within you method or function body even it was set (or using your terminology “declared”) outside of it. So there’s no way to have the variable unless it is declared. And there’s no way to do that without running the PHP code (simplification, but it does not matter here). And code is not coming from nowhere, hence the need of include or require of said code that sets variable.

    You may try to use php.ini‘s auto_include_file to have your variables auto-included, but still, the PHP code needs to be used for that.

    But you generally doing it wrong. move all global variables into class, set autoloader and access i.e. statically. The code will be much cleaner.

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

Sidebar

Related Questions

I have a situation with my php code. In a previous page the user
My situation: Folder structure is /resources/website/inc/ (/resources/ is where configs are stored, /website/ holds
I have a folder with a lot of .php files. I would like to
I have a situation like this. <php> <redirect the page > <exit> <javascript> <redirect
In PHP 0 is treated as boolean false. Hence, whenever I'm in a situation
I have the following situation. I have a PHP script that imports a CSV
Here's the lowdown of the situation. I am creating a role-playing game with PHP.
I am brand-spanking-new to the namespace concept in php. The situation: Multiple files in
Ok, this situation is a little weird but anyway. This PHP code generates several
I've uploaded a folder to a WordPress site. I'd like to access it e.g

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.