note 124052 added to reserved.variables.server

From: Date: Sun, 21 Jul 2019 05:42:21 +0000
Subject: note 124052 added to reserved.variables.server
Groups: php.notes 
Request: Send a blank email to php-notes+get-211626@lists.php.net to get a copy of this message
So near, and yet so far … $_SERVER has nearly everything you need to know about the current web page environment. Something which would have been handy is easy access to the protocol and the actual web root. For the protocol, you may or may not have $_SERVER['HTTPS'] and it may or may not be empty. For the web root, $_SERVER['DOCUMENT_ROOT'] depends on the server configuration, and doesn’t work for virtual hosts. For practical purposes, I normally include something like the following in my scripts: <?php // Web Root // Usage: include("$root/includes/something.inc.php"); $root = $_SERVER['WEB_ROOT'] = str_replace($_SERVER['SCRIPT_NAME'],'',$_SERVER['SCRIPT_FILENAME']); // Host & Protocol // Usage: $url = "$protocol://$host/images/something.jpg"; $host = $_SERVER['HTTP_HOST']; $protocol=$_SERVER['PROTOCOL'] = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http'; ?> ---- Server IP: 208.43.231.9 Probable Submitter: 82.199.157.54 (proxied: 60.241.83.80) ---- Manual Page -- http://php.net/manual/en/reserved.variables.server.php Edit -- https://master.php.net/note/edit/124052 Del: integrated -- https://master.php.net/note/delete/124052/integrated Del: useless -- https://master.php.net/note/delete/124052/useless Del: bad code -- https://master.php.net/note/delete/124052/bad+code Del: spam -- https://master.php.net/note/delete/124052/spam Del: non-english -- https://master.php.net/note/delete/124052/non-english Del: in docs -- https://master.php.net/note/delete/124052/in+docs Del: other reasons-- https://master.php.net/note/delete/124052 Reject -- https://master.php.net/note/reject/124052 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#211626) next »