1

I want to define the BASE tag in html using PHP

<!DOCTYPE html>
<html lang="<?php echo LANG; ?>">
<head>
    <meta charset="<?php echo CHARSET; ?>">
    <base href="<?php echo BASE; ?>">
</head>
....

Did some research here, and came up with this.

config.inc.php

define('LANG', 'es_ES');
define('CHARSET', 'utf-8');
define('SERVER_SERVER_NAME', 'http://' . $_SERVER['SERVER_NAME']);
define('SERVER_PHP_SELF', dirname($_SERVER['PHP_SELF']));

define('BASE', SERVER_SERVER_NAME . SERVER_PHP_SELF . '/');

2 questions:

  1. Is there a way to define the keyword http? Sometimes it can be https and hardcoding that keyword is a bad idea.

  2. Should i define the BASE value by ending it with a slash or not ?

Any improvements on this very simple code?

Thanks

Barmar
  • 741,623
  • 53
  • 500
  • 612
Marco
  • 2,687
  • 7
  • 45
  • 61

1 Answers1

4
  1. Just leave the protocol out, and start the URL with //. It will then default to the protocol of the document that contains it.

  2. The <base> URL should end with a / if you want it to specify a folder.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • [That's what I said...](http://stackoverflow.com/questions/43396937/define-base-tag-in-html-using-php#comment73854794_43396937) - 2 mins. prior ;-) – Funk Forty Niner Apr 13 '17 at 16:07
  • I was typing my answer at the same time as you were commenting. I needed to do some googling to check the `` part, so I didn't post it immediately. – Barmar Apr 13 '17 at 16:11
  • Seeing http://stackoverflow.com/a/1889957/1415724 shows potential problems with the `` tag with certain versions of IE. – Funk Forty Niner Apr 13 '17 at 16:14
  • @Fred-ii- It says the problem is in IE6. That's prehistoric. IE8 is the oldest version anyone has even the slightest concern about, and even that is mostly dwindling. – Barmar Apr 13 '17 at 16:34