我正在练习制作漂亮的链接
我有这个页面:
http://news.red-sec.net/article/26/This-is-a-title
它工作得很好,它的原始页面是
article.php?id = 26& title =这是一个标题//抱歉根据堆栈溢出不能发布2个以上的链接
你幸运的是他们都是一样的
我尝试为用户/用户名做同样的事情:
http://red-sec.net/user/badboy17< - 页面的样式似乎缩短了一半。
原页是
user.php?u = badboy17 //再次对不起(这个页面按我要的方式工作)
这是user.php页面的代码:
<?php
ini_set('session.cookie_domain', '.red-sec.net');
session_set_cookie_params(0, '/', '.red-sec.net');
session_start();
include 'res/connection.php';
include 'res/menu.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>R3D S3C | Home page</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style1.css"/>
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
</head>
<body>
<?php menu(); ?>
<?php
if(isset($_GET['u'])){
$user = $_GET['u'];
$query = "SELECT * FROM users WHERE username = '$user'";
$r = mysqli_query($connect,$query);
$num_rows = mysqli_num_rows($r);
echo $num_rows;
if($num_rows < '1'){
header('Location: index.php');
}else{
$row = mysqli_fetch_array($r);
$username = $row['username'];
$email = $row['email'];
echo "<h2 class='title'>$username</h2>";
}
}else{
header('Location: http://red-sec.net');
}
?>
<?php endbd(); ?>
</body>
</html>
menu.php的代码,其中函数menu()和endbd()都是:
<?php
require 'connection.php';
function menu(){
if(!isset($_SESSION['username'])){
echo '<nav class="navbar navbar-default navbar-fixed-top shadow">
<div class="container">
<a href="http://red-sec.net" class="navbar-brand">Red-Sec.net</a>
<ul class="nav navbar-nav">
<li class="menuitem"><a href="http://red-sec.net">Home</a></li>
<li class="menuitem"><a href="http://announcements.red-sec.net">Announcements</a></li>
<li class="menuitem"><a href="http://forum.red-sec.net">Forum</a></li>
<li class="menuitem"><a href="http://blog.red-sec.net">Blog</a></li>
<li class="menuitem"><a href="http://news.red-sec.net">News</a></li>
<li class="menuitem"><a href="http://donate.red-sec.net">Donate</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="menuitem"><a href="http://red-sec.net/signup.php">Sign Up</a></li>
<li class="menuitem"><a href="http://red-sec.net/Login.php">Log In</a></li>
</ul>
</div>
</nav>
<script
src="https://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script>
<script src=" ../js/menu.js"></script>
<div class="container bg">
<div class="row full">
<div class="col-lg-8 bd">';
}else{
$username = $_SESSION['username'];
echo '<nav class="navbar navbar-default navbar-fixed-top shadow">
<div class="container">
<a href="http://red-sec.net" class="navbar-brand">Red-Sec.net</a>
<ul class="nav navbar-nav">
<li class="menuitem"><a href="http://red-sec.net">Home</a></li>
<li class="menuitem"><a href="http://announcements.red-sec.net">Announcements</a></li>
<li class="menuitem"><a href="http://forum.red-sec.net">Forum</a></li>
<li class="menuitem"><a href="http://blog.red-sec.net">Blog</a></li>
<li class="menuitem"><a href="http://news.red-sec.net">News</a></li>
<li class="menuitem"><a href="http://donate.red-sec.net">Donate</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="menuitem"><a href="http://red-sec.net/profile.php">'.$username.'</a></li>
<li class="menuitem"><a href="http://red-sec.net/Logout.php">Log Out</a></li>
</ul>
</div>
</nav>
<script
src="https://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script>
<script src="../js/menu.js"></script>
<div class="container bg">
<div class="row full">
<div class="col-lg-8 bd">';
}
}
function endbd(){
require'connection.php';
echo '</div>
<div class="col-lg-4 bd sidebar stick">
<h2 class="title" style="margin-left:0%!important;">Latest News Posts</h2>
<hr class="under">';
$query = "SELECT * FROM news ORDER BY date DESC LIMIT 5";
$run = mysqli_query($connect,$query);
if(!$run){
echo 'sorry';
}
while($row = mysqli_fetch_array($run)){
$article_id = $row['article_id'];
$user_id = $row['user_id'];
$title = $row['title'];
$content = $row['content'];
$date = $row['date'];
$query = "SELECT username FROM users WHERE ID = '$user_id'";
$test = mysqli_query($connect,$query);
$row2 = mysqli_fetch_array($test);
$user_name = $row2['username'];
$title2 = str_replace(" ","-",$title);
echo '<div class="row">
<div class="col-lg-12"><h3 class="para"><a class="para" href="http://news.red-sec.net/article/'.$article_id.'/'.$title2.'">'.$title.'</a></h3>
<p class="para">Written by: '.$user_name.'</p>
</div>
</div>';
}
echo '</div>
</div>
</div>';
}
?>
答案 0 :(得分:0)
假设css目录位于根目录中,请尝试此...
<link rel="stylesheet" type="text/css" href="/css/style1.css"/>
所以,这告诉浏览器查找根目录/
,然后查找其中的css目录。如果没有正斜杠,浏览器就会寻找相对链接,例如;试图在当前页面的目录中找到一个css目录,并且由于你重写了它们,它没有找到一个css目录。