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

Need help getting ROOT_PATH to work.

I've been trying for a few hours now to figure out my mistake but seem to be no closer, so hopefully one of you guys could help. I have my site located in a subfolder of htdocs called "shirts4mike".

This is the code from my config file:

<?php

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

And this is my include:

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

Any help would be a lifesaver right now, thanks!

2 Answers

Don't use define(). Change it to $BASE_URL and $ROOT_PATH =

Passing _$SERVER into define is most likely causing your error. The $value property of define() takes only integers, floats, strings, and booleans.

Thanks so much man, just relieved a major headache. Just out of curiousity though, Randy appears to use a constant instead of a variable in the video, any reason why it might work for him?

Randy is above the law. He does what he pleases.

On a serious note, it might have something to do with the concatenation? Maybe it would have worked if you had surrounded the $value expression with another set of parentheses.

Alexander Stanuga
Alexander Stanuga
11,999 Points

I've been having a lot of difficulty try ing to resolve this issue, and it appears by the comments/questions at the bottom of the page that I'm not alone.

Just so I understand, regarding the config.php file, what you're suggesting is, instead of...

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

Which is how Randy showed us to do, we need to replace it with...

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

is that correct?

If thats the case, my text editor (Coda 2) keeps informing me that:

Parse error: parse error in - on line 3 Errors parsing -

Alexander Stanuga
Alexander Stanuga
11,999 Points

My bad, I neglected the $ in order to create the variables. I'll fix that, and I assume that I need to change all the other BASE_URL & ROOT_PATH's on the other documents into variables too?

Alexander Stanuga
Alexander Stanuga
11,999 Points

Hmm still not doing it for me. I'll look elsewhere

Alexander Stanuga
Alexander Stanuga
11,999 Points

At the moment I can't even view my page, every time I try opening the site in my browser I'm met with a blank white page.