$_SERVER['HTTP_HOST'] generating 2 times

Asked

Viewed 34 times

-3

I’m having a hard time.

I’m in the localhost and I want to take the path of website to advance a link of a image

$uri = $_SERVER['HTTP_HOST'] . '/mvc_crud_pdo'; 

$iconeTransporte = $produtos->getTransporte() == 'Correios' 
          ?'<img src ="' . $uri . '/imgs/iconeCorreiosCaminhao.png" style="height:45px;" title="Correios" />' 
          :<img src ="' . $uri . '/imgs/iconeTransportadoraCaminhao.png" style="height:45px;" title="Transportadora" />';

mvc_crud_pdo is the domain.

Something like:

http://localhost/mvc_crud_pdo

But the following is happening problem: inserir a descrição da imagem aqui

Note that in Elements, the link is correctly generated but in console gives error:

What must I do to correct this duplicity?

  • Note that the URL you want to generate, as well quoted, has the http://, but in your code at no time this is added to the value. Search for relative URL difference to absolute URL and understand the problem.

  • Thank you, I get it! That’s right!

1 answer

0

I do it this way:

  • I create a file called Constants.php:

In this file I save all the paths of my application as in the example:

// Diretório absoluto do servidor / htdocs ou www/html.
define("docRoot", $_SERVER["DOCUMENT_ROOT"]);

// Caminho relativo da aplicação:
define("docProject", "/MeuApp");

// Caminho aboluto da plicação:
define("docRootProject", (docRoot . "/MeuApp"));

// Caminho relativo da pasta imagens.
define("docImagens", (docProject . "/imgs"));

// Caminho absoluto da pasta imagens.
define("docRootImagens", (docRootProject . "/imgs"));

And so on for all folders used in the application.

For use would look something like this:

$iconeTransporte = ($produtos->getTransporte() == 'Correios')
? '<img src ="' . docImagens . '/iconeCorreiosCaminhao.png." style="height:45px;" title="Correios" />'
: '<img src = "' . docImagens . '/iconeTransportadoraCaminhao.png" style = "height:45px;" title = "Transportadora" />';
  • The "docPasta" are for links;
  • "docRootPasta" is for requires and includes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.