Jump to content


Photo

simple error


  • Please log in to reply
12 replies to this topic

#1 simao20

simao20
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 26 May 2006 - 02:23 AM

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)

<? 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
}
?>

and the a file called index.php (code below)


<?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

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 26 May 2006 - 05:11 AM

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?
~ D Kuang

#3 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 26 May 2006 - 08:04 AM

Do you see anything when u "View Source" the index.php page in browser...if yes please paste it here....
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#4 simao20

simao20
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 26 May 2006 - 09:19 AM

[!--quoteo(post=377225:date=May 26 2006, 06:11 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 26 2006, 06:11 AM) View Post[/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) View Post[/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.

#5 dixie

dixie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 August 2006 - 11:41 AM

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)

#6 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 16 August 2006 - 12:05 PM

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)


That's not the same script, since the doctype is completely different.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#7 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 16 August 2006 - 12:12 PM

nothing, a complete blank screen.


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
include($_SERVER['DOCUMENT_ROOT'] . '/layout.php');

Try that and also have a look at the error settings in your php.ini file.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#8 dixie

dixie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 August 2006 - 12:28 PM

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();
?>

#9 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 16 August 2006 - 12:39 PM

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:
<?php include_once '<file>'; ?>
is the correct syntax as mentioned in the php manual. It's a construct, not a function.[/code]

#10 dixie

dixie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 August 2006 - 12:46 PM

My other PHP files will not work if I change the directive. Unless I can have more than one directive in php.ini or httpd.conf. ??

#11 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 16 August 2006 - 12:57 PM

no, you can't have multiple docroots :)

just move all your tutorial files into the docroot or modify them.

#12 dixie

dixie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 August 2006 - 01:31 PM

How do webservers with hundreds of website "roots" get round that then :-\
Assuming each of these websites on the same server can use $_SERVER['DOCUMENT_ROOT']

#13 sammya

sammya
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 11 January 2007 - 12:41 AM


<!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>


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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users