2017-03-15 48 views
1

糾正登錄後這個簡單的PHP腳本後重定向頁面,配置超鏈接http://www.mysite.it頁 我如何可以改變腳本,以便如果登錄是正確的,你直接打開鏈接http://www.mysite.it的登錄在PHP

<?php 
session_start(); 
$username = $_POST['username']; 
$password = $_POST['pw']; 

if($username == "" or $password == ""){ 
echo "Non puoi accedere senza Username o password"; 
}else if($username == "" and $password == ""){ 
echo "Non puoi accedere senza Username e password"; 
}else{ 
// configure your username and password 
if($username == "test" AND $password == "test"){ 
echo "Benvenuto $username"; 
echo "<a href='http://www.mysite.it'>Vai alla pagina</a>"; 
}else{ 
echo "Accesso negato, questo username non esiste"; 
} 
} 

function loggeduser($username){ 

} 


?> 
+0

你需要使用頭重定向和它的解釋很好這裏http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php – Achayan

回答

0

您可以使用函數來執行重定向:

function redirectTo($newUrl) 
{ 
     header("Location: " . $newUrl); 
     exit(); 
} 

並在代碼:

if($username == "test" AND $password == "test"){ 
    redirectTo("http://www.mysite.it");  
}else{ 
... 
} 
0

頁眉必須首先聲明頁眉。或者它會顯示錯誤,如已經聲明的頭文件。

echo '<script type="text/javascript"> 
      window.location = "www.xyz.com" 
     </script>'; 

改爲使用它。