Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Directory traversal and file inclusion problem

Hello everyone,

I followed Alex's register and login series from PHP Academy. I made one like his just the same way just that my CSS files were different. Now this is my problem.

My bootstrap folder contains css, js and img folders. My core folder contains init file, database folder having connect file and functions folder having general functions and user functions files. My includes folder contains the header, footer, navbar and all, along with an overall folder having overall header and overall footer.

All the files included above are linked and relative to the index.

I created a new folder called forums in the root directory and I put an index file inside it. I just put the path as include '../core/init.php', include '../includes/overall/header.php', etc. Just added two dots to traverse back and then include the files and styles but I am getting all sorts of warnings and errors. I want to create a new folder in the root directory and include all these files, functionality and styles. Please help me do this.

Thank You!
Maybe if you could show us the code in question we could help you better.
[Image: wOdD4yf.gif]
We can't really help you, witout you telling us what these errors are.

The most obvious ones would be your relative paths are incorrect.

Try using absolute paths and see if that works out for you.
PHP Code

<?php 
    
include '/../core/init.php';
    include 
'/../includes/overall/header.php';
?>

    <div class="hero-unit">
    <h2><center>FORUMS</center></h2>
    Welcome. All the resources related to the 
    academics can be found here!
    </div>

<?php include '/includes/overall/footer.php' ?>

That's my code inside the forums folder placed in the root directory.

And these are my errors.

Code
Warning: include(includes/head.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 5

Warning: include(): Failed opening 'includes/head.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 5

Warning: include(includes/header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 10

Warning: include(): Failed opening 'includes/header.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 10

Warning: include(includes/navbar.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 11

Warning: include(): Failed opening 'includes/navbar.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 11
FORUMS
Welcome. All the resources related to the academics can be found here!

Warning: include(/includes/overall/footer.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\forums\index.php on line 13

Warning: include(): Failed opening '/includes/overall/footer.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\forums\index.php on line 13

So the content is displayed but not the styles, not the functionality.

May be if you still can't figure out, I will zip the whole folder and give you. Here's the link. http://www.mediafire.com/?4zhfh7r8me95n0w
(Dec 25, 2012 09:51 PM)trollster Wrote:  
PHP Code

<?php 
    
include '/../core/init.php';
    include 
'/../includes/overall/header.php';
?>

    <div class="hero-unit">
    <h2><center>FORUMS</center></h2>
    Welcome. All the resources related to the 
    academics can be found here!
    </div>

<?php include '/includes/overall/footer.php' ?>

That's my code inside the forums folder placed in the root directory.

And these are my errors.

Code
Warning: include(includes/head.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 5

Warning: include(): Failed opening 'includes/head.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 5

Warning: include(includes/header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 10

Warning: include(): Failed opening 'includes/header.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 10

Warning: include(includes/navbar.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 11

Warning: include(): Failed opening 'includes/navbar.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\includes\overall\header.php on line 11
FORUMS
Welcome. All the resources related to the academics can be found here!

Warning: include(/includes/overall/footer.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Study\TestSite\forums\index.php on line 13

Warning: include(): Failed opening '/includes/overall/footer.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Study\TestSite\forums\index.php on line 13

So the content is displayed but not the styles, not the functionality.

May be if you still can't figure out, I will zip the whole folder and give you. Here's the link. http://www.mediafire.com/?4zhfh7r8me95n0w
See that following slash (/includes)?

That doesn't work in PHP :( I'm assuming that's why you're getting an error.
If you add a beginning slash php will think its an absolute path.
[Image: wOdD4yf.gif]
Then how do I get rid of the problem?
Get rid of the beginning slash? So then php will take it as a relative path.
[Image: wOdD4yf.gif]
Got the same bunch of errors. Could you please check out the files I put in that link?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Javascript]  by MavenGradleJan 23, 2020 03:39 PM 11 450 Jan 23, 2020 03:39 PM
Last Post: MavenGradle
[PHP] by BabadookFeb 1, 2019 10:50 PM 11 367 Feb 1, 2019 10:50 PM
Last Post: Babadook
[PHP] by Viper228Aug 26, 2018 02:28 PM 0 123 Aug 26, 2018 02:28 PM
Last Post: Viper228