I have a reviews page on my website, and I wanted my website to be extremely user friendly, so I made it a sub-index. I have my index.php under a folder named reviews (found here ) so the domain is just /reviews. When I try to include aphp or CSS it abandons them and excludes them.
The code I am using to include my CSS (which is working on every other page) is:<link rel="stylesheet" type="text/css" href="/stylesheets/index.css">
The PHP include() that I'm using is:<?php include('header.php'); ?>
This PHP works on all pages that do not use a parent folder, ex. index.php (for my homepage).
The HTML in the PHP document is:<html> <center><nav> <ul> <li><a href="/">Home</a></li> <li><a href="">Arcade</a> <ul> <li><a href="/arcade/action">Action</a></li> <li><a href="/arcade/arcade">Arcade</a></li> <li><a href="/arcade/puzzle">Puzzle</a></li> <li><a href="/arcade/vehicle">Vehicle</a></li> <li><a href="/arcade/violence">Violence</a></li> <li><a href="/arcade/defense">Defense</a></li> <li><a href="/arcade/rpg">RPG</a></li> </ul> </li> <li><a href="">Watch</a> <ul> <li><a href="/watch/tv">TV Shows</a></li> <li><a href="/watch/movies">Movies</a></li> </ul> </li> <li><a href="">Extras</a> <ul> <li><a href="/news">Updates</a></li> </ul> </li> <li><a href="/support">Support</a></li> </ul> </nav></center> </html>
Anybody know any solutions to get my PHP and my CSS working in sub-folders?
My website is http://www.gameshank.com/
The homepage is using the header.php file!
Problem courtesy of: Austin BunkerSolution
Call the .PHP file by:<?php include('../header.php') ?>
The /../header.php won't work either...
Then clear your browser history and cookies, then it works from the editing end of things.
Strange fix, but it worked. But until the editor was cleared of history and cookies, it wouldn't work.
Solution courtesy of: Austin BunkerDiscussion
Does this work?$path = $_SERVER['DOCUMENT_ROOT']; $path .= "/header.php"; include($path);
Discussion courtesy of: Wim Molenberghs
If you know that header.php is in the same directory as from the file you want to include it to:include(__DIR__ . '/header.php');
This is immune to changes in the working directory and therefore pretty fail-safe.Magic constants Docs
You might find as well the following Q&A interesting:what is the difference of absolute path in html and php ? Relative paths : going down and up PHP include with ../ failed open
Also it's important to understand the difference between the CSS-URL (URL-path is resolved in the browser) and the paths in PHP (those file-paths are resolved on the server, the browser is yet far far away).
Discussion courtesy of: hakre
This recipe can be found in it's original form on Stack Over Flow .
本文开发（php）相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师