2013-11-01 49 views
-1

我一直致力於保護服務器上的某些頁面。我能夠創建一個登錄屏幕和全部,並且工作完美。之後,我決定通過添加一些CSS(背景,水平中心對齊等)來增加它。在此之後,出於某種原因,即使在我登錄我的登錄信息之後,以前沒有任何內容正在處理,我可以在登錄後看到頁面的其餘部分。添加CSS後PHP文檔停止工作

我實現我的登錄的方式是,我創建了一個名爲login.php的頁面,我也有index.php,這是我試圖訪問的頁面。在index.php中,我首先使用require來始終訪問login.php。我也有theme.css讓事情看起來更好。

我不明白的是,它是如何工作的,但現在突然間它停止工作。在登錄頁面工作後,我甚至沒有碰到除CSS文件之外的任何東西。

這裏是我的代碼:

的index.php

<?php 
    require('login.php'); 
?> 

<?php 
    require('session.php'); 
?> 

<html> 
    <head> 
     <title>Protected Page</title> 
     <link rel="stylesheet" href="css/theme.css" type="text/css"> 
    </head> 
    <body> 
     <form enctype="multipart/form-data" action="add.php" method="POST"> 
      Name: <input type="text" name="name"><br> 
      E-mail: <input type="text" name = "email"><br> 
      Phone: <input type="text" name = "phone"><br> 
      Photo: <input type="file" name="photo"><br> 
      <input type="submit" value="Add"> 
     </form> 
     <table> 
      <tr> 
       <td><form method="post"><input type="submit" name="submit" value="Check Status"></form></td> 
       <td><form action="logout.php" method="post"><input type="submit" name="submit" value="Logout"></form></td> 
      </tr> 
     </table> 
    </body> 
</html> 

的login.php

<?php 
    ## put sha1() encrypted password here - example is 'hello' 
    $password1 = '43b1c8633e86765546bb1f44c4d654ed223fa064'; 
    ## username dictionary 
    $uname1 = 'ismail'; 

    session_start(); 

    if (!isset($_SESSION['logged'])) 
    { 
     $_SESSION['logged'] = false; 
    } 

    if (isset($_POST['password'])) 
    { 
     if ((sha1($_POST['password']) == $password1) && ($_POST['username'] == $uname1)) 
     { 
      $_SESSION['logged'] = true; 
      $user = $_POST['username']; 
      $pwd = $_POST['password']; 
     } 
     else 
     { 
      die ('Incorrect password'); 
      session_destroy(); 
     } 
    } 

    if (!$_SESSION['logged']): 
?> 

<html> 
    <head> 
     <title>Login</title> 
     <link rel="stylesheet" href="css/theme.css" type="text/css"> 
    </head> 

    <body> 

    <div class="container"> 
     <div class="vcenter"> 
     <div id="box-login"> 
      <img src="images/logo1.jpg" alt="PT BPI Logo" height="120px" class="center"> 
      <br /> 
      <table class="center"> 
       <form method="post"> 
       <tr> 
        <td>Username:</td> 
        <td><input type="text" name="username"></td> 
       </tr> 
       <tr> 
        <td>Password:</td> 
        <td><input type="password" name="password"></td> 
       </tr> 
       </form> 
      </table> 
      <input type="submit" name="submit" value="Login"> 
     </div> 
     </div> 
    </div> 

    </body> 
</html> 

<?php 
    exit(); 
    endif; 
?> 

theme.css

/* 
    AUTHOR: Ismail Fadillah Adiputra 
    VERSION: 1.0 | 20131030 
*/ 

/* general */ 
body { 
    margin:0; 
    padding:0; 
    background: -webkit-radial-gradient(#EDEDED, #9AC1DB); /* Safari */ 
    background: -o-radial-gradient(#EDEDED, #9AC1DB); /* For Opera 11.1 to 12.0 */ 
    background: -moz-radial-gradient(#EDEDED, #9AC1DB); /* For Firefox 3.6 to 15 */ 
    background: radial-gradient(#EDEDED, #9AC1DB); /* Standard syntax */ 
    } 
h1, h2, h3, h4, h5, h6 { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; text-transform:uppercase; font-weight:normal; text-align:center; } 
h1 { font-size:3em; margin:0; } 
h2 { font-size:3.4em; } 
p { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; font-size:13px; } 
a { border-bottom:1px dotted; } 
a:hover { border-bottom:1px solid; } 
input { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; font-size:13px; } 
td { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; font-size:13px; } 

/* Appearance of the box in the login page */ 
#box-login { 
    background:white; 
    padding:10px 0px 10px 0px; /* padding top, right, bottom, left (in order) */ 
    border-radius:5px; /* rounded corner */ 
    box-shadow: 5px 5px 10px #888888; /* shadow */ 
    margin:185px auto; /* horizontal align center */ 
    width:275px; 
    } 

.container { 
    position:relative; 
    width:100%; 
} 

.right { 
    position:absolute; 
    right:0px; 
    width:300px; 
    background-color:#b0e0e6; 
} 

/* 
.center { 
    margin:auto; 
    width:50%; 
} 
*/ 

.center { 
    /* center align the right way */ 
    float:none; 
    display:block; 
    margin:auto; 
} 

/* Changing the appearance of the input button */ 
input[type="submit"] { 
    float:none; 
    display:block; 
    margin:10px auto; 
    background:#EDEDED; 
    text-decoration:none; 
    font-family:'Tahoma'; 
    font-size:11px; 
    color:#656464; 
} 
input[type="submit"]:hover { 
    float:none; 
    display:block; 
    margin:10px auto; 
    background:#656464; 
    text-decoration:none; 
    font-family:'Tahoma'; 
    font-size:11px; 
    color:#EDEDED; 
} 

任何深入瞭解這個問題,你可以提供給我,我將不勝感激。請讓我知道,謝謝!

+4

沒有辦法,添加CSS可以更改腳本的行爲。就PHP而言,它只是純文本。 – Barmar

+0

你的意思是'沒有任何東西正在處理'?什麼是add.php和session.php的內容?你只是在談論login.php? – manonthemat

回答

1

在login.php中,您的</form>標記位於錯誤的位置。

的形式login.php中應編碼如下: -

<br /> 
    <form method="post">  <!-- moved! --> 
    <table class="center"> 
     <tr> 
      <td>Username:</td> 
      <td><input type="text" name="username"></td> 
     </tr> 
     <tr> 
      <td>Password:</td> 
      <td><input type="password" name="password"></td> 
     </tr> 
    </table> 
    <input type="submit" name="submit" value="Login"> 
    </form>     <!-- moved! --> 
0

有很多錯誤的代碼和頁面。 我解決了所有問題,並根據需要製作頁面,以便集成代碼。

更改頁面按照下面給出的代碼(不改變你的CSS和它的name.Your 「CSS」 的正常使用。):

的index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Login</title> 
<link rel="stylesheet" href="css/theme.css" type="text/css"> 
</head> 
<body> 
<div class="container"> 
    <div class="vcenter"> 
    <div id="box-login"> 
     <img src="images/logo1.jpg" alt="PT BPI Logo" height="120px" class="center"> 
     <br/> 
     <table class="center"> 
      <form action="aunthiticate.php" method="post"> 
      <tr> 
       <td>Username:</td> 
       <td><input type="text" name="username"></td> 
      </tr> 
      <tr> 
       <td>Password:</td> 
       <td><input type="password" name="password"></td> 
      </tr> 
      <tr><td colspan="2"> <input type="submit" name="submit" value="Login"></td></tr> 
      </form> 
     </table> 

    </div> 
    </div> 
</div> 


</body> 

的login.php

​​

aunthiticate.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
</head> 
<body> 
<?php 
## put sha1() encrypted password here - example is 'hello' 
$password1 = '43b1c8633e86765546bb1f44c4d654ed223fa064'; 
## username dictionary 
$uname1 = 'ismail'; 

session_start(); 

if (!isset($_SESSION['logged'])) 
{ 
    $_SESSION['logged'] = false; 
} 

if (isset($_POST['password'])) 
{ 
    if (($_POST['password'] == $password1) && ($_POST['username'] == $uname1)) 
    { 
     $_SESSION['logged'] = true; 
     $user = $_POST['username']; 
     $pwd = $_POST['password']; 
     header('location:login.php'); 
    } 
    else 
    { 
     die ('Incorrect password'); 
     session_destroy(); 
    } 
} 
?> 
</body> 
</html> 
<form enctype="multipart/form-data" action="add.php" method="POST"> 
     Name: <input type="text" name="name"><br> 
     E-mail: <input type="text" name = "email"><br> 
     Phone: <input type="text" name = "phone"><br> 
     Photo: <input type="file" name="photo"><br> 
     <input type="submit" value="Add"> 
    </form> 
    <table> 
     <tr> 
      <td><form method="post"><input type="submit" name="submit" value="Check Status"></form></td> 
      <td><form action="logout.php" method="post"><input type="submit" name="submit" value="Logout"></form></td> 
     </tr> 
    </table> 
</body>