Home > Blockchain >  Undefined index: REQUEST_URI and HTTP_HOST
Undefined index: REQUEST_URI and HTTP_HOST

Time:12-26

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

CodePudding user response:

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']));
 }
  •  Tags:  
  • php
  • Related