我为使用Indexhibit或Wordpress的客户做了一些网站。我不断收到来自他们的相同"我在哪里登录?"电子邮件,所以想在我的网站上创建一个简单的转发表单,客户可以在其中输入 URL,选择 Wordpress/Indexhibit 并单击转到并转发到那里的网站。
经过一些谷歌搜索,我构建了以下内容:
<?php if($_SERVER['REQUEST_METHOD'] == 'POST') : $siteid1 = $_POST['siteid1']; header('Location: http://' . $siteid1 . '/ndxz-studio/'); else:?>
<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post">
<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 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="siteid1" />
<input class="btn btn-success loginbuttons" type="submit" value="Go" />
</form>
<?php endif; ?>
然后对于Wordpress,在它的正下方也是如此。
但是因为我正在使用
<?php if($_SERVER['REQUEST_METHOD'] == 'POST') : $siteid1 = $_POST['siteid1']; header('Location: http://' . $siteid1 . '/ndxz-studio/'); else:?>
它似乎只接受网站上的一种形式。(所以要么 indexhibit 无法转到/ndxz-studio,要么 WP 无法转到 WP-admin)
PHP不是我的强项,所以抱歉我犯了任何愚蠢的错误
这是因为:
<?php if($_SERVER['REQUEST_METHOD'] == 'POST') : $siteid1 = $_POST['siteid1'];
这在你的表格中总是正确的。所以,PHP 执行它。PHP 永远不会到达第二个if
语句,所以它永远不会执行。
尝试使用if else
语句,并确保您的表单名称是唯一的
编辑:
下面是一些示例代码,可帮助您入门。
if($_POST['siteid1']) {
$siteid1 = $_POST['siteid1'];
// execute code here
} elseif($_POST['siteid2']) {
$siteid1 = $_POST['siteid1'];
// Execute code here
}