Your Ad Here

New Post/Thread Notification: PHP Forum

Hello,

welcomewiki has just posted in the PHP Forum forum of Wiki Newforum under the title of PHP Include File.

This thread is located at http://www.wikinewforum.com/showthread.php?t=5863

Here is the message that has just been posted:
***************
*_Example 2_*

Now, let's assume we have a standard menu file that should be used on all pages (include files usually have a ".php" extension). Look at the "menu.php" file below:


<html>
<body> <a href="http://www.w3schools.com/default.php">Home</a> |
<a href="http://www.w3schools.com/about.php">About Us</a> |
<a href="http://www.w3schools.com/contact.php">Contact Us</a>

The three files, "default.php", "about.php", and "contact.php" should all include the "menu.php" file. Here is the code in "default.php":


<?php include("menu.php"); ?> <h1>Welcome to my home page</h1> <p>Some text</p> </body>
</html>

If you look at the source code of the "default.php" in a browser, it will look something like this:


<html>
<body>
<a href="default.php">Home</a> |
<a href="about.php">About Us</a> |
<a href="contact.php">Contact Us</a>
<h1>Welcome to my home page</h1>
<p>Some text</p>
</body>
</html>

And, of course, we would have to do the same thing for "about.php" and "contact.php". By using include files, you simply have to update the text in the "menu.php" file if you decide to rename or change the order of the links or add another web page to the site.


*The require() Function*

The require() function is identical to include(), except that it handles errors differently.


The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).


If you include a file with the include() function and an error occurs, you might get an error message like the one below.


PHP code:


<html>
<body>

<?php
include("wrongFile.php");
echo "Hello World!";
?>

</body>
</html>

Error message:


*Warning:* include(wrongFile.php) [function.include]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5 *Warning:* include() [function.include]:
Failed opening 'wrongFile.php' for inclusion
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5 Hello World!

Notice that the echo statement is still executed! This is because a Warning does not stop the script execution.


Now, let's run the same example with the require() function.
PHP code:


<html>
<body>

<?php
require("wrongFile.php");
echo "Hello World!";
?>

</body>
</html>

Error message:


*Warning:* require(wrongFile.php) [function.require]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5 *Fatal error:* require() [function.require]:
Failed opening required 'wrongFile.php'
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5

The echo statement was not executed because the script execution stopped after the fatal error.


It is recommended to use the require() function instead of include(), because scripts should not continue executing if files are missing or misnamed.
***************

Your Ad Here

FREE TRAINING By World's No.1 Site Wikipedia

Hi

Here the SAP HR Real Blue Print: http://www.wikinewforum.com/showthread.php?t=1410


Join us World's Best FREE SAP HR Training @ www.wikinewforum.com


Online Training (Any time you can log-in)

FREE SAP HR TRAINING

WITH REAL TIME SCREEN SHOTS

By World's No.1 Site Wikipedia



Duration: 40 Days Venue: Wikipedia Website

Timings: Any time you can open and can take training

Support: Any time 24/7

We called as Special training because:

  • Real Time Employees will teach & answers your queries
  • Real Time Scenarios
  • Real Time System screen shots step by step configuration
  • Post training support like Resume & Interview tips with exact requirement, we provide top companies HR email ID's and every day vacancy list.

Special Topics apart from general topics:

  • We teach special topics like following where no any dare to reach
  • Payroll & Time Schema's
  • Payroll & Time PCR's (Personal Calculation Rules)
  • Rates of Pay
  • Factoring/Pro-ration
  • Wage type Valuation
  • Time Quota's & Time Types
  • Time Evaluation
  • Absence Valuation
  • Integration wit FICO & other Modules
  • And more and more....list will not stop
  • Totally End-to-End implementation Process

Visit our Website

www.wikinewforum.com

Free Demo

http://www.wikinewforum.com/showthread.php?p=10222#post10222

Reach us

info@wikinewforum.com

Presented

World No. 1 Site - Wikipedia

Our Aim is to provide FREE SAP Training, hope you join.