Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

For example:

Content of server-a.com/test.php:

echo 'hello world one';

// now I need to call server-b.com/test.php here silently
// without interfering with user experience

echo 'hello world two';

Content of server-b.com/test.php:

mail($foo, $bar, $qux); header('location: http://google.com');


Now running server-a.com/test.php should output hello world one hello world two. And it should not redirect to google.com even though server-b.com/test.php was called successfully.

share|improve this question
1  
Your question does not relation show a between the two scripts. which one is calling what? – Lord Loh. Oct 24 '12 at 22:16
if you don't want header() to run make it conditional on some parameter you can decide when to pass. – Dagon Oct 24 '12 at 22:17
@LordLoh. If you run server-a.com/test.php, you also silently run server-b.com/test.php – IMB Oct 25 '12 at 17:24
Who down voted? Explain what's wrong with this question. – IMB Oct 25 '12 at 17:24

4 Answers

up vote 2 down vote accepted

You can use file_get_contents()

file_get_contents("server-b.com/test.php");

or Curl

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "server-b.com/test.php"); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_exec($ch); 
share|improve this answer

use this function file_get_contents():

file_get_contents("server-b.com/test.php");
share|improve this answer

You can use Symfony2's Process component for that.

Example:

use Symfony\Component\Process\PhpProcess;

$process = new PhpProcess(<<<EOF
    <?php echo 'Hello World'; ?>
EOF
);
$process->run();
share|improve this answer

You can remove the location header with header_remove. After you include server-b.com/test.php just call

header_remove('Location');
share|improve this answer
How can you include a php file which is on another server? – marvin Oct 24 '12 at 22:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.