3

I have some PHP files called file1.php, file2.php, file3.php. Now, I want to run these PHP files one by one from other PHP file called all.php. I mean file2.php will be executed after file1.php was completed. File3.php will be executed after file2.php was completed. How to do that ?

Can I use exec function ? It is safe for my hosting ? I am using Cpanel in shared hosting. There is any way to do that but safe for my content in hosting ?

Thank you very much !

1
  • include what you need in all.php Commented Nov 27, 2014 at 6:31

4 Answers 4

5

you can use include()

include('file1.php');
include('file2.php');
include('file3.php');

or include_once()

include_once('file1.php');
include_once('file2.php');
include_once('file3.php');

or require or require_once

require 'file1.php';
require 'file2.php';
require 'file3.php';

=> require() will produce a fatal error (E_COMPILE_ERROR) and stop the script

=> include() will only produce a warning (E_WARNING) and the script will continue

Sign up to request clarification or add additional context in comments.

Comments

1

in the file all.php you can do:

include('file1.php');
include('file2.php');
include('file3.php');

1 Comment

when you include the file, it's as if you have the file written at the location where you have included it !!!!
1

Yes you can use 'exec' function or as alternate 'system', 'passthru' functions

But in that case your files i.e. 'file1.php', 'file2.php' and 'file3.php'

  • will execute as cli execution.
  • you will not get http variables like $_REQUEST, $_SESSION etc.
  • security is depend upon code what you written in file1.php.
  • you code will execute as a permission of apache user if you are calling all.php from web url (so probably it will be safe).

Comments

1

If you want to execute a tottaly seperate script U could albo use exec (http://php.net/manual/en/function.exec.php)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.