未加星标

PHP header file isn't working in a subfolder

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二05 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏

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 Bunker

Solution

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 Bunker

Discussion

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开发工程师 软件开发流程 软件开发工程师

代码区博客精选文章
分页:12
转载请注明
本文标题:PHP header file isn't working in a subfolder
本站链接:https://www.codesec.net/view/628463.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(315)