1
I have this snippet of code, but many others follow the same style:
if(!$_COOKIE[SITEINDEX]) {
setcookie(SITEINDEX, max(explode('/', dirname($_SERVER[PHP_SELF]))));
define(siteindex, '/' . max(explode('/', dirname($_SERVER[PHP_SELF]))) . '/');
} else {
define(siteindex, '/' . $_COOKIE[SITEINDEX] . '/');
}
It causes when loading the page, create a cookie with the first URL URI so it doesn’t keep changing every time you press F5 or have to redo every time you press F5 and in this case I can’t assign any value to this cookie siteindex
before the if
or it would have no logic and that’s where the problem comes in. PHP displays notices "siteindex" not defined and prevents the application from being loaded, not only with this excerpt, as I have if
of this style in several places, which does not have the variable declared for it to know if it exists and, if yes, do something, if not, only show, on online servers that does not have display_error
they work but on localhost that has display_error
they don’t work. I didn’t want to turn off the dislay_error
, but fix it without declaring the variable with some value that will prevent it from working.
How would you do that?
An example from Notices is this
<?php
define(siteprot, $_SERVER[HTTPS] ? 'https://' : 'http://');
define(sitehost, $_SERVER[HTTP_HOST]);
define(siteuri, $_SERVER[REQUEST_URI]);
if(!$_COOKIE[SITEINDEX]) {
setcookie(SITEINDEX, max(explode('/', dirname($_SERVER[PHP_SELF]))));
define(siteindex, '/' . max(explode('/', dirname($_SERVER[PHP_SELF]))) . '/');
} else {
define(siteindex, '/' . $_COOKIE[SITEINDEX] . '/'); }
define(siteurl, siteprot . sitehost . siteindex);
define(secret, '/' . max(explode('/', dirname($_SERVER[PHP_SELF]))) . '/');
?>
Notice: Use of Undefined Constant siteprot - assumed 'siteprot' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 2
Notice: Use of Undefined Constant HTTPS - assumed 'HTTPS' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 2
Notice: Use of Undefined Constant sitehost - assumed 'sitehost' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 3
Notice: Use of Undefined Constant HTTP_HOST - assumed 'HTTP_HOST' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 3
Notice: Use of Undefined Constant siteuri - assumed 'siteuri' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 4
Notice: Use of Undefined Constant REQUEST_URI - assumed 'REQUEST_URI' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php online 4
Notice: Use of Undefined Constant SITEINDEX - assumed 'SITEINDEX' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 6
Notice: Undefined index: SITEINDEX in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 6
Notice: Use of Undefined Constant SITEINDEX - assumed 'SITEINDEX' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 7
Notice: Use of Undefined Constant PHP_SELF - assumed 'PHP_SELF' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 7
Warning: Cannot Modify header information - headers already sent by (output Started at D: Roberto Monteiro Desktop Server 57 www qrcode index.php:2) in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 7
Notice: Use of Undefined Constant siteindex - assumed 'siteindex' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 8
Notice: Use of Undefined Constant PHP_SELF - assumed 'PHP_SELF' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 8
Notice: Use of Undefined Constant siteurl - assumed 'siteurl' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 12
Notice: Use of Undefined Constant secret - assumed 'secret' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 13
Notice: Use of Undefined Constant PHP_SELF - assumed 'PHP_SELF' in D: Roberto Monteiro Desktop Server 57 www qrcode index.php on line 13 /qrcode//qrcode/
yeah, I know I could trade everything for isset or Empty but it’s over 60,000 lines, I switched some and it works great, but then again, I didn’t want to have to use something I stopped using which is Empty and isset, but Valew
– flourigh
added an example of notices if connect display error
– flourigh
actually works in any version of php I am currently in 7 but was in 5, is that with error off it works but when linking is that of error, but I will try with these you put
– flourigh
really, with these (E_ERROR | E_WARNING | E_PARSE) it allowed the execution of the script without displaying the notices, has it possible not to display only notice or need to stipulate everyone I want to display except notice? because I want to see all the errors except the ones that aren’t exactly a mistake
– flourigh
I updated the answer by adding at the end the part of the error re-port
– Don't Panic
cool just put what we don’t want
– flourigh
I don’t know why, but the ones I used only worked like this E_ALL & ~E_NOTICE | E_STRICT
– flourigh
I think it’s best to review this issue of errors Why use error_reporting with display_errors and display_startup_errors? ;)
– Guilherme Nascimento
@Guilhermenascimento Inkei in response to the other Post
– Don't Panic
@Guilhermenascimento Corrected!
– Don't Panic
@Everson is not really a matter of correction is just a feature tip to simplify something, both ways are correct :)
– Guilherme Nascimento