hello, I get this error: PHP Notice: Undefined variable: url in $server_url = $_SERVER['DOCUMENT_ROOT']; $url = $server_url.'/content/'; PHP: what is the reason of this error? regards
Basically it is saying that the variable $url was note declared before using. This is not much of a problem, you can either declare and set variables before using or turn notices off in your php.ini (error reporting settings).
To declare strings in PHP, you use the single quote or double quotes. For example: $url = ''; $url = "";
There is nothing wrong with that, I'm not getting any errors. Try the following: <?php echo $_SERVER['DOCUMENT_ROOT'] . "<br />"; $server_url = $_SERVER['DOCUMENT_ROOT']; $url = $server_url.'/content/'; echo $url; ?> PHP: If you still get errors, then there's probably something wrong with your PHP. =/ There is a big difference between single and double quotes. Single quote doesn't interpret escape sequences, but double quote do. For example: <?php $lol = "what"; echo '$lol'; // this will output "$lol" echo "$lol"; // but this will interpret the variable, thus it will output "what" ?> PHP: See this for more info.
i had them in config.php and i was including config.php in index.php i just tried using by itself and i didn`t get any error. I do not know why i am getting this error when i include.
Aha~ Now we're talking.. It would help if you provide more details (source of both config.php and index.php maybe), there could be a number of reasons. At first, I thought it's because you're including it wrong, but the error should be different so you must be including it correctly. Still, hard to tell with very little details. But I'm betting that you're trying to call a variable that doesn't exist from the other file. (check your typos). The following will generate similar error: <?php error_reporting(E_ALL); $server_urls = $_SERVER['DOCUMENT_ROOT']; $url = $server_url.'/content/'; // typo echo $url; ?> PHP:
i am so stupid. ofcourse i will get the error. i am trying to use a variable while including. Surprisingly it was still working, i was only getting notice. include ($url."inc/config.php"); // $url variable is in config file. PHP:
$url in the include is completely unnecessary because it doesn't contain anything nor does it even exist (that's why you're getting a notice), take it off: include ("inc/config.php"); PHP: Only use relative path whenever you include a file, absolute path gives you headaches.
I would turn notices off in your php.ini file or just set this code in the top of your script, error_reporting(E_ALL ^ E_NOTICE); PHP:
Its best practice to not have these errors then to conceal them. Use isset() before using user submitted data (ie. via $_POST, $_GET, $_REQUEST etc.)
It does matter. Every time a notice, a warning, or an error is triggered by PHP, it opens a log file, writes to it, and closes it. It slows down performance, and really is just... unprofessional. All errors should be reported during development, and should be taken care of before going live with the site.