rv20 Posted May 20, 2009 Share Posted May 20, 2009 When you, include "somefile.ext"; am i right in saying it just runs that script? so it's similar to adding an external css file, <link rel="stylesheet" type="text/css" href="some_css_file.css" /> SO... when you have html and php on the same *.php page, to make things neater can you just include the relevant *.php file whenever you need to run some php code, so somethin like, //login.php <?php include "check_login.php"; <html><head></head><body> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type = "text" name = "u_login"> <input type ="submit> </form> <body></html> ?> i usually see all the php code and html code on one page which makes things pretty messy, can i do what i am asking? Link to comment https://forums.phpfreaks.com/topic/158912-including-files/ Share on other sites More sharing options...
Anxious Posted May 20, 2009 Share Posted May 20, 2009 It does what 'include' means. It works in the same way as if you'd include a css file. If the included file isn't in reach, the script will still run. Just may not work as you wanted. Like if a CSS file is missing, the web page wont look as it should do. It works the same. If you require a file, the script WONT run without that file in reach. Link to comment https://forums.phpfreaks.com/topic/158912-including-files/#findComment-838097 Share on other sites More sharing options...
GingerRobot Posted May 20, 2009 Share Posted May 20, 2009 When you include a file, it is, execution-wise, (almost) identical to swapping the line that does the including for all of the source code in the included file. In other words this: file1.php <?php $text = 'foo'; include('file2.php'); echo 'bar'; ?> file2.php <?php echo $text; ?> Is the same as: file1.php <?php $text = 'foo'; echo $text; echo 'bar'; ?> Edit: Updated to add variables for clarity. Link to comment https://forums.phpfreaks.com/topic/158912-including-files/#findComment-838118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.