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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.