I have this code snippet, 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 the cookie to load with the first URL URI so it does not change every time you press F5 or you have to redo every time you press F5, and in this In case, I can not assign any value to this cookie siteindex
before the if
happens or it would not have 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 snippet, since I have if
of this style in several places, has the variable declared for it to know if it exists and, if so, to do something, if not, only show, in online servers that do not have display_error
they work but in localhost that has display_error
they do not work. I did not want to turn off dislay_error
, but I would heal this without declaring the variable with some value that would prevent it from working.
How would you do that?
An example of 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 on line 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: Can not 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 /