2017-05-31 48 views
-2

我有一個PHP帳戶的網站。我想寫一個「profile.php/user」的CSS(例如:profile.php/benjamin)。我試圖把這一行在profile.php:個人頁面的CSS PHP

<link rel="stylesheet" type="text/css" href="profile.css"> 

但顯然不起作用。

profile.php

<?php 
session_start(); 

if($_SESSION['logged'] == true){ 
    $username = $_SESSION['login_username'] ; 
    $username = strtoupper($username); //il facem uppercase 
    echo "Welcome ".$username; 
    echo "</br>Press here to go to the home page"; 
    echo "</br>Click <a href='/logout.php'> here </a> to log out."; 
} 
else { 
echo " </br></br></br>You must login first to see this section "; 
header("refresh:4;url=/index.php"); 
} 
?> 

<html> 
<head> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!--scalare pagina in functie de dispozitiv --> 
    <link rel="stylesheet" type="text/css" href="profile.css"> 
<html> 

<body> 


<div class = "top_band"></div> 
</body> 
</html> 
+4

解釋'顯然不起作用'。向我們展示'profile.php'中的完整代碼 – Kishor

+0

另外,什麼不起作用?瀏覽器的Devtools中是否有任何錯誤?我們需要更多信息來幫助你。 – theiNaD

回答

0

假設CSS文件在同一目錄中的腳本,它應該是:

<link rel="stylesheet" type="text/css" href="../profile.css"> 

這是因爲據瀏覽器而言,profile.php/是URL中的一個目錄。要回到同一級別,您必須在URL中使用../

瀏覽器不知道任何關於實際文件位置的信息,以及URL的哪些部分是目錄,文件名和參數,它只是對文本進行解析。 /只是簡單地分離目錄級別,並且../在解析相對URL時刪除了尾隨目錄級別。