Jump to content

Including files


rv20

Recommended Posts

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
Share on other sites

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
Share on other sites

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