我做了网站登录使用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