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

  • Home
  • SEARCH
  • 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 7691057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:32:18+00:00 2026-05-31T20:32:18+00:00

I’m running XAMPP for Mac. When I first started working with PHP, I would

  • 0

I’m running XAMPP for Mac.

When I first started working with PHP, I would define my directory with a variable:

 $root = "http://localhost/~aaron/SiteFolder/"; // Dev
 $root = "http://www.sitename.com/";            // Live

This will work, but it’s a huge annoyance having to comment one out, depending on if I’m editing the dev site or the live site.

I’m slowly transitioning over to OOP habits and want to maximize efficiency if at all possible. So I’m attempting to define ROOT with the current directory as shown here:

define("ROOT", dirname( __FILE__ ) . DIRECTORY_SEPARATOR);

This outputs:

/Users/aaron/Sites/SiteFolder/

This is not entirely useful to me when I’m working on the dev site, because I want to be able to use ROOT as a prefix for my images, files, etc.

This obviously won’t work:

<img src="/Users/aaron/Sites/SiteFolder/images/charizard.png">

What do I need to do to fix this problem to properly define my directory?

  • 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-31T20:32:19+00:00Added an answer on May 31, 2026 at 8:32 pm

    Based on your comments in my other answer, this is what you could do:

    You could create a simple installation page and ask the user for the url where they plan to host your web app.

    Then you can set this variable in a database or something.

    A lot of web apps do this: WordPress, Joomla come to mind.

    EDIT:

    You could also try to build the url using the php $_SERVER variable. You can get the host, port, to build the url.

    Unfortunately this could be a problem if someone decides to say host your web app in something other than the root of the domain of subdomain.

    Something like ‘http://domain/yourwebapphere/’

    You wouldn’t be able to detect that without the user specifying it. If you used a single endpoint and used an htaccess for redirecting urls, you’d still need to specify a base url in the htacess for it to redirect properly.

    EDIT2:

    Ok, if you really want to create the url dynamically, here’s some psuedo code on how to do it.

    $protocol = parse_server_protocol($_SERVER['server_protocol']);
    $port = $_SERVER['port']
    $host = $_SERVER['server_name'];
    //For use case where the app is not hosted at root of domain ("http://domain.com/test") for example
    $urlroot = parse_root($_SERVER["REQUEST_URI"]);
    
    $siteurl = buildRootUrl($protocol, $port, $host, $urlRoot);
    
    //Now save that root url in the database.
    

    If you are using htacess to create clean urls, your app would need to know how to write the baseurl in the instance where it is not hosted at the root of the domain.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
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
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.