Jump to content

Recommended Posts

Hi , i read many articles and tried many things before asking but i came to a dead end. My problem is very simple (or at least i believe so).

 

In the main directory \httpdocs there is this file we call "header.php" and another file we call "article.php".

 

So the code of the article is very simple:

 

<?php
include("header.php");
echo "bla bla bla\n";
?>
 
So far so good.
 
Let's say that we create a new folder \httpdocs\new_folder
 
and inside there we create a new file that we call "new_file.php".
 
So we would simple like to call the header.php from the parent folder BUT IT TURNS TO BE IMPOSSIBLE !
 
I have tried:
 
include('../header.php');
(in an article of this website says that this work - well IT DOESN'T !
 
i have tried many other things but i cannot load the header.php from the previous directory !
 
I wanna tip the person who will find the solution so you better leave a paypal along with the answer !
 
 
Link to comment
https://forums.phpfreaks.com/topic/290504-previous-directory-issue/
Share on other sites

Hello,

I tested it on my machine and it works great.

 

File #1: header.php at the root

 

File #2: index.php in a sub folder.

 

Here's the content of index.php:

<?php
include('../header.php');
?>

Are you sure you don't get a permission error or a syntax error? Did you check your logs?

Are you on Windows or Linux?

 

Alternatively, you could try this code:

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/header.php"); 
?>

This is not even loading ! There must be a problem with this symbol ->   '   I dont think you can use " and also '.

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/header.php"); 
?>

The message below

include("httpdocs/new_folder/header.php");

this is totally wrong because header.php is not located in the new folder...

 

 

 

If someone does not believe me i can provide user/pass to see himself...

 

All these things and many more are simply NOT WORKING.

Edited by xubuntu69

Either of the solution mogosselin posted should be working for you from how you described your problem.

 

 

 

There must be a problem with this symbol ->   '   I dont think you can use " and also '.

What! That is nonsense. An array key can be wrapped in single or double quotes doesn't matter which is used. 

 

Do you get any error messages? If you don't then I suggest your turn error reporting on. Either in your php.ini configuration or apply this to the very top of your code (after the opening PHP tag)

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

ok so....

 

<?php
$magictitle = "Blinds Stealing - Poker Lesson School";
require_once('mainfile.php');
$module_name = basename(dirname(__FILE__));
$index = 1;
include('header.php');
include('footer.php');
?>

this file is working , have a look

www.pokerhaze.com/az.php

 

But his file ...

 

 

<?php
$magictitle = "Blinds Stealing - Poker Lesson School";
require_once('../mainfile.php');
$module_name = basename(dirname(__FILE__));
$index = 1;
include('../header.php');
include('../footer.php');
?>

this file is not working , look here www.pokerhaze.com/blog/az.php

 

i had the "errors display" on .. without any errors...

 

could someone explain what is going on and why the file httpdocs/blog/az.php folder cannot read the files from parent folders?

 

I have tested also other folders and other file names, can't do it.

Edited by xubuntu69

 

 

i had the "errors display" on .. without any errors...

In the php.ini?

 

If thats the case you should not be getting a blank white screen. Check your servers error logs for the errors too.

 

Your could change your code to this to see where it is failing

<?php

echo "I am in: " . getcwd();

function require_file($file)
{
    echo "<p>Checkfing if $file exists in ".realpath(dirname($file))." ...";
    if(file_exists($file))
    {
        echo "OK, attemping to require it... ";
        require_once($file);
        echo "OK";
    }
    else
    {
        echo 'FAIL';
    }
    echo '</p>';
}

$magictitle = "Blinds Stealing - Poker Lesson School";
require_file('../mainfile.php');
$module_name = basename(dirname(__FILE__));
$index = 1;
require_file('../header.php');
require_file('../footer.php');
?>
Edited by Ch0cu3r

This link http://www.pokerhaze.com/blog/az.php is throwing a "500 internal server error" 

 

What are the  permissions on the blog folder ? Try matching them to the httpdocs folder (just a guess)

Also try commenting out the includes one by one to see what is causing the internal server error.

Check the permissions on the files in this particular directory. Now should work - http://www.pokerhaze.com/blog/az.php

 

The files (header and footer) should be executable also to be able to execute the content.

 

What do you want to accomplish, a new template?

Edited by jazzman1

I want to accomplish this :

there is an addon that i installed

www.pokerhaze.com/blog

 

and i want to load this add on with the header and the footer of my website !!!! Thats all !!

 

 can we do it ? 

 

your new script is not working 

 

http://www.pokerhaze.com/blog/az.php

 

it seams so easy and so impossible....

Edited by xubuntu69

The content management is irrelavent.

 

Just make a new folder, create a new file in there and try to include the header or footer from the previous folder... it will turn out to be impossible.

 

The server setup that someone mentioned above is also irrelavent.

 

There are no restrictions of any kind like httaccess ... 

 

The conclussion is this

 

FILES from previous folders cannot be loaded.

 

:P

Edited by xubuntu69

No, it is :) The header and footer files are part of this CMS and they contain a lot of logic. If you create files for instance,  _header.php and _footer.php in the same directory when header.php and footer.php are, you will be able to include them to az.php ( I tried ) Try!

Edited by jazzman1

@xubuntu69 so this is all false information!

 

Do you really think if this was not possible we'd post code which will never work.

 

Also it would of been beneficial at the start you told use that these files you were trying to include where part of your CMS. 

 

Jazzman1 has concluded your CMS is at fault. It is restricting where certain files can and can nott be included from, maybe its for security. You can only blame the creators of the CMS for not being flexible enough.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.