0

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?

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Show your directory structure. Where are you calling the include() function from?
This is my structure: postimg.org/image/vge1ouy4h I'm calling it from index.php
OK, which file are you trying to include the header.php file into? Everything in root?
header.php is in folder includes, the full path to it is root/htdocs/includes
Yes, I can see that. My question is where are you calling the include() from? i.e. is it from htdocs/index.php?
|
3

You should use physical location rather than URI.

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

Comments

1

You can't use a internet address as path for includes/requires, use a physical path instead, like /htdocs/includes/header.php.

Comments

0

try this code

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.