TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

n00b question :-)

Page: 1 Reply
May 6th 2004#149807 Report
Member since: May 6th 2004
Posts: 10
Hi, i read that part about the include code in this site and i heard it before, but is this also possible with a menu you use on the left of a site?

I haven´t tryed that code yet as i don´t know yet how it really works but i would be glad to know...
Reply with Quote Reply
May 6th 2004#149808 Report
Member since: Nov 26th 2001
Posts: 2586
You can include anything. It could be one word or a paragraph, or it could be a whole section of code.
Reply with Quote Reply
May 6th 2004#149809 Report
Member since: May 6th 2004
Posts: 10
Cool, ok i will try using this soon, then i don´t have to use i-frames..etc....
Reply with Quote Reply
May 6th 2004#149821 Report
Member since: Nov 26th 2001
Posts: 2586
it's quite simple.

[php]
include 'someFile.html';
print '
';
include 'somePhpScript.php';

?>
[/php]

and essentially where you put the include function and include that portion of markup or code, that is where it will be. So if you have a footer on all your pages that is the same, then just "cut" out the footer code and place it in a new file, call it something meaningful like "footer.inc.php" and then use the include function right where you cut the code out.

Note: sometimes you see footer.inc <- the '.inc' extension. Most hosts do not put the .inc into their parsed list of pages in their server config files, so if you have any sensitive data, like passwords or your own scripts, that you don't want others to see, just put a '.php' extension on the end of it. That way you can't view the source code. for example: footer.inc.php <- the inc tells you its an include and the .php hides the source.

This is also great for creating function and class libraries. Like a db class you can use on any page that needs it. Just include it on the top of the page.

One other bit of security that I use is to "wrap" the include into the page that includes it.

So for example (note the use of a CONSTANT declaration here - a variable that cannot be changed once set):

[php]

if (!defined(SOME_VAR)) {
define ('SOME_VAR', true);
}

?>
[/php]

put that at the very top of your pages, then for the "include" pages put this:

[php]

$die_message = 'www.yoursite.com';

if (!defined(SOME_VAR)) {
die("$die_message");
}
[/php]

Basically all this does is makes sure that the included pages are only "included" in valid pages. This is really useful when you deal with config files and administration scripts. You might have 3 level of users visiting your sites, an admin ,the "user", and a guest. You can "wrap" each included script within a page when the appropriate user is logged in by setting a "constant".

Then in your includes directory put a blank file and call it "index.html". That way if you have directory browsing turned "on", you won't be able to browse the include directory. Like if you have an /admin/ directory and don't want people to browse your scripts there.

Sorry to ramble, but includes are very handy and a great way to organize your pages on a lot of different levels.
Reply with Quote Reply
May 7th 2004#149876 Report
Member since: May 6th 2004
Posts: 10
it's quite simple.

PHP Code:
include 'someFile.html';
print '';
include 'somePhpScript.php';

?>

and essentially where you put the include function and include that portion of markup or code, that is where it will be. So if you have a footer on all your pages that is the same, then just "cut" out the footer code and place it in a new file, call it something meaningful like "footer.inc.php" and then use the include function right where you cut the code out.

Note: sometimes you see footer.inc <- the '.inc' extension. Most hosts do not put the .inc into their parsed list of pages in their server config files, so if you have any sensitive data, like passwords or your own scripts, that you don't want others to see, just put a '.php' extension on the end of it. That way you can't view the source code. for example: footer.inc.php <- the inc tells you its an include and the .php hides the source.

This is also great for creating function and class libraries. Like a db class you can use on any page that needs it. Just include it on the top of the page.

One other bit of security that I use is to "wrap" the include into the page that includes it.


Thank you very much, can i also cut out the code of a menu and place that in a file called menu.inc.php because that could be handy as well or..? So when u change a link it change everywhere...? On all the pages.
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum