简体   繁体   中英

Undefined index: REQUEST_URI and HTTP_HOST

How can I get rid of this errors.

Line 8 : define('CURRENT_PAGE', basename($_SERVER['REQUEST_URI']));
Line 15: define('READ_PATH', $_SERVER['HTTP_HOST'].'/read.php?id=');

errors:

Undefined index: REQUEST_URI in ......... on line 8
Undefined index: HTTP_HOST in ....... on line 15

if you use CLI then u can check them for their existence but in the browser, HTTP_HOST will be available any time.

 if (!empty($_SERVER['HTTP_HOST'])) {
    define('CURRENT_PAGE', basename($_SERVER['HTTP_HOST']));
 }

 if (!empty($_SERVER['REQUEST_URI'])) {
     define('CURRENT_PAGE', basename($_SERVER['REQUEST_URI']));
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM