Ninjakreborn Posted April 17, 2006 Share Posted April 17, 2006 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<?phpinclude "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<?phpinclude "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. Quote Link to comment https://forums.phpfreaks.com/topic/7642-include-file/ Share on other sites More sharing options...
wildteen88 Posted April 17, 2006 Share Posted April 17, 2006 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]<?phpinclude "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. Quote Link to comment https://forums.phpfreaks.com/topic/7642-include-file/#findComment-27867 Share on other sites More sharing options...
Ninjakreborn Posted April 17, 2006 Author Share Posted April 17, 2006 so what would the purpose of taking strings out of a specific file without pulling the whole file. Quote Link to comment https://forums.phpfreaks.com/topic/7642-include-file/#findComment-27871 Share on other sites More sharing options...
AndyB Posted April 17, 2006 Share Posted April 17, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/7642-include-file/#findComment-27884 Share on other sites More sharing options...
Ninjakreborn Posted April 17, 2006 Author Share Posted April 17, 2006 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 Link to comment https://forums.phpfreaks.com/topic/7642-include-file/#findComment-27888 Share on other sites More sharing options...
sKunKbad Posted April 17, 2006 Share Posted April 17, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/7642-include-file/#findComment-27926 Share on other sites More sharing options...
Ninjakreborn Posted April 17, 2006 Author Share Posted April 17, 2006 thanks for the help./ Quote Link to comment https://forums.phpfreaks.com/topic/7642-include-file/#findComment-27932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.