Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
requiring using /var/www works but using localhost doesnt work

I am new to working on linux environment and i am also working on a php project on linux. And I faced a problem while requiring php files. I have two php files called test.php and database.php. Both this files are in /var/www/TEST/.

This the code in database.php

<?php echo("You have included the database"); ?>

And this is the code in test.php

<?php require("/var/www/TEST/database.php");?>

Then when i browse to test.php using firefox i get the expected output "you have included the database". but when I change test.php to

<?php require("localhost/TEST/database.php"); ?>

I get no out put when I browse to test.php. I have started the apache service and also changed the file access of /var/www/ to 755. I hope you could help me on why I am getting this kind of result. Thank you.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

First you should enable error reporting:

<?php 
// Put these lines to the top of your script
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
ini_set('xmlrpc_errors', true);

Then you try to include a file via HTTP stream, but you forgot http:// or https:// before localhost and including via stream is disabled for security reason. The configuration is allow_url_include. It's off by default and you should leave it off.

Try to get into composer / psr classmaps / psr autoloading. This is kinda "industry standard" mechanism. You should go for that.

over 4 years ago · Santiago Trujillo Relatório

0

To make it as a static reference you can code it like:

require($_SERVER['DOCUMENT_ROOT'] . '/TEST/database.php'); // $_SERVER['DOCUMENT_ROOT'] gets you '/var/www' or whatever your server root maybe
over 4 years ago · Santiago Trujillo Relatório

0

<?php require("database.php");?>

<?php require("database.php"); ?>

No Need To require Full Path When You Are Working in One Folder

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda