Absolute address (including script) in PHP

0

Consider the following html address:

http://exemplo.com/1/2/3/teste.php

I wanted to indicate in the variable $ender the absolute address of my scripts (including them) to be found independent of the change of address (being in the root or subdirectory). I tried this "http://$_SERVER[HTTP_HOST]$SERVER[REQUEST_URI]" to try to at least replace this: ( http://exemplo.com/1/2/3/ ). Did not work. I wanted to avoid the literalness of everything ( http://exemplo.com/1/2/3/teste.php ). I just had some partial success with http: // $ _ SERVER [HTTP_HOST], but it only replaces the base address.

<?php
error_reporting(E_ALL);
$host = $_SERVER['HTTP_HOST']$SERVER['REQUEST_URI']/;
$id   = $_GET['id'];
if ($id == 1) {
    
asked by anonymous 24.10.2017 / 22:11

1 answer

0

It seems like you have a syntax error there. Try this:

$protocolo = empty($_SERVER['HTTPS']) ? 'http://': 'https://';
$url = $protocolo . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $url;
    
24.10.2017 / 22:31