The code below shows me "111
" and "222
". But doesn't redirect me anywhere. What can I do now?
<?php
echo "111";
header("Location: http://www.google.com");
echo "222";
return Redirect::to('http://www.google.com');
echo "333";
?>
The code below shows me "111
" and "222
". But doesn't redirect me anywhere. What can I do now?
<?php
echo "111";
header("Location: http://www.google.com");
echo "222";
return Redirect::to('http://www.google.com');
echo "333";
?>
Two things ...
You need to put exit
after your header("Location: ... ")
Example:
header("Location: http://www.google.com");
exit;
But more importantly ... your header won't redirect if you've already written to the output buffer with echo
.
You can't have any output before the header tag is set, so remove the echo statement and exit the script after the header:
header("Location: http://www.google.com");
exit;
It's not working because you've already sent data to the client (the echo
). Either send your headers before you echo anything, or buffer it like this:
ob_start();
echo "111"; //Note: You're missing a semicolon here
header("Location: http://www.google.com");
echo "222";
$obj = Redirect::to('http://www.google.com');
echo "333";
ob_flush();
return $obj;
To Continue Reading... Hope this helps!