简体   繁体   English

将PHP重定向到新窗口

[英]Redirect PHP to new window

I have a PHP file reports.php that has a form which when clicked submit goes to reports6.php. 我有一个PHP文件report.php,该文件具有一种形式,单击后提交即可进入reports6.php。

reports6.php has the code for mysql, if rows are not found it is redirected back to reports.php with the error code. report6.php具有mysql的代码,如果未找到行,则会将其重定向回带有错误代码的reports.php。

In reports6.php I am using to go to reports.php 在reports6.php中,我正在使用reports.php

header ("location: reports.php")

However if rows are found if sets some parameters and calls another php file (cpdf.php) to create the pdf from those parameters using header redirect again. 但是,如果找到行,则设置一些参数并调用另一个php文件(cpdf.php)以再次使用标头重定向从这些参数创建pdf。

What I want is when the user clicks submit from reports.php .. cpdf.php should open in new page. 我想要的是当用户单击reports.php中的Submit时。cpdf.php应该在新页面中打开。

if I use target="_blank" in reports.php while submitting form report6.php opens in another tab and pdf gets generated but if there are no rows reports.php is opened in another tab saying "no rows found". 如果我在提交表单时在reports.php中使用target =“ _ blank”,则report6.php将在另一个选项卡中打开并生成pdf,但是如果没有行,则report.php将在另一个选项卡中打开,提示“未找到行”。

If i dont use _blank in reports.php and use javascript in reports6.php to open the cpdf.php and header redirect to reports.php it doesn't work (i have given allow pop-ups but I dont know why the cpdf.php won't open).. 如果我不使用reports.php中的_blank并在reports6.php中使用javascript打开cpdf.php,并将标头重定向到reports.php,则它不起作用(我给出了允许弹出窗口,但我不知道为什么使用cpdf。 php将无法打开)。

If i give some output in reports6.php like "echo me;" 如果我在report6.php中提供一些输出,例如“ echo me;” then the pdf opens fine.. i suppose that has to do with the sequence of php and the or something. 然后pdf打开正常..我想这与php和the之类的东西有关。

As i searched other previously asked questions there is no way to use header and open in new tab in php.. 当我搜索其他先前询问的问题时,无法使用标头并在php中的新标签页中打开。

So what can I do in this case? 那么在这种情况下我该怎么办?

Thanks. 谢谢。

edit: 编辑:

Here is the relevant code: 以下是相关代码:

Reports.php Reports.php

<form name="report6" action="report6.php" onsubmit="return check_digit('report6','system_id',' System ID ')"method="post">
        <td><b>Print old Invoice by System ID: </b></td>
        <td><input type="text" name="system_id" ></td>
        <td><input type="submit" name="Run" value="Run"></td>
</form>

Reports6.php Reports6.php

$sql=blah blah blah
if ( $row_cnt == 0 ) 
    { 
        $mysqloutput="No such System ID in the Database";
        $_SESSION["mysqloutput"]=$mysqloutput; 
        mysqli_close($con);
        die(header ("location: reports.php"));
    }
else
{ header ("location: cpdf.php"); }

cpdf.php cpdf.php

//The code to generate the pdf //生成pdf的代码

What I have tried: 我试过的

1) Add target="_blank" in reports.php 1)在report.php中添加target =“ _ blank”

2) Add <script type="text/javascript" language="Javascript">window.open("cpdf.php")</script> in reports6.php 2)在report6.php中添加<script type="text/javascript" language="Javascript">window.open("cpdf.php")</script>

What I want: 我想要的是:

cpdf.php opens in new tab when form is submitted from reports.php if rows are there 如果从那里提交报表,则从reports.php提交表单时,cpdf.php将在新选项卡中打开

if not redirects back to reports.php in the same tab only (not in another tab as I get it) 如果没有,则仅重定向到同一选项卡中的reports.php(在我得到的其他选项卡中不)

You cannot open a new window in PHP because it is server side scripting. 您无法在PHP中打开新窗口,因为它是服务器端脚本。 You could however add an indicator to your header location when you want it to be opened in a new window as so: 但是,当您希望在新窗口中打开标题时,可以将其添加到标题位置:

header("Location: reports.php?newwindow=true"); exit();

and on your reports.php file, you could pick that GET method up, and check if it is set, and force the window to be opened in a new window using javascript. 然后在您的reports.php文件中,您可以选择该GET方法,并检查是否设置了该方法,并使用javascript强制在新窗口中打开该窗口。

<?php if(isset($_GET['newwindow']) && $_GET['newwindow']=="true"){ ?>
<script>[... script that handles new window here ...]</script>
<?php } ?>

如果您想使用php打开一个新窗口,这里是正确的代码

echo "<script language=\"javascript\">window.open('cpdf.php',\"_blank\");</script>"; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM