-1

I found the problem on my old apps, PHP Notice: Undefined offset: 1

This is the code:

    $uri = "sub.examples.com";
    $pageurl = explode("/",$uri);
    if($uri=='/') {
        $homeurl = "https://".$_SERVER['HTTP_HOST'];
        (isset($pageurl[1])) ? $pg = $pageurl[1] : $pg = '';
        (isset($pageurl[2])) ? $ac = $pageurl[2] : $ac = '';
        (isset($pageurl[3])) ? $id = $pageurl[3] : $id = 0;
    } else {
        $homeurl = "https://".$_SERVER['HTTP_HOST'].$pageurl[1];
        (isset($pageurl[2])) ? $pg = $pageurl[2] : $pg = '';
        (isset($pageurl[3])) ? $ac = $pageurl[3] : $ac = '';
        (isset($pageurl[4])) ? $id = $pageurl[4] : $id = 0;
    }

The errors in the line

$homeurl = "https://".$_SERVER['HTTP_HOST'].$pageurl[1];

Can anyone provide a solution?

Thanks, Regards.

Ahmad
  • 65
  • 1
  • 8
  • 1
    not sure what are you trying to achieve but $pageurl[1] will be set only if the $uri is something like $uri = 'sub.examples.com/something' in which case the $pageurl[1] will be 'something' – marac990 Apr 23 '21 at 17:50
  • You're not using the [ternary operator](https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary) correctly. A ternary returns either the left or right value based on the comparison at the beginning. You do not do the assignments inside of the ternary. – aynber Apr 23 '21 at 17:56

1 Answers1

0
$homeurl = "https://".$_SERVER['HTTP_HOST'].$pageurl[0];

replace this line.

Braiam
  • 1
  • 11
  • 47
  • 78
  • this would lead to $homeurl = 'example.comsub.examples.com' if $_SERVER['HTTP_HOST'] is 'example.com' – marac990 Apr 23 '21 at 17:53