这是我当前使用的代码,在localhost上这个工作很好并且重定向,但是当我尝试在像altervista.org这样的免费网站上传时,这个没有重定向更多..为什么?
<?php
$p = $_GET['azione'];
// login.php?azione=login
if($p == "login"){
if(!isset($_POST['invia'])){ ?>
<div class="loginform">
<h3>Login!</h3>
<form class="form-horizontal" method="post" action="#" id="formlogin">
<div class="control-group">
<label class="control-label" for="username"></label>
<div class="controls">
<input type="text" placeholder="Username" name="username" id="username" /><br>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="password" placeholder="Password" name="password" id="password" /><br>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-large" name="invia" id="login" value="Accedi">
Sign in!
</button>
<br><br>
<a href='register.php'>Sign Up Now!</a> <br><br>
<a href='forgotpass.php'>Forgot Your Password?</a>
</div>
</div>
</form>
</div>
<?php } else {
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
if($username == "" || $password == ""){
echo "<div class='alert alert-error'>
<strong>Sorry!</strong> Complete all fields!
</div>";
header("Refresh: 2; URL= login.php?azione=login");
} else {
$password_cript = md5($password);
$recuperadati = mysql_query("SELECT * FROM utenti WHERE username = '$username' AND password = '$password_cript'");
$verificadati = mysql_num_rows($recuperadati);
if($verificadati == 1){
$sessione = mysql_fetch_array($recuperadati);
$_SESSION['utente'] = $sessione['username'];
$_SESSION['id_user_logged'] = $sessione['id'];
echo "<div class='alert alert-success'>
You are now logged in!
</div>";
header("Refresh: 2; URL= profile.php?username=".$_SESSION['utente']."");
} else {
echo "<div class='alert alert-error'>
<strong>Sorry!</strong> Username or Password not found!
<a href='login.php?azione=login'>Try again</a> or <a href='register.php'>Sign Up now</a>
</div>";
}
}
}
// login.php?azione=logout
} elseif ($p == "logout"){
session_destroy();
echo "<div class='alert alert-success'>
Logout!
</div>";
header("Refresh: 2; URL= index.php");
}
?>
刚刚添加了login.php的完整代码,也许它可以是最有帮助的
答案 0 :(得分:0)
除非在本地服务器上启用了输出缓冲,否则在使用标头功能之前回显输出不起作用。它可能在生产服务器上关闭。
试试这个:
if($verificadati == 1){
$sessione = mysql_fetch_array($recuperadati);
$_SESSION['utente'] = $sessione['username'];
$_SESSION['id_user_logged'] = $sessione['id'];
header("Refresh: 2; URL= profile.php?username=".$_SESSION['utente']."");
echo "<div class='alert alert-success'>
You are now logged in!
</div>";
} else {
echo "<div class='alert alert-error'>
<strong>Sorry!</strong> Username or Password not found!
<a href='login.php?azione=login'>Try again</a> or <a href='register.php'>Sign Up now</a>
</div>";
}
如你所见,你应该移动
echo "<div class='alert alert-success'>You are now logged in!</div>";
到您的目标网页。