simao20 Posted May 26, 2006 Share Posted May 26, 2006 [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]<? phpfunction 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> </td> <td> <!-- end header and begin content --> <?php } // close myheader() function footer() { ?> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr></table></body></html><?php}?>[b]and the a file called index.php (code below[/b])<?phpinclude $_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 bestFernando Ribeiro Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/ Share on other sites More sharing options...
poirot Posted May 26, 2006 Share Posted May 26, 2006 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 Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-39109 Share on other sites More sharing options...
samshel Posted May 26, 2006 Share Posted May 26, 2006 Do you see anything when u "View Source" the index.php page in browser...if yes please paste it here.... Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-39129 Share on other sites More sharing options...
simao20 Posted May 26, 2006 Author Share Posted May 26, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-39141 Share on other sites More sharing options...
dixie Posted August 16, 2006 Share Posted August 16, 2006 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 Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75624 Share on other sites More sharing options...
king arthur Posted August 16, 2006 Share Posted August 16, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75631 Share on other sites More sharing options...
king arthur Posted August 16, 2006 Share Posted August 16, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75632 Share on other sites More sharing options...
dixie Posted August 16, 2006 Share Posted August 16, 2006 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 fileinclude $_SERVER['DOCUMENT_ROOT']. '/layout.php';// Use the myheader function from layout.phpmyheader("Welcome to My Website!");// Include the welcome html page.include $_SERVER['DOCUMENT_ROOT']. '/html/index_page.html'; // Include News Index Fileinclude $_SERVER['DOCUMENT_ROOT']. '/includes/news_index.php'; // Use the footer function from layout.phpfooter();?> Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75639 Share on other sites More sharing options...
Jenk Posted August 16, 2006 Share Posted August 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75641 Share on other sites More sharing options...
dixie Posted August 16, 2006 Share Posted August 16, 2006 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. ?? Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75644 Share on other sites More sharing options...
Jenk Posted August 16, 2006 Share Posted August 16, 2006 no, you can't have multiple docroots :)just move all your tutorial files into the docroot or modify them. Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75651 Share on other sites More sharing options...
dixie Posted August 16, 2006 Share Posted August 16, 2006 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'] Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-75669 Share on other sites More sharing options...
sammya Posted January 11, 2007 Share Posted January 11, 2007 [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:=====================================<?phpclass 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. Quote Link to comment https://forums.phpfreaks.com/topic/10472-simple-error/#findComment-157815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.