Page 1 of 1

template error

Posted: Thu Jul 14, 2011 12:13 pm
by BLACKMASK
ok im not exactly new to php but it has been a couple of years since i created a website. back then what i did was make a layout and use a php code to insert html documents.

the code i usually use

<?php include ("$page")?>

when i put the code in i get an error

Warning: include() [function.include]: Filename cannot be empty in /home/midwes44/public_html/mmh.php on line 74

Warning: include() [function.include]: Filename cannot be empty in /home/midwes44/public_html/mmh.php on line 74

Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/midwes44/public_html/mmh.php on line 74

the link i use is
http://www.midwestmosthated.com/mmh.php ... ntent.html

i use to do this code with ease and now its not working. I cant remember how the hell this code works and i've been stuck for the past 2 days! can anyone help?!?!?

Re: template error

Posted: Thu Jul 14, 2011 12:30 pm
by sinecosine
At a first glance, it appears that you are presuming the "Register Globals" option is "On". If you have not used PHP for awhile, this might make sense!

The link you show at the bottom of the page has, .../page=content.html and then you use "page" directly in your code as include ("$page"). This looks to me like you are using register globals "the old way"... so to speak. As of PHP 4.2.0, register globals is turned off. So, you need to use the superglobals in order to retrieve the query string.

For example, if you are receiving a GET request, you would do something like this:

Code: Select all

$page = $_GET['page'];
...
include ("$page");
So, take a look at the PHP manual for _POST and _GET as well as for "Register Globals".

Re: template error

Posted: Thu Jul 14, 2011 2:50 pm
by BLACKMASK
honestly that made it more difficult for me to understand lol sorry i guess im not as good as i thought.

correct me if im wrong,

i have my template filed mmh.php that has my layout with links

my content would be content.html

<?php $page = $_GET['page'];
...
include ("$page");?>

how would i insert this into my page if u can help with that

Re: template error

Posted: Thu Jul 14, 2011 5:20 pm
by sinecosine
This is how you would go about it... Now keep in mind that this is just an example and not production code (e.g., no validation is done and it is critical that it be done!)

mmh.php:

Code: Select all

<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>This is your web page!!!</title>
</head>
<body>
<h1>WOW!</h1>
<p>There is some exciting stuff here! This is mmh.php</p>
<p>In fact, this page comes from somewhere else...</p>
<?php
$page = $_GET['page'];
echo $page;
include ( "$page" );
?>
</body>
</html>
content.php:

Code: Select all

<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>This is your web page!!!</title>
</head>
<body>
<h1>WOW 2!</h1>
<p>This is content.php</p>
</body>
</html>
Put these 2 files in your document root. You can access mmh.php as follows:
http://{you_host_here}/{you_directory_here_if_one_exists}/mmh.php/page=content.html

Hope that helps!

Re: template error

Posted: Fri Jul 15, 2011 12:10 pm
by BLACKMASK
ok i think im just slow smh ive done everything u guess request but now my layout isnt even showing :banghead:

Code: Select all


<?php
$page = $_GET['page'];
echo $page;
include ( "$page" );
?>

arent I suppose to input mmh.php or content.html where the [page] or (page) is? this is the only thing holding me back from finishing this site and its killin me

Re: template error

Posted: Fri Jul 15, 2011 12:19 pm
by BLACKMASK
:D you know what, i did a lot of trail and error and finally figured out what i was doing wrong! thanks everyone for the help!