Instruction include() is serving to read and execute code from file in time when script is running. Also you can use require() instruction, which work same as include(), but they have sundry errors: - include() - type of error: Warning, if no file the script will be still running!
require() - type of error: Fatal Error, if no file the script will be permanently terminated (stopped!)
Basic use of include instruction!
File: data.php
Code:
<?php
$name="Thomas";
$nick="dario";
echo '<span>My name is $name and my nick is $nick</span>';
?>
File: test.php
Code:
<?php
echo '<span>Content of data.php file</span>
';
echo '<span>START</span>
';
include("data.php");
echo '<span>EOS</span>
';
?>
Description: including information from data.php
Include and condition instruction
File: data.php
Code:
<?php
$forum="http://www.myfreedomain.net/";
?>
File: test.php
Code:
<?php
if($including=="yes"){
echo'<span>My favourite </span>';
echo'<a href="';
include("data.php");
echo'">page</a>';
}else{
include("other_file.php");
}
?>
Description: If variable $including will equal with yes then data.php will be included, if no then other_file.php will be included
Basic use of require instruction!
File: data.php
Code:
<?php
$my_login="login";
$my_pass="pass";
?>
File: test.php
Code:
<?php
require("data.php");
if($pass=="$my_pass" && $login=="$my_login"){
echo '<span>You have been loged! :)</span>';
}else{
echo '<span>You taped bad login!</span>';
}
?>
Description: In data.php you have information about login and by the condition instruction you check them!
Created by m1chu
|