Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

baseURL - php include code from seperate document

Featured Replies

I am wanting to make my life easier when using php include tags to include a php script or html from another source. My problem is, on a localhost mamp.. all is great and it works. Upload it to a server and I get errors.
Can someone help me understand what I need to do to get this to work on my hosting server?

 

<?php include ($_SERVER['DOCUMENT_ROOT'] . '/assets/navbar.php'); ?>
 

 

gives me the error of:
Warning: include() [function.include]: Failed opening '/home/'domain'/public_html/assets/subbar.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/'domain'/public_html/families_relief/index.php on line 34
The actual folder root the website is it is:
domain.com/families_relief
Mainly because it is a tester. I am looking for some sort of way to work it so that the include will always grab the right code and knows where to look. I was looking at something like a 'baseURL'. But anyone offer me advice, I will happily take it!
Thanks

One way is to have a config file (config.inc.php) that is included by all scripts that will define all your helper functions and site constants. In that file define your base url and base uri constants

define ('BASE_URI', '/home/example/'); //remote path to root folder
define ('BASE_URL', 'http://www.example.com/'); //live url
//define ('BASE_URI', '/Applications/MAMP/htdocs/example/'); //local path to root folder
//define ('BASE_URL', 'localhost/example/');//local url

Then your include can be something like

include(BASE_URI . 'assets/subbar.php');

Be sure to comment / uncomment out the 2 lines depending on whether you're working locally or remotely

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.