在JS中使用PHP进行$redirectlocation和$_职位
Using PHP within JS for $redirectlocation and .$_POST
我看了看,我的调整不起作用(noob),但我试过了!
我在一个安全端口上为cPanel Webmail进行了自定义登录,并希望在自定义登录页面上填充错误消息,而不是重定向到默认端口通用登录页面。
以下是我发现的代码,除了我使用Wordpress并遇到标头已发送错误外,它应该可以完美工作。我试图包含plugble.php,因为它与我过去为Wordpress管理区域编写的插件一起使用,但我无法在公共前端解决错误。
Username: <input type="text" name="user" value="" size="20" /><br />
Password: <input type="password" name="pass" value="" size="20" /><br />
<div style="display:none">
<input type="text" name="domain" value="emajenweb.webserversystems.com"/>
<select name="port">
<option selected="selected" value="2096"></option>
</select>
</div>
<?php
if($_POST['domain'] && $_POST['user'] && $_POST['pass'] && !($_GET['failed'] == "1")) {
$port = $_POST['port']; // sets the port number to login to
// Get the protocol to use for this connection
switch($port) {
case '2096': // Secure Webmail
$protocol = 'https://';
break;
}
// Build the URL
$redirectlocation = $protocol.$_POST['domain'].':'.$port.'/login/?user='.$_POST['username'].'&pass='.$_POST['pass'].'&failurl='.$_POST['failurl'];
header ("Location: ".$redirectlocation); // Send URL
} else {
$error = 1;
header ("Location: ".$_POST['failurl']); // Send URL if all neede information is not provided
}
?>
我遇到问题的代码是:
header ("Location: ".$redirectlocation); // Send URL
} else {
$error = 1;
header ("Location: ".$_POST['failurl']); // Send URL if all neede information is not provided
考虑到标头已经发送错误,我希望将标头位置值更改为javascript,但我失败了。。。
我的表单正在运行,但在自定义登录页面上传播的失败消息并没有达到要求。
Webmail登录
已经发送的错误标头是一个非常常见的错误。这是由…嗯。。。标头已发送。当您向服务器发送响应时,会发送标头。在您的情况下,它是:
Username: <input type="text" name="user" value="" size="20" /><br />
Password: <input type="password" name="pass" value="" size="20" /><br />
<div style="display:none">
<input type="text" name="domain" value="emajenweb.webserversystems.com"/>
<select name="port">
<option selected="selected" value="2096"></option>
</select>
</div>
所以。。。如何解决这个问题?非常简单。只需在发送响应之前移动处理脚本:
<?php
if($_POST['domain'] && $_POST['user'] && $_POST['pass'] && !($_GET['failed'] == "1")) {
$port = $_POST['port']; // sets the port number to login to
// Get the protocol to use for this connection
switch($port) {
case '2096': // Secure Webmail
$protocol = 'https://';
break;
}
// Build the URL
$redirectlocation = $protocol.$_POST['domain'].':'.$port.'/login/?user='.$_POST['username'].'&pass='.$_POST['pass'].'&failurl='.$_POST['failurl'];
header ("Location: ".$redirectlocation); // Send URL
} else {
$error = 1;
header ("Location: ".$_POST['failurl']); // Send URL if all neede information is not provided
}
?>
Username: <input type="text" name="user" value="" size="20" /><br />
Password: <input type="password" name="pass" value="" size="20" /><br />
<div style="display:none">
<input type="text" name="domain" value="emajenweb.webserversystems.com"/>
<select name="port">
<option selected="selected" value="2096"></option>
</select>
</div>
您应该参考这个SO线程了解更多信息:如何修复";标头已发送";PHP 中的错误
相关文章:
- 没有找到相关文章