0

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.

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

4 Answers 4

5

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); 
Sign up to request clarification or add additional context in comments.

Comments

0

use this function file_get_contents():

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

Comments

0

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

header_remove('Location');

1 Comment

How can you include a php file which is on another server?
0

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();

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.