Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php include doesn't work even inside the same folder

Tags:

include

php

reg.php is in members folder

<?php include "members/reg.php";?>  // doesn't work
<?php include ("members/reg.php");?>  // doesn't work

Then I replace reg.php in the same folder as the current file

<?php include "reg.php";?>  //doesn't work.
like image 757
Alegro Avatar asked Dec 27 '12 08:12

Alegro


People also ask

What does include () do in PHP?

PHP Include Files. The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

Can we include one PHP file multiple times?

If the file is included twice, PHP will raise a fatal error because the functions were already declared. It is recommended to use include_once instead of checking if the file was already included and conditionally return inside the included file.


2 Answers

Try this

ini_set( 'error_reporting', E_ALL );
ini_set( 'display_errors', true );

include './members/reg.php';

Possibly the include worked but caused a silenced error.

like image 182
Michel Feldheim Avatar answered Sep 19 '22 23:09

Michel Feldheim


With:

define('ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);

you can define the root of your project (which is the one the file you put it in) and then call:

include ROOT."members/reg.php";
like image 37
Shoe Avatar answered Sep 16 '22 23:09

Shoe