g Void
g Void

Reputation: 171

php include when hosting

My hostname is

http://gvidas.lhosting.info

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

Answers (4)

Talysson
Talysson

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

BenM
BenM

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

Anil Meena
Anil Meena

Reputation: 993

try this code

 $path = $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_NAME'];

 <?php include("$path/includes/header.php"); ?>

Upvotes: 0

Irwan
Irwan

Reputation: 321

You should use physical location rather than URI.

<?php include("/htdocs/includes/header.php"); ?>

Upvotes: 3

Related Questions