Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Enhancing a Simple PHP Application Cleaning URLs with Subfolders Introducing Constants

Alexander Stanuga
Alexander Stanuga
11,999 Points

Having issues getting ROOT_PATH to work, blank white page loading no CSS showing

I've been trying to resolve this same issue for a few hours now, I've read many of the posts from others in the same boat, tried the suggested solutions but I still appear to be getting a blank white page.

One post I found interesting and slightly helpful was this one ... (https://teamtreehouse.com/forum/need-help-getting-rootpath-to-work)

Michael De Marre suggested substituting define() within the config file to variables in order to create $BASE_URL and $ROOT_PATH, as shown in the code below...

    $BASE_URL = "/";
    $ROOT_PATH = $_SERVER["DOCUMENT_ROOT"] . "/";

Once done I then reverted all the relevant code on the other documents to the new viable names ($ROOT_PATH & $BASE_URL).

which was fine when I go to a page by typing a specific URL i.e.: (shirts4mike/shirts.php) & (shirts4mike/receipt). These page displayed fine... BUT links back to home page don't work, and whenever I try to load the homepage I still get a blank white page

I also tried changing the folder directories such as ...

define("BASE_URL" . "/");
    define("ROOT_PATH" . $_SERVER["DOCUMENT_ROOT"] . "/");
    define("BASE_URL" . "/shirts4mike/");
    define("ROOT_PATH" . $_SERVER["DOCUMENT_ROOT"] . "/shirts4mike/");
    define("BASE_URL" . "shirts4mike/");
    define("ROOT_PATH" . $_SERVER["DOCUMENT_ROOT"] . "shirts4mike/");

ABSOLUTELY ANY HELP WOULD BE GREATLY APPRECIATED

If it makes any difference, I'm on a Mac using MAMP Pro and redirected localhost to shirts4mike in the Hosts settings for this particular site (as I have a few others I'm working on atm).

Also, after reading this post (https://teamtreehouse.com/forum/introducing-constants-is-killing-my-soul) and with the first of the above three code snippets in play, I inserted Andrew Shock's code into the top of my receipt/index.php as suggested. The code output:

Notice: Undefined variable: ROOT_PATH in /Applications/MAMP/htdocs/shirts4mike/receipt/index.php on line 9

Warning: include(inc/header.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/shirts4mike/receipt/index.php on line 9

Warning: include(): Failed opening 'inc/header.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/shirts4mike/receipt/index.php on line 9 Thank You!

Thank you for your payment. Your transaction has been completed and a receipt for your purchase has been emailed to you. You may log into your account at www.paypal.com/au to view details of this transaction.

Need another shirt already? Visit the Shirts Listings page

Notice: Use of undefined constant ROOT_PATH - assumed 'ROOT_PATH' in /Applications/MAMP/htdocs/shirts4mike/receipt/index.php on line 25

Warning: include(ROOT_PATHinc/footer.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/shirts4mike/receipt/index.php on line 25

Warning: include(): Failed opening 'ROOT_PATHinc/footer.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/shirts4mike/receipt/index.php on line 25

Alexander Stanuga
Alexander Stanuga
11,999 Points

I am somewhat baffled about the first line of output:

Notice: Undefined variable: ROOT_PATH in /Applications/MAMP/htdocs/shirts4mike/receipt/index.php on line 9

as I have included a link to the config.php at the top of the document with:

require_once("../inc/config.php");

3 Answers

Bill Roberts
Bill Roberts
8,337 Points

You should have commas where you have periods. define("BASE_URL" , "/"); define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/");. Leave the one after $_SERVER["DOCUMENT_ROOT"], though, since you are concatenating that with /.

Alexander Stanuga
Alexander Stanuga
11,999 Points

Thanks so much for pointing that out for me Thomas! I made the change, but unfortunately my problem persists

Alexander Stanuga
Alexander Stanuga
11,999 Points

Ok, both shirts4mike/contact and shirts4mike/receipt are now displaying correctly.

For some reason I think I've narrowed it down to my homepage or index.php, shirts.php & shirt.php. I'll throw up my homepage index.php code.

<?php 

require_once("../inc/config.php"); ?>

<?php   
$pageTitle = "Unique T-shirts designed by a Frog";
include(ROOT_PATH . 'inc/header.php'); ?>

        <div class="section banner">

            <div class="wrapper">

                <img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
                <div class="button">
                    <a href="<?php echo BASE_URL; ?>shirts.php">
                        <h2>Hey, I&rsquo;m Mike!</h2>
                        <p>Check Out My Shirts</p>
                    </a>
                </div>
            </div>

        </div>

        <div class="section shirts latest">

            <div class="wrapper">

                <h2>Mike&rsquo;s Latest Shirts</h2>

                <?php include(ROOT_PATH . 'inc/products.php'); ?>
                <ul class="products">
                    <?php 

                        $total_products = count($products);
                        $position = 0;
                        $list_view_html = ""; 
                        foreach($products as $product_id => $product) {
                            $position = $position + 1;
                            if ($total_products - $position < 4) {
                                $list_view_html = get_list_view_html($product_id, $product) . $list_view_html;
                            }
                    } 
                    echo $list_view_html;
                    ?>                              
                </ul>

            </div>

        </div>

<?php include(ROOT_PATH . 'inc/footer.php'); ?>

Can anyone see if I'm doing anything wrong?

Julian Pavett
Julian Pavett
12,724 Points

Hi, I think that your root may be wrong here: require_once("../inc/config.php") You don't need to go up a folder to access you 'inc' directory. Should be: require_once("inc/config.php");