sgt_johnny
sgt_johnny

Reputation: 329

Execute a PHP page and store in a variable?

Im using a simple pdf creater for php, basically its:

<?php
$html = "test";
inclued("MPDF57/mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>

If i run this, a pdf opens up with the text "test" in it.

Now my problem is, i want to out put a whole site, so im doing something like this on a separate file, its named printx.php. In side de file is code like this

<?php
$ID=$_GET['ID'];
$result=mysqli_query($link,"SELECT * FROM table WHERE ID = '$id');
?>
<html>
<table><tr><td>
<?php var_dump($result);?>
</td></tr></table>
</html>

there is a lot more, but it doesnt matter here, because if i call the site it self by 10.0.0.99/printx.php?ID=13 it works fine

if i do the following

 <?php
$html = require("printx.php?ID=13");
inclued("MPDF57/mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>

An empty site gets created as PDF

Why? What is the reason that the site does not got go into the pdf?

Upvotes: 0

Views: 308

Answers (1)

CarCzar
CarCzar

Reputation: 150

use $html = file_get_contents("printx.php?ID=13");

instead of $html = require("printx.php?ID=13");

Hmmm... file_get contents may require the full url so file_get_contents("http://10.0.0.99/printx.php?ID=13");

Upvotes: 2

Related Questions