Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP redirect without header() or meta

I'm trying to design a page which does some database actions, then redirects to user back to the page they came from. The problem is that I use a require() function to get the connection to the database, so the headers are already sent. A meta tag is out of the question since I want it to look like all the processes are done from the page they came from. Any tips? Is there a way I can use the require() and the header() or do I have to drop one? Is there an alternative to header()?

like image 913
Yoshiyahu Avatar asked Dec 09 '22 11:12

Yoshiyahu


1 Answers

If you can't send the header() before some content gets sent, use output buffering by placing an ob_start(); at the beginning of your script before anything is sent. That way, any content will be stored in a buffer and won't be sent until the end of the script or when you manually send the buffer's contents.

On another note, simply requireing another file would not generate any headers/content unless that included script sends them. The most common "hidden" cause of this is unnoticed whitespace before or after the <?php ?> tags.

like image 162
Wiseguy Avatar answered Dec 26 '22 05:12

Wiseguy