在同一页面上重定向到x/y URL的两个PHP表单
我正在尝试为使用Wordpress或Indexhibit管理这些站点的客户创建一个“简单”重定向 我已经设置好了它,允许他们输入自己的域,并将其重定向到相应的管理区域(我很惊讶有多少人忘记了,但这是我的解决方案) 我让它在一个重定向中工作得很好,但是在上一次提交的基础上,它尝试使用if/elseif来集成两者,但解析失败 任何关于我做错了什么的想法/非常感谢我的帮助在同一页面上重定向到x/y URL的两个PHP表单,php,forms,url,redirect,if-statement,Php,Forms,Url,Redirect,If Statement,我正在尝试为使用Wordpress或Indexhibit管理这些站点的客户创建一个“简单”重定向 我已经设置好了它,允许他们输入自己的域,并将其重定向到相应的管理区域(我很惊讶有多少人忘记了,但这是我的解决方案) 我让它在一个重定向中工作得很好,但是在上一次提交的基础上,它尝试使用if/elseif来集成两者,但解析失败 任何关于我做错了什么的想法/非常感谢我的帮助 <?php if ($_POST['indexhibit_url']) { if($_SERVER['REQUEST_ME
<?php
if ($_POST['indexhibit_url']) {
if($_SERVER['REQUEST_METHOD'] == 'POST') : $indexhibit_url = $_POST['indexhibit_url']; header('Location: http://' . $indexhibit_url . '/ndxz-studio/');
}
elseif ($_POST['wordpress_url']) {
if($_SERVER['REQUEST_METHOD'] == 'POST') : $wordpress_url = $_POST['wordpress_url']; header('Location: http://' . $wordpress_url . '/wp-admin/');
}
?>
<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post" name="indexhibit_url">
<h3>Indexhibit</h3>
<p class='formp'>If your website is powered by <em>Indexhibit</em> submit your URL to be forwarded to your admin area</p>
<input class='loginforms' type="text" value='i.e. your-domain-name.com' onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'i.e. your-domain-name.com':this.value;" name="indexhibit_url" />
<input class="btn btn-info loginbuttons" name="index_submit" type="submit" value="Go" />
</form>
<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post" name="wordpress_url">
<h3 style='margin-top:2em;'>Wordpress</h3>
<p class='formp'>If your website is powered by <em>Wordpress</em> submit your URL to be forwarded to your admin area</p>
<input class='loginforms' type="text" value='i.e. your-domain-name.com' onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'i.e. your-domain-name.com':this.value;" name="wordpress_url" />
<input class="btn btn-info loginbuttons" name="wp_submit" type="submit" value="Go" />
</form>
<?php endif; ?>
您正在混合三元运算符和非三元运算符:
只需使用正常的if/else语法:
if ($_POST['indexhibit_url']) {
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$indexhibit_url = $_POST['indexhibit_url'];
header('Location: http://' . $indexhibit_url . '/ndxz-studio/');
}
}elseif ($_POST['wordpress_url']) {
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$wordpress_url = $_POST['wordpress_url'];
header('Location: http://' . $wordpress_url . '/wp-admin/');
}
}
请记住,像这样使用PHP_SELF会使您的代码容易受到xss注入的攻击Perfect!是的,我是PHP新手,所以我仍然犯了很多错误。但这(再加上从代码末尾删除)使其工作得非常完美。许多人都感谢您应该使用netbeans、eclipse等IDE进行开发,以避免语法错误。