打印PHP后重定向
我想重定向到一个页面,在用户点击打印和打印过程完成后。这能实现吗 这是我的简单代码打印PHP后重定向,php,printing,Php,Printing,我想重定向到一个页面,在用户点击打印和打印过程完成后。这能实现吗 这是我的简单代码 <?php include('include/conn.php'); $id = $_GET['id']; $sql = "select * from barcode where b_acc_no_code = '".$id."'"; $result = mysqli_query($conn,$sql); while($row = mysqli_fetch_assoc($result)){ $path
<?php
include('include/conn.php');
$id = $_GET['id'];
$sql = "select * from barcode where b_acc_no_code = '".$id."'";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
$path = $row['b_path'];
echo '<img src="'.$path.'.jpg" />';
echo '<script>window.print();</script>';
//header('location: barcode.php');
}
?>
如您所见,我对重定向代码进行了注释。提前感谢不幸的是,当您已经在网页上打印内容时,您不能使用标题功能。(标题必须在任何内容之前)这就是为什么不能这样做 解决方法是通过javascript重定向,如下所示:
echo '<script>self.location = "barcode.php";</script>';
echo'self.location=“barcode.php”;
您可以使用函数来检查是否可以使用header函数,但这只是一个计划问题。在您的代码中,使用JS可以解决问题。如果php已经输出了任何内容,那么header()
函数将不起作用。标题应在任何输出之前发送
你可以用
<meta http-equiv="refresh" content="5; url=http://yourdomain.com/path/to/barcode.php">
在加载完成后5秒钟内重定向的页面的HTML中
希望这有帮助 头应该首先定义,因为您没有使用输出缓冲区。我已经尝试过了,它就像一个符咒。简单而有效!谢谢