Pergunta

I'm a php noob, so bear with me...

I have two files here. Both are in the SAME directory

I have a config file:

config.php

<?php
date_default_timezone_set('America/Chicago');

define('APP_NAME',"/control");
define('HTTP_SERVER', 'http://localhost/');
define('SITE_NAME', 'http://localhost/');
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT'].APP_NAME);
?>

Then I have my index file:

index.php:

<!DOCTYPE html>
<html>
<head>
<?php
require ('config.php');
echo "<script type='text/javascript' src='".DOCUMENT_ROOT."/scripts/jquery.js"'></script>;
?>
.....THE REST OF MY HTML.....

But I get an error that "DOCUMENT_ROOT" is undefined. Why is it not pulling the value from the config.php file?

Foi útil?

Solução

Change this line: (missing ending quote " after </script> and $ sign in front of DOCUMENT_ROOT)

I tested the following on my server and the script did load, since I do have jquery.js on mine.

echo "<script type='text/javascript' src='".DOCUMENT_ROOT."/scripts/jquery.js"'></script>;

to:

echo "<script type='text/javascript' src='$DOCUMENT_ROOT/scripts/jquery.js'></script>";

or:

echo "<script type='text/javascript' src='".DOCUMENT_ROOT."/scripts/jquery.js'></script>";

Outras dicas

You need to dereference your variable using $:

$DOCUMENT_ROOT

That is assuming it's been properly defined in the server environment.

There is a small syntax error at the end of your echo, otherwise it works fine for me.

echo "<script type='text/javascript' src='".DOCUMENT_ROOT."/scripts/jquery.js\"'></script>";
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top