我做了網站登錄使用PHP和HTML。代碼:登錄網站和其他網站部分
<?php
session_start();
$user="root";
$host="localhost";
$password="";
$database="mb_dusnionys_login";
$usertable="nariai";
mysql_connect ($host, $user,$password) or die ("negalima");
mysql_select_db ($database)or die (mysql_error());
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$sql="SELECT * FROM {$usertable} WHERE username='{$myusername}' AND password='{$mypassword}'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION ["username"]=$myusername;
$_SESSION ["password"]=$mypassword;
$_SESSION ["userrecord"]=mysql_fetch_assoc($result);
header ("location: /nariu_turinys/index.html");
}
else {
echo "Netinkamas vartotojo vardas arba slaptažodis. Grįžkite atgal ir bandykite iš naujo";
}
我的網站的conseption:有一個與主鍵索引文件和登錄form.Button重定向沒有登錄其他索引文件和登錄窗體重定向到與用戶名和PASW的要求,第三個索引文件。在這個目錄是我的網站的主要部分。 當我使用登錄表單登錄網站時,一切都可以,但是如果我在網頁中進行復制並複製網址並粘貼到其他瀏覽器或其他選項卡中,則無需登錄即可訪問此部分。 問題是如何在沒有登錄的情況下使這些部件不可用?
您正在使用[一個** **過時數據庫API](http://stackoverflow.com/q/12859942/19068)和應該使用[現代替換](http://php.net/manual/en/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin 2013-04-22 13:44:04
不要存儲純文本密碼! [使用散列安全地存儲它們](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet)。 – Quentin 2013-04-22 13:47:22
你能告訴我這更詳細的,我該怎麼做? – user2290637 2013-04-22 14:13:05