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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:53:46+00:00 2026-05-15T23:53:46+00:00

I realized I used a particular function over and over again in my PHP

  • 0

I realized I used a particular function over and over again in my PHP files, so I took the function out of all of them and put it in a seperate PHP file and included it where I need it.

Now when I make updates to the function, all the files that use it get updated. Great.

Now there is just one problem, the function itself uses relative URLs, and when you include the PHP the files are relative to the calling PHP, not the included’s PHP directory. I know the quick and dirty answer is to use absolute links, but how can I get the included PHP to reference things to ITSELF and not to the PHP that called it.

Example:

index.php includes a file called create_table.php….. create_table.php echoes CSS and javascript to index.php. The CSS and javascript are in the same directory as create_table.php, but when using src=”javascript.js” it wants to find the javascript.js where index.php is located, not where create_table.php is located.

Edit: how the structure works

/includes/create_table.php
/includes/style.css
/includes/javascript.js
/test/dir/1/2/3/index.php

So when I attempt to use src=”javascript.js” instead of looking for /includes/javascript.js it tries to find /test/dir/1/2/3/javascript.js

  • 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-15T23:53:47+00:00Added an answer on May 15, 2026 at 11:53 pm

    Use of absolute links is not “quick and dirty” but absolute necessary thing.
    And your problem has very little in common with PHP. It is HTML problem. It is not PHP calling your CSS file, but browser, after reading the link from HTML code.

    The only purpose of absolute path is to solve your problem – to find a particular file from any location.
    Of course it should be only path, not URI. All HTML links can be (and should be) shortened to path parts.

    instead of looking for /includes/javascript.js

    Bingo!
    Therefore, just tell it to look for this very address, an absolute one – /includes/javascript.js

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

Sidebar

Related Questions

i realized when i used urlencode or rawurlencode in PHP encoding the simple character
I just realized my mistake! I used the table jokecategory twice... learning PHP is
Upon coding, I realized I had made a mistake. I used git checkout 7e57dbf5a7245...
I realized that I can have problems with single quotes in php arrays: <?php
I used reflection many times before on public methods, but I never realized that
I'm new to PHP (used to Python) and I've been instructed to create something
I used PSPad for my WordPress template and just now realized the DOCTYPE was
I just realized that SQL server '=' comparator when used for text comparison is
The following function is meant to be used as a decorator that stores the
I want to use a algorithm to reduce memory used to save the particular

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.