Forum Moderators: coopster

Message Too Old, No Replies

Using PHP Includes

Can't seem to make it work like I thought it should

         

MatthewHSE

5:56 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, I don't know much about PHP but I thought I at least knew enough to use PHP includes. But, it appears that I don't.

I have a PHP script that generates an error page for my form processor. The script generates the page in the following manner:

print <<<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<title>Form Errors</title>

</head>

<body>

Error page content goes here.

</body>

</html>

EOF;

I want the error page thus generated to use the same header and footer as the rest of my site. The header and footer are .cgi files that I call with SSI on my HTML pages. But, I can't seem to get them included in the page generated by the above.

I tried creating a new header.html page with the only contents being the SSI to call my header.cgi file. Then, I tried to include header.html in the PHP code shown above. For some reason it didn't work; what might I be doing wrong?

Thanks,

Matthew

lorax

6:20 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you tried formatting the page and then printing it? Like this:

$page = "
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">\n\n

<html>

<head>

<title>Form Errors</title>

</head><body>".include("header.html")."

Error page content goes here.

".include("footer.html")."</body></html>";

print $page;

MatthewHSE

8:30 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I finally managed to get the header and footer in place, using the following code:

function display_errors($errors){
$errors = '<li>' . join('<li>', $errors);

print <<<EOF

<html>

<head>

<title>Form Errors</title>

EOF;

include 'http://mydomain.com/header.html';

print <<<EOF

<ul>$errors</ul>

EOF;

include 'http://mydomain.com/footer.html';

print <<<EOF

</body>

</html>

EOF;

}

The problem now is, on the error page, a warning message appears above the header and the footer, like this:

Warning: display_errors(): stream does not support seeking in /path/to/my/cgi-bin/formprocessor.php on line 378

Where line 378 is the line where my header include is placed. (Same error just above the footer, but a different line number.)

So now that I've got the header and footer on the page, how do I get rid of those warnings?

Thanks,

Matthew

DrDoc

8:38 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put an @ sign in front of include.

@include("filename.php");

MatthewHSE

9:59 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, that did it!