该页面没有在PHP中正确重定向

时间:2015-08-01 07:01:53

标签: php firefox redirect header

当我使用非管理员用户登录时,它会收到我的错误

  

页面未正确重定向

这是login.php页面代码

<?php

require_once ('session.php');
if($_SESSION['userdetail'] !=FALSE){
    header('location: home.php');
            exit();
}
?>
<html>
<head><title>Login</title></head>
<body>
<form action="checklogin.php" method="post" enctype="multipart/form-data">
<table>
<tr><td>UserName:</td><td><input type="text" name="user_name"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" ></td></tr>

<tr><td colspan="2"><input type="submit" value="Submit"></td></tr>
</table>
</form> 

这是ckecklogin.php页面代码

<?php

if(!isset($_POST['user_name']) || !isset($_POST['password'])){
     header('location: login.php?log=error');
            exit();
}

if(empty($_POST['user_name']) || empty($_POST['password'])){
     header('location: login.php?log=error');
            exit();
}


require_once('includes/connection.php');
require_once('includes/book_functions.php');
require_once('includes/user_functions.php');
require_once ('session.php');

$user_name=$_POST['user_name'];
$user=  get_user_by_name($user_name);
db_close();
if(!$user){
    header('location: login.php?log=errusr');
            exit();
}
$password=$_POST['password'];
$user->passhash;
if (password_verify($password, $user->passhash)) {

    $_SESSION['userdetail']=$user;
    $_SESSION['userdetail']->passhash = NULL;
    header('location: home.php');
            exit();
}
else{
     header('location: login.php?log=errusr');
            exit();
}

它标题我home.php和firefox给我这个错误,这是如果我像普通用户登录但如果我登录我的管理员帐户我工作没有任何问题! 有什么问题?

2 个答案:

答案 0 :(得分:1)

在发送标题之前,您不应该有任何输出

坏:

    print_r($_SESSION['user_info']);
   header('location: home.php');

好:

   header('location: home.php');

坏:

echo $password=$_POST['password'];
echo $user->passhash;

好:

"emptyness"

答案 1 :(得分:0)

使用bitmap = android.provider.MediaStore.Images.Media .getBitmap(cr, selectedImage); imageView.setImageBitmap(bitmap); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); String encodedImageString = Base64.encodeToString(b, Base64.DEFAULT); byte[] bytarray = Base64.decode(encodedImageString, Base64.DEFAULT); Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0, bytarray.length); myDb.execSQL("INSERT INTO imgtbl VALUES('"+encodedImageString+"');"); Cursor c= myDb.rawQuery("SELECT * FROM imgtbl", null); c.moveToFirst(); String img=c.getString(0); byte[] byarray = Base64.decode(img, Base64.DEFAULT); Bitmap bmimg = BitmapFactory.decodeByteArray(byarray, 0, byarray.length); ImageView iv=(ImageView)findViewById(R.id.img2); ImageView iv1=(ImageView)findViewById(R.id.img3); iv.setImageBitmap(bmimg); iv1.setImageBitmap(bmimg); 删除标题错误也可以使用ob_clean或通过javascript重定向