Jump to content

Recommended Posts

[b]I'm reading a book called "creating interactive websites with PHP and web services", i've got to a part where the book tells me to write a php file called layout.php (code below)[/b]

<? php
function myheader($ptitle)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
</head>
<body>
<table width="100%" border="2" cellspacing="0" cellpadding="0" bordercolor="#000000">
<tr>
<td colspan="3"><img src="pic/logo.jpg" width="150" height="112" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<!-- end header and begin content -->

<?php
}

// close myheader()
function footer()
{
?>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>
<?php
}
?>

[b]and the a file called index.php (code below[/b])


<?php

include $_SERVER['DOCUMENT_ROOT'].
'/layout.php';

myheader("Welcome to my Website!");

echo "Welcome to my Website!";

footer();

?>

------------------------------

i understand what it's purpose, but the problem is that i get a blank screen when i run index.php. Can someone help me please.

all the best
Fernando Ribeiro
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/
Share on other sites

Well, I can't tell what is the problem.

IF it failed to include "layout.php"
it should throw an error (fatal error: called to undefined function myheader...).

I also can't understand it's purpose... The argument passed ($ptitle) is not used...
I think the purpose is to waste some resources by increasing the overhead calling unnecessary functions.

PS: Sinceramente, que treco horroroso! De onde vocĂȘ tirou isso?
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-39109
Share on other sites

[!--quoteo(post=377225:date=May 26 2006, 06:11 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 26 2006, 06:11 AM) [snapback]377225[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Well, I can't tell what is the problem.

IF it failed to include "layout.php"
it should throw an error (fatal error: called to undefined function myheader...).

I also can't understand it's purpose... The argument passed ($ptitle) is not used...
I think the purpose is to waste some resources by increasing the overhead calling unnecessary functions.

PS: Sinceramente, que treco horroroso! De onde vocĂȘ tirou isso?
[/quote]


This is the beginning of the example, just to show how it works, then it gets more complicated...

Tirei isso de um livro que o criador de phpfreaks escreveu [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

[!--quoteo(post=377245:date=May 26 2006, 09:04 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ May 26 2006, 09:04 AM) [snapback]377245[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Do you see anything when u "View Source" the index.php page in browser...if yes please paste it here....
[/quote]

nothing, a complete blank screen.
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-39141
Share on other sites

  • 2 months later...
I have the same blank screen and I downloaded the files from Sybex. All my other PHP scripts work fine.

Source code of blank page is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>

This is the second book and none of the source code actually works (carp)
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75624
Share on other sites

[quote author=dixie link=topic=94275.msg416752#msg416752 date=1155728484]
I have the same blank screen and I downloaded the files from Sybex. All my other PHP scripts work fine.

Source code of blank page is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>

This is the second book and none of the source code actually works (carp)
[/quote]

That's not the same script, since the doctype is completely different.
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75631
Share on other sites

[quote author=simao20 link=topic=94275.msg377257#msg377257 date=1148635199]
nothing, a complete blank screen.
[/quote]

If that's the case it is probably not actually including layout.php at all but you are not seeing the errors.

I do believe the line should be
[code]
include($_SERVER['DOCUMENT_ROOT'] . '/layout.php');
[/code]

Try that and also have a look at the error settings in your php.ini file.
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75632
Share on other sites

Thats not the script its the output of the script.
This is the script and I think the problem is the include $_SERVER['DOCUMENT_ROOT'] as my files are not in my htdocs root but deeper in the directory structure. However I don't know how to fix it without re-writing every file ;-( even then I don't know if I am right.

<?php
// include the layout file
include $_SERVER['DOCUMENT_ROOT'].
  '/layout.php';

// Use the myheader function from layout.php
myheader("Welcome to My Website!");

// Include the welcome html page.
include $_SERVER['DOCUMENT_ROOT'].
  '/html/index_page.html';
 
// Include News Index File
include $_SERVER['DOCUMENT_ROOT'].
  '/includes/news_index.php';
 
// Use the footer function from layout.php
footer();
?>
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75639
Share on other sites

you'll need to either change your document root directive in httpd.conf and php.ini or change all the files.. choice is yours.

and re: include syntax:
[code]<?php include_once '<file>'; ?>[/code] is the correct syntax as mentioned in the php manual. It's a construct, not a function.[/code]
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75641
Share on other sites

  • 4 months later...
[quote author=dixie link=topic=94275.msg416752#msg416752 date=1155728484]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>

[/quote]

I've got exactly the same problem, and I don't think the problem is that layout.php is not included. This part actually works until you include the Meta class to the layout.php and call it (I'm following the book step by step, writing the code myself, so not using the code available for download, and yes I did update the errors reported in errata).

I first thought the problem lay within the clsMetaContent.php, as it seems to fill in some meta data (see the <META tag in the quote above), but then I reduced the code to something very basic like this:

=====================================
<?php
class Meta{

function metadata($ptitle){
$meta = "<TITLE>TEST</TITLE>\n";
return $meta;
}
}
?>
=====================================

Then I uploaded the new code & had a look at the source again (from within internet explorer) and guess what: I had identically the same source code. This means the META tag does not come from the Meta class!

I don't know how to proceed now, so if anyone has found a solution in the mean time, I'd be happy to hear it.
Link to comment
https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-157815
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.