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
JazzKennyWowy
Forum Newbie
Posts: 1
Joined: Wed Mar 14, 2018 10:59 am

Problem with SITE_ROOT

Post by JazzKennyWowy »

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
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 »

You have defined your SITE_ROOT as a file system path:

Code: Select all

define("SITE_ROOT", "/public_html/exercises/");
However, in your function you are using it as a URL:

Code: Select all

header("Location: " . SITE_ROOT . "scripts/show_error.php?" . "error_message={$user_error_message}&" . "system_error_message=
You probably want to define it as a URL instead:

Code: Select all

define("SITE_ROOT", "http://mysite.com/exercises/");
(#10850)
Post Reply