【问题标题】:Redirect url inside url在 url 中重定向 url
【发布时间】:2012-11-24 10:36:16
【问题描述】:

我的网站上有一个外部论坛登录表单,但登录后我希望用户重定向回访问者在登录前查看的确切网站页面。

我用的东西:

<script>
function goBack()
{
window.history.go(-1)
}
</script>

<form action="./forum/ucp.php?mode=login" method="post">
<fieldset>
<label for="username">Name:</label><br>
<input type="text" name="username" id="username" size="20" class="input"><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password" size="20" class="input"><br>
<label for="autologin">Remember<input type="checkbox" name="autologin" id="autologin"></label><br>
<input type="hidden" name="redirect" value="goBack()">
<input type="submit" name="login" value="Log in" class="button">
</fieldset>
</form>

但是,浏览器会重定向到:

http://www.mysite.com/forum/goBack()?sid=87b53e6ecb0ae9062a3a9b930

我只设法重定向到我网站的索引:

value="http://www.wow.com">

谁来帮帮我:)?

【问题讨论】:

  • 显示使用此隐藏字段的代码。
  • 我编辑了问题:)
  • 您没有显示使用redirect 字段的PHP 代码。如果只是将值放在Location: 标头中,那将行不通;该标头包含一个 URL,而不是 Javascript。

标签: url redirect history back


【解决方案1】:

您可以按照以下代码:

<?php
//perform your post operations
if(isset($_POST['submit'])){
echo "<pre>";
print_r($_POST);
?>
<script>
window.history.go(-2); // -1 will post on the page from which it has been posted
</script>
<?php
    }
    ?>
    <html>
    <body>
    <form id="myForm" name="myForm" method="post">
    Name: <input type="text" name="name" id="fname">
    Email <input type="text" name="email" id="emailid">
    <input type="submit" name="submit" value="Submit" id="submit">
    </form>
    </body>
    </html>

【讨论】:

    猜你喜欢
    • 2018-12-15
    • 2016-06-27
    • 2012-04-19
    • 2013-04-30
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 2016-06-01
    相关资源
    最近更新 更多