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:
Is there a way to define the keyword http
? Sometimes it can be https
and hardcoding that keyword is a bad idea.
Should i define the BASE value by ending it with a slash or not ?
Any improvements on this very simple code?
Thanks
Just leave the protocol out, and start the URL with //
. It will then default to the protocol of the document that contains it.
The <base>
URL should end with a /
if you want it to specify a folder.