0

设置:

当我遇到一些我不太理解的东西时,我正在对这个页面的后端进行逆向工程以获取乐趣和练习:

单击注册时,/js/login.js 中的 AttemptRegister() 会进行初始输入验证,检查所有字段是否为空,包含默认值,并确保密码匹配。

function AttemptRegister() {
 // Simple validation of input fields first
 var status=document.getElementById("regstatus");
 status.style.color='#000000';
 status.value = "";

 var username = document.getElementById("username");
 var email = document.getElementById("email");
var password = document.getElementById("password");
var confirmPassword = document.getElementById("confirmPassword");

if(""==username.value || "user name"==username.value) {
    status.style.color='#C00000';
    status.value = "Invalid user name";
    username.selected = true;
    return;
}
if(""==email.value || "email" == email.value) {
    status.style.color='#C00000';
    status.value = "Invalid email address";
    email.selected = true;
    return;
}
if(""==password.value || "password" == password.value) {
    status.style.color='#C00000';
    status.value = "Must provide password";
    password.selected = true;
    return;
}
if(password.value!=confirmPassword.value ) {
    status.style.color='#C00000';
    status.value = "Passwords do not match";
    password.selected = true;
    return;
}

// We open the thankyou page for registering, as that's where the actual registration occurs on the POST variables.  If they fail, we'll get kicked back here
status.value = "Submitting...";
//window.location.href='thankyou_reg.html';

// Submit with hidden form
var form = document.getElementById("submitEmail").form;
document.getElementById("submitEmail").value = email.value;
document.getElementById("submitUsername").value = username.value;
document.getElementById("submitPassword").value = password.value;
form.submit();

}

它将html中的“regstatus”字段设置为“Submitting...”并填写下面隐藏的html表单并将其提交给thankyou_reg.html?

<form action="thankyou_reg.html" method="post">
    <input type="hidden" name="submitEmail" id="submitEmail" value=""/>
    <input type="hidden" name="submitUsername" id="submitUsername" value=""/>
    <input type="hidden" name="submitPassword" id="submitPassword" value=""/>
    <input type="hidden" name="registerSubmit" id="registerSubmit" value="true"/>
</form>

这就是我困惑的地方,表单数据如何由平面 .html 页面处理?它进行二次验证检查以确保用户名和密码足够长,电子邮件格式正确,并查询数据库以确保此电子邮件或用户名尚未使用。如果其中任何一个失败,它会弹回 index.html 页面并再次使用错误消息更新“regstatus”输入字段。

问题:

我在这里想念什么?PHP 或服务器设置中是否有办法转移表单操作,在这种情况下为“thankyou_reg.html”,并将其重定向到 php 页面?然后在成功时加载“thankyou_reg.html”或在失败时返回“index.html”,使用将执行“regstatus”值更改的javascript?

4

2 回答 2

0

在 .htaccess 文件中,可以更改设置以在扩展名为 .html 的文件中运行 PHP 代码。您使用的网站可能将其更改为运行 PHP。

http://php.about.com/od/advancedphp/p/html_php.htm

于 2013-07-25T17:33:14.457 回答
0

Apache 和其他服务器有多种方法可以指定应为特定文件扩展名加载的应用程序。例如,.php扩展表示应该加载 PHP 并应该处理请求。我的想法是.html扩展实际上是由服务器应用程序(可能是 PHP)处理的,但他们本可以这样做来混淆在后台进行处理的内容。

可能存在映射thankyou_reg.html到 php 页面的重写规则。例如,将它映射到类似的东西可能会很好,它可以index.php?forward=thankyou_reg.html为您提供更漂亮的面向用户的 url。

thankyou_reg.html可能是一个目录,index.php里面有一个文件。

但实际上任何事情都可能在幕后发生。

于 2013-07-25T17:33:21.793 回答