Jump to content

Problems with require()


surelyoujest

Recommended Posts

I'm creating a system of templates for my website.  My index.php file is essentially the frame for all the site's content.  Each link on the site directs the user to index.php while attaching a value to the variable $content:

 

[pre]http://www.domain.com/index.php?content=value[/pre]

 

which then plugs into this:

 

[pre]<?php

if (empty ($content)) {

require 'templates/body.html';

} else {

require 'templates/$content.html';

}

?>[/pre]

 

In theory, this should load value.html into the layout of index.php, while using body.html as a default if $content is empty. Instead, body.html is the only thing that loads. In other words, it seems as if $content refuses to take on any value.

 

This procedure worked perfectly on a website I did for a client, but it's being very rebellious against my own website. I should mention that the "templates" folder and all the files therein are properly uploaded and named. Your thorough criticism--and your patience with a PHP noob--is greatly appreciated. Thanks,

 

surelyoujest

Link to comment
https://forums.phpfreaks.com/topic/141119-problems-with-require/
Share on other sites

you are probably used to register_globals being on, which is no longer the default (and shouldn't be for security reasons)

 

try this:

<?php
if (empty ($_GET['content'])) {
require 'templates/body.html';
} else {
require 'templates/{$_GET['content']}.html';
}
?>

 

note: this should get your script working...but it too is very flawed when it comes to security. someone could put something in the url that would allow them access to pages they shouldn't have access to

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.