0

I have a code that redirects to an url with header like

header("Location: $reponseUrl"); 

But I want to echo something before redirecting like

echo "some text here"; 
header("Location: $reponseUrl"); 

But the output comes like

headers already sent by (output started at..)..

Finally i found the solution

It has to be done somthing like this

header("Refresh: 5; url=$reponseUrl");
echo 'some text here'; 

This will echo for 5 seconds then it will redirect.

Lois
  • 13
  • 5
  • It would be great if you tell me the duplicate question. coz m looking for it. Please – Lois Apr 28 '15 at 08:43
  • It is linked at the top of the question. – Rangad Apr 28 '15 at 08:45
  • @Rangad thanks.. m new here little confused – Lois Apr 28 '15 at 08:48
  • You cant echo something and then redirect. How would that even look? You can either redirect or echo. No matter what you do, it's absolutely **impossible** to echo something first and then redirect, no matter what you try. – N.B. Apr 28 '15 at 09:17
  • @N.B. it works.. impossible is nothing !!.. you have to look for available options – Lois Apr 28 '15 at 09:53
  • 1
    No, it **does** not work. You are just dumping some random header you found which is not even a standard. What you **need** is a client-side refresh mechanism, but you wanted a server-side one - this shows how lost you are. You also wanted to echo something while sending `Location` header. This is a clear indication you have no idea how HTTP works. A refresh after a period of time can be done. Just not with **regular** HTTP. Note the bolded word regular. The only reason this crap works is because vendors support it because of people who do random stuff like you. – N.B. Apr 28 '15 at 10:03
  • What is the logic in this? Why do you want to redirect somebody, after echoed something? Put there a link like `next`, or `goto this page`. This is how it works. Before any output, do the controlling, database manipulations, etc... and redirect if need. If no need, then after all of this, show the content of the page. – vaso123 Apr 28 '15 at 10:17
  • m new and learning myself... I am using this in my payment gateway. after transaction completes it will show a loading for 5 sec then redirects to my site with the transaction details... whether its not correct but it works in my site... Still you think this doesn't work then i can give you my payment link you can do it yourself;; LOL – Lois Apr 29 '15 at 10:17
  • It will be greatly appreciated if you tell me a solution without bla bla.... for me this code works. :) – Lois Apr 29 '15 at 10:22

0 Answers0