Problem with SITE_ROOT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
munkitkat
Forum Newbie
Posts: 6
Joined: Thu Mar 10, 2016 6:22 am

Problem with SITE_ROOT

Post by munkitkat »

I am teaching myself php (working through a textbook) and have hit a couple of problems. I've just spent about 4 hours trying to get the SITE_ROOT configured. I have selected public_html/exercises as the ROOT using

define("SITE_ROOT", "/public_html/exercises/");

Now, I on error I want to redirect to public_html/exercises/scripts/show_error.php. I'm using

function handle_error ($user_error_message, $system_error_message) {
header("Location: " . SITE_ROOT . "scripts/show_error.php?" . "error_message={$user_error_message}&" . "system_error_message={$system_error_message}");
exit();
to do that but each time I get

The requested URL /public_html/exercises/scripts/show_error.php was not found on this server.

What am I doing wrong?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem with SITE_ROOT

Post by requinix »

How do they define SITE_ROOT? Is it supposed to be a file path on the server or is it supposed to be a URL? Yes, they are two different things - they overlap a lot, but they are not the same.

It looks like you've given it a value for a file path but you're using it like it has a URL. Try changing it to just "/exercises/".
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Problem with SITE_ROOT

Post by Christopher »

A quick search suggests that you are using a tutorial for lynda dot com. There are several other tutorials that define SITE_ROOT as absolute path to the public HTML directory -- which makes sense from a name using "root". That tutorial seems to use SITE_ROOT as what in HTML is referred to as <base> or sometimes defined as BASE. So bad naming lynda! Maybe try something "http://mysite.com/exercises/" or "http://localhost/exercises/", or the partial URL requinix suggested.
(#10850)
Post Reply