-1

In php page if i use echo to print something it's not showing printed output. It happens only in case use header Location. If header location is not there then it's printing.

see this is code

echo "to print something here";

header("Location: package.php");

After executing this i am not able to see output. But if i remove header("Location: package.php"); then output is printing.

Please help me.

I am using Wamp server 3 Php 5.6

Jonathan
  • 2,778
  • 13
  • 23
user647956
  • 59
  • 2
  • 2
  • 6
  • 1
    `header("Location: package.php");` tells the browser to redirect you, so that's expected. That also being said `header("Location: package.php");` won't normally work after you've echoed something unless you're using output_buffering which it seems you are if it works. – Jonathan Apr 05 '17 at 17:21
  • You can either echo or you can do a header redirect. Not both. – Matt Apr 05 '17 at 17:22
  • what are you trying to do? echo 'to print something here' on the package.php page? – coderodour Apr 05 '17 at 17:23

1 Answers1

0

What you need to do is not possible as php headers must sent out before any content, so the correct order is:

header("location: package.php");
echo "to print something here";

But this will redirect you instantly and you will not you see the content. So you should do the redirection by JS:

echo "to print something here";
echo '<script>setTimeout("document.location.href = 'http://www.thepageuouwant.com/package.php';",500);</script>';

This way you will show your message as well as after half a second (500ms) the user will be redirected to the new page.

Shakti Phartiyal
  • 6,156
  • 3
  • 25
  • 46