Reputation: 171
My hostname is
Inside HEAD I have
<?php include("http://gvidas.lhosting.info/includes/header.php"); ?>
Physical location of that file is in /htdocs/includes/header.php
Why doesn't it work? Should I use relative paths?
Fragment of index.php
root/htdocs/index.php:
<!DOCTYPE HTML>
<HTML>
<HEAD>
<?php include("includes/header.php"); ?>
<?php if (isset($_SESSION["admin_id"])) { redirect("managePage.php"); } ?>
<?php $permision = "public"; ?>
</HEAD>
<BODY>
<...>
</BODY>
</HTML>
Fragment of header.php
root/htdocs/includes/header.php:
<?php require_once ("../includes/session.php"); ?>
<?php require_once ("../includes/functions.php"); ?>
<?php $db = mysqli_connect('http://gvidas.lhosting.info/', 'user', 'pass', 'beta');
if(mysqli_connect_errno()) { die("Database connection failed: " .
mysqli_connect_error() . " (" . mysqli_connect_errno() . ")");
}
?>
I now think I should use
<?php require_once ("session.php"); ?>
innstead of
<?php require_once ("../includes/session.php"); ?>
Any thoughts?
Upvotes: 0
Views: 511
Reputation: 1403
You can't use a internet address as path for includes/requires, use a physical path instead, like /htdocs/includes/header.php
.
Upvotes: 1
Reputation: 53198
Most live servers won't allow absolute including. You can update the code as follows:
<?php include("includes/header.php"); ?>
The relative path will depend where you're including the file from. The above example assumes that the file in which this include()
function is called from a file inside the web root.
Upvotes: 3
Reputation: 993
try this code
$path = $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_NAME'];
<?php include("$path/includes/header.php"); ?>
Upvotes: 0
Reputation: 321
You should use physical location rather than URI.
<?php include("/htdocs/includes/header.php"); ?>
Upvotes: 3