Jump to content

include file


Ninjakreborn

Recommended Posts

I have learnt include "" , I have some questions about this.
What is this for, to keep people from being able to see the source code, and if so why. I also noticed if you put in a url like
<?php
include "http://www.w3schools.com";
?>
For instance it loads the webpage, but not the graphic files and pictures for it, are there situations where one might need to pull an outer website into there website for some reason like this,I also noted if you try and do something like this
<?php
include "http://www.w3schools.com";
include "http://www.gamefaqs.com";
include "http://www.phpfreaks.com";
include "http://www.php.net";
?>
for instance, then it loads each webpage onto the php page, but one after another and they always stack, like the w3 schools would be on top, below that the gamefaqs would start, after that and it keeps going, is there ever a point for anything like this.
Link to comment
Share on other sites

No, you dont include a whole website.

inlcude or require is used to include extra source code into a certain file. Most programmers split up their code in to seperate files. For example for connecting to a mysql db, people will create a file called db.php wit hthe folllowing:
[code]<?php

$host = "localhost";
$user = "root";
$pass = "password";
$database = "db_name";

mysql_connect($host, $user, $pass) or die("Database connection faild");

mysql_select_db($database) or die("Database selection failed");

?>[/code]
Then when they need to connect to mysql they would use this:
[code]<?php

include "db.php";

// MySQL query stuff here

?>[/code]
When you do that what PHP does is basically is copy 'n' paste the code from db.php to the file that is including the db.php. It just saves having to type up all the mysql connection stuff each time you want to connect to the database.

Have a look at the examples [a href=\"http://uk.php.net/manual/en/function.include.php\" target=\"_blank\"]here[/a] from the fine manual.
Link to comment
Share on other sites

[!--quoteo(post=365709:date=Apr 17 2006, 05:58 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 17 2006, 05:58 PM) [snapback]365709[/snapback][/div][div class=\'quotemain\'][!--quotec--]so what would the purpose of taking strings out of a specific file without pulling the whole file.[/quote]
It's called modular design (among other things). By using an included file instead of entering the same content into every page of a site, you can change one file and have every page change. Also, you never need to debug a piece of code that works only the stuff outside the included parts.

An approximate HTML equivalent to an included file is an external javascript or external CSS file.
Link to comment
Share on other sites

[!--quoteo(post=365726:date=Apr 17 2006, 03:49 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 17 2006, 03:49 PM) [snapback]365726[/snapback][/div][div class=\'quotemain\'][!--quotec--]
now the comparison to javascript and css external files really cleared that up, because I always use external css, and have started learning javascript with external files, so that does help a lot, thank you.
[/quote]

A nice reason to use an include file to connect to your database is that you can .htaccess protect the include folder for better security, or even better place the include file above the root.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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