![](/img/trans.png)
[英]in PHP 5.3.3 how can a “per server” or “per instance” or “per website” variable be defined and used?
[英]Changing the address of the website, as per the php being used
我的abc.html页面中有一个按钮<input type="button" onclick="javafun();">
单击它会转到javascript,这会将信息进一步发送到我的abc.php ...,而javascript函数如下所示:
function login()
{
xmlhttp=GetXmlHttpObject();
//alert("pass");
if(xmlhttp==null)
{
alert("Your browser does not support AJAX!");
return;
}
var url="login.php";
url=url+"?id="+username+"&passwrd="+passwrd;
xmlhttp.onreadystatechange=statechangedLogin;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
}
function statechangedLogin()
{
//alert(xmlhttp.readyState);
if(xmlhttp.responseText=="<font color='red'>Your User Name or Password is incorrect. Please try again.</font>")
{
document.getElementById("response").innerHTML=xmlhttp.responseText;
}
else
{
//hwin=window.location="http://forum.research.bell-labs.com/zeeshan/qotw/login.php";
document.getElementById("mainbody").innerHTML=xmlhttp.responseText;
//hwin.document.innerHTML=xmlhttp.responseText;
//alert();
}
}
一切正常,但在地址栏中的网站地址保持不变: http : //severname.com/abc.html
我想这个地址栏改变,根据PHP。 它应该来到... http://severname.com/abc.html/login.php
但仍不应显示?id=username&passwrd=passwrd
这有可能吗?
Zeeshan
将请求发布到../login.php吗?
而不是使用ajax,将表单元素包装在
<form method=POST action="login.php">
User Name: <input name="username"><br>
Password: <input name="passwrd" type="password"><br>
<input type="submit" name="Login">
</form>
如果要更改地址栏,为什么要使用AJAX?
编辑向表单添加实数值
编辑2更清楚。
您确实应该通过表单登录(请参阅@nathans帖子)。
如果登录成功:
$failMsg = urlencode("Logged in successfully") header("Location: loginForm.php?okMsg=$msg&redirect=home.php");
如果登录失败:
$failMsg = urlencode("Failed to login") header("Location: loginForm.php?failMsg=$msg");
在您现在显示错误消息的loginForm.php中,输入:
<? echo htmlentities($_REQUEST['failMsg']);?>
在显示成功的loginForm.php中,将登录消息放入
<? echo htmlentities($_REQUEST['okMsg']);?>
并放在头部标签中
<? if(array_key_exists($_REQUEST,'redirect')) { echo "<meta http-equiv='refresh" content='5;url=/".$_REQUEST['redirect']."' />"; } ?>
没有JavaScript,用户会收到漂亮的错误消息,并在登录后转发到主页。
<form method="post" action="login.php">
您根本不需要AJAX。 如果您使用Java onSubmit="return my_validation_function()
来验证输入,则可以添加onSubmit="return my_validation_function()
...如果一切正常,您的验证函数应返回true;否则,则返回false(假返回值将停止该表单从提交)
听起来您根本不需要AJAX,只是常规格式,除非我遗漏了一些东西。
我认为您误解了AJAX的全部内容。 Ajax应该在后台运行,即不更改URL。 如果需要,请尝试document.location =“ foobar”;
Ajax隐藏与服务器的JS交互。 那是为了什么 如果您希望浏览器指向某个URL,则不应使用Ajax。 您想要归档的东西可以使用简单的POST请求(使用旧的<form>
轻松实现。 HTTP POST请求从URL隐藏请求的参数,并将其传递到消息本身的标头中。 因此,URL可以是干净的。
正如其他评论者所谈到的那样,真正的答案是,您不能更改网页的URL(“#”片段标识符除外,但对您没有用),而不会导致浏览器向其发送请求。网址。
如果您要通过AJAX提交,则不想麻烦尝试更改URL。 或者,您可以按照其他评论的建议进行发帖请求。
<form method="post" action="login.php">
您的方法有些不安全,容易受到某些脚本攻击。 我会考虑不进行Ajax登录,而仅使用常规形式。 这篇文章帮助了我很多:
http://www.evolt.org/PHP-Login-System-with-Admin-Features
Evolt的另一个外观与您要完成的相似,但我尚未阅读-只是Google的“ evolt ajax登录”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.