-3

My code is below

$base = if((!empty(($_SERVER['HTTPS']  ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'));

I'm checking whether $_SERVER['HTTPS'] is not empty but I get this notice:

Notice: Undefined index: HTTPS in D:\xampp\htdocs\flower-shop\flowers.php on line 24

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

The following code should work. If you notice, in the PHP shorthand you don't include the if word.

<?php
   $base = (isset($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].'/';
?>

I would not rely on $_SERVER['HTTP_HOST'] since this can be modified by the client and can cause some huge issues.

halfer
  • 19,824
  • 17
  • 99
  • 186
David
  • 4,313
  • 1
  • 21
  • 29
  • I expect that the question indicated as a duplicate probably is the correct response - the OP accessed an array index that does not exist, and that dup should show them how to fix it. If it was not marked as dup, it could probably be closed as "typographical error" on the basis of the close reason text: "while similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers". – halfer Mar 28 '15 at 20:44