2012-12-06 60 views
1

我有我的網站,但在我登錄後外部論壇登錄表單想用戶重定向回確切的網站頁面訪客在登錄前看着。重定向URL內的URL

的事情我使用:

<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"> 

誰會幫助我:)?

+1

顯示使用這個隱藏字段的代碼。 – Barmar

+0

我編輯了這個問題:) – user1860809

+0

你沒有顯示使用'重定向'字段的PHP代碼。如果只是將該值放在'Location:'標題中,那將不起作用;該標題包含一個URL,而不是Javascript。 – Barmar

回答

0

你可以按照下面的代碼:

<?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> 
+0

謝謝你的建議!我編輯了這個問題,但:) – user1860809