我得到了文件index.php,其中包括管理文件夹中的index.php文件
<?php require 'admin/index.php'; ?>
在管理文件夹index.php文件基本上是导入2个css文件的登录表单
<DOCTYPE HTML>
<html>
<head>
<title>Simple Login Form</title>
<meta charset="UTF-8" />
<meta name="Designer" content="PremiumPixels.com">
<meta name="Author" content="$hekh@r d-Ziner, CSSJUNTION.com">
<-- site layout -->
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/structure.css" />
</head>
<body>
<form id="myForm" class="boxlogin" action="index.php" method="POST">
<fieldset class="boxBody">
<label>Email <span style="color:red;"><?php if(isset($errorMsg)) echo $errorMsg;?></span></label>
<input name="email" type="text" tabindex="1" placeholder="root" required>
<label><a href="" class="rLink" tabindex="5">Forget your password?</a>Password</label>
<input name="password" type="password" tabindex="2" required>
</fieldset>
<div class="footer">
<label><input type="checkbox" tabindex="3">Keep me logged in</label>
<input type="submit" class="btnLogin" value="Login" tabindex="4"/>
</div>
</form>
</body>
</html>
当我运行index.php文件时,脚本包括admin/index.php文件。但是css的链接被破坏了,因为包含了admin/index.php文件在具有不同路径的文件中。
我可以将.css文件路径更改为
<link rel="stylesheet" type="text/css" href="admin/css/reset.css" />
<link rel="stylesheet" type="text/css" href="admin/css/structure.css" />
这将解决问题,但如果我想从另一个路径调用/admin/index.php脚本,该怎么办。
假设"根文件夹"不在服务器上的根文件夹中,例如/var/www/php/loginscript/
对于这种情况,最好的解决方案是什么?谢谢
这样做:
<link rel="stylesheet" type="text/css" href="/css/reset.css" />
<link rel="stylesheet" type="text/css" href="/css/structure.css" />
注意hrefs
中添加的/
我会为每个静态内容创建一个绝对的URL(如:/css/reset.css),并在HTML中设置一个标记。