如何自动登录并加载其他页面。我可以自动登录,但我希望自动重定向到http://website.com/xxx.php
我使用了以下代码,自动登录正常工作但重定向页面
<form id="loginForm" name="loginForm" method="post" action="login_page_url">
<select name="uni_url" id="logServer" class="validate[required]">
<option class="" value="customer" fbUrl="" cookieName="">
</option>
</select>
<input id="edit-submitted-username" name="username" type="text" maxlength="128" value="username" class="" />
<input id="edit-submitted-password" class="form-text required" name="password" type="password" value="password" class="" />
<input type="hidden" id="loginKid" name="kid" value="" />
</form>
<script>
document.loginForm.submit();
</script>
答案 0 :(得分:0)
我们可以使用PHP处理登录。 Javascript在客户端执行,而PHP在服务器端执行。对于登录,服务器端的执行是有意义的。 为此,您可以声明您的表单:
<form action="./processLogin.php" method="post" name="loginForm">
然后在您所在的同一文件夹中创建文件processLogin.php
(因为我们在上面的代码中声明了这一点),其中包含以下代码:
<?php
session_start(); // if necessary
// retrieve username:
$user= $_REQUEST["username"]; // The REQUEST parameter is the value of the attribute 'name' of the 'input's of your form.
//In your declaration: '<input ... name="username" ...'
// retrieve the password as well:
$pass = $_REQUEST["password"]; //same as above
//check stuff (user exists, password is correct...)
//and at some point, if everything is OK :
header('Location: http://website.com/xxx.php');
exit;
//remember, these 2 lines come together
?>
答案 1 :(得分:0)
你可以试试javascript
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
但谷歌已经知道了。 : - (