我写了以下javascript代码,提示用户在访问页面之前输入密码。另外,我想在密码正确的情况下向要加载的页面发送网址。这是将另一个html页面的url发送到该页面的正确方法
function pagePassword(url)
{
var password;
var pass1="xxxxxx";
password=prompt('Please enter the page password:',' ');
if (password==pass1)
{
//code to send a url of another html page to the page which is going to load if the password entered by the user is correct
window.location="http://nano.uark.edu/nanophpscripts/xxxxxxx.php?pageurl="+url;
}
else {
alert('Wrong password!');
}
}
这是edit_backend.php页面的代码。该页面获取另一个html页面的URL并在文本框中打开它的源代码
$url=$_GET["pageurl"];
echo "<textarea name=\"content\" id= \"content\" cols=\"90\" rows=\"40\">";
$handle = fopen("$url","r");
while(!feof($handle))
{
$text = fgets($handle);
echo $text;
}
fclose($handle);
?>
echo "</textarea><br>";
答案 0 :(得分:1)
密码处理服务器端,而不是javascript。任何人都可以查看javascript并查看密码或他们要访问的页面。
答案 1 :(得分:1)
好吧,你必须在javascript中转义网址 - 可能是:
"http://........?pageurl="+escape(url);
在php脚本中:
$prevpagename=htmlspecialchars(urldecode($_GET["pageurl"]));
可能应该有用。
当然,正如上面提到的那样,在客户端比较您的密码并不是一件明智的事情。
答案 2 :(得分:0)
首先,您不应该在Javascript中保留任何敏感数据,任何人都可以在其中查看源代码。您需要使用PHP处理登录。
其次,只是为了好玩,我将你的window.location链接剪切并粘贴到我的浏览器中,并在3分钟内能够查看你的php文件中的所有源代码,包括你的数据库登录详细信息,就在你的小应用程序中
你可能不想让这种情况发生......