Forum Moderators: coopster
I can't get this to work for anything. I have a php menu- I want the links to fill the variable below on my main index page. This is how I have one link set up:
echo ("<li><a href='index.html?page=contact'>" . "Contact" . "</a></li>");
So the contact.html page should replace the $page.html place. I thought it might have something to do with register globals but any way I set it isn't working.
<div id="left">
<?php @ require_once ("$page.html"); ?>
</div>
The main goal is simply to feed these content pages into the variable from the php menu. Any suggestions?
If that is all right (I like to assume) have you checked to make sure you are actually getting the varible from the link? Try just printing out $page to make sure its working.
Try this instead
<?php require($HTTP_GET_VARS['page'] . ".html"); ?>
If that doesn't work, try
<?php require("contact.html"); ?>
If that doesn't work, your path to the file is wrong.
Don't put in the @ until it works - you're just making your debugging harder.
Tom
content ¦ menu ¦ information
I want the content <div> to contain a $variable that will contain the pages that are being sent via a php menu. In my profile you can see two columns, a menu in one and a search box in the other.
Basically, the menu links should simply tell the 'content' pages (like contact.html, clients.html) to fill the variable in the content <div>. Creating one template for the entire site.
The problem I'm having right this second is with this line:
<div id="left">
<?php @ require_once ("$page.html"); ?>
</div>
-->It clears everything under the latest news and info image (the two right-side columns). $page is suppose to be empty- but I tested just to make sure that if I made a page.html with some content:
<div id="left">
<?php @ require_once ("page.html"); ?>
</div>
It works. But I can't switch the content pages without the $var.
Make more sense I hope? It could be real easy, I'm just new to this-
Thanks for any insight into how this might work.
index.html is in the same folder as menu.php. menu.php is require_once in another <div> no problem.
menu.php (example)
--------------
echo ("<li><a href='index.html?page=contact'>" . "Site Map" . "</a></li>");
index.html
--------------
<div id="left">
<?php require($page.html); ?>
</div>
-->I tried each suggestion above- and get:
Fatal error: Failed opening required 'html' (include_path='.;c:\php4\pear') in
What am I missing?
if it does and is at the root level then I think I have another idea.
Take a look at the documentation for include and require on php.net.
They reference the include_path [php.net].
This is probably the problem. You need to reference the file structure without relation to urls. For the web I would use.
<?php
$content = $DOCUMENT_ROOT . $page . ".html";
require($content);
?>
Take a look at user contributed notes for require() [php.net]
<added>sorry madcat, I misunderstood what you were doing originally. When I read this last post I had the ooooooooooh, I see.
The menu works as it should...
<div id="left">
<?php
$pool = @include($_GET['page'] . ".html");
if (!$pool) { include("hello.html"); }
?>
</div>
If I don't supress the @include function above:
Warning: Failed opening '.html' for inclusion (include_path='.;c:\php4\pear') -->
appears only on the home page?
Warning: Failed opening '.html' for inclusion (include_path='.;c:\php4\pear') -->
Question: What file is it including?
Answer: .html
In other words, $_GET['page'] is undefined. Why? I think you've answered it:
appears only on the home page?
On the home page, you probably get there by putting in a domain name and there are no GET parameters. If you are going to use this method, you MUST have $_GET['page'] default to something VALID if it is not defined. Currently it defaults to "" so
require($_GET['page'] . ".html");
defaults to
require(".html");
require($page1.html);
Two problems:
1. This will cause a parse error since "." is not an allowable character in a variable name.
2. Even if it PHP could parse this, it wouldn't give the desired result because it would be looking for the variable named $page1.html and it would not be taking the value of $page1 and [i]concatenating[/] it to the string ".html" and, even if it did, the . would then be the contatenation operator, so you would be concatenating the value of $page1 to "html" (no dot) so you would be looking for a file with a name of the form "filenamehtml" which is probably not what you want.
If you just type in the url, hello.html will display. It's not until the links are chosen that hello.html will be replaced. So there is never "", no?
Something else is still wrong, because your error message says that it is trying to include ".html" which indicates that $page == "". Or was the error message from before you made that change? Failed to reload?
Anyway, it works now right?
Tom
You could do if else statements
if ($page==Contact){
include ('contact.html');
} elseif ($page==Clients) {
include ('clients.html);
} else {
include ('index.html');
What is the security issues involed?
He's using a GET param to specify which file gets loaded. If someone were to get a malicious script on his server and set the page to include it, he has taken as yet no steps to stop this. But if they can upload a malicious script, they can probably get it to run some other way.
This can be made quite safe and is a common method for doing this. I don't think there's a real problem as long as you're aware of what's happening.
I don't thing switching files to and fro a variable should be this tough
It isn't. There's something that's not coming through from your explanations.
Tom
>>include($_GET['page'] . ".html");
completely unsafe depending on the configuration of PHP.
I could just use a url like [mydomain.com...]
In somedir there is an .htaccess file that enables php parsing for html files and so the included file could execute php code.
Simply, in my php.menu:
echo ("<li><a href='index.html?&page=home'>" . "Home" . "</a></li>");
echo ("<li><a href='index.html?&page=clients'>" . "Clients" . "</a></li>");
echo ("<li><a href='index.html?&page=contact'>" . "Contact" . "</a></li>");
echo ("<li><a href='index.html?&page=sitemap'>" . "Site Map" . "</a></li>");
In my index.html:
<div id="left">
<?php
include $_GET['page'] . ".html";
?>
</div>
That's it. The menu works when I click on the links because $_GET is fulfilled. But upon entering the site: Warning: Failed opening '.html' for inclusion (include_path='.;c:\php4\pear').
Of course, there are the security risks that I have to think of now.
if/else statements become unrealistic if you have more than five pages.
If this works somehow, I'll see web designing in a whole new light though. Designing one template, that's it. It's nothing new, but for me it means time on my side.
This has nothing to do with php.ini-dist?
<div id="left">
<?php
$valid = true;
switch ($_GET['page']) {
case 'page1': break;
case 'page2': break;
case 'page3': break;
case 'page4' : break;
case 'page5' : break;
case 'page6' : break;
case 'page7' : break;
default: $valid = false; break;
}if ($valid) include($_GET['page'] . '.html');
else include('home.html');
?>
</div>
Here it is.
--------------------------------------------
Now what I want to do is figure out a way to make it modular. I have to study up but if I can find a way to use a function to make this effect work for 250+ pages- production time can be cut in half. db's?
Thank you for all your inputs- most appreciated.