phplearner2008 Posted February 13, 2009 Share Posted February 13, 2009 Hi, I have a file Interest_Sent.php where there is a checkbox and delete button, When the checkbox is checked and delete is pressed, it goes to process.php. I am posting the code below: <?php include_once('C:\Program Files\Apache Group\Apache2\htdocs\matrimonial\config.php'); $MY_ID = $_POST['MY_ID']; if(isset($_SERVER['HTTP_REFERER'])) $ref = $_SERVER['HTTP_REFERER']; if($ref == 'http://localhost/matrimonial/templates/Interests_Sent.php') { $checkbox = array(); $checkbox = $_POST['box']; $count = count($checkbox); for($i=0;$i<$count;$i++) { $value = $checkbox[$i]; $sql = "UPDATE interests_sent SET DELETED = 'Yes', DELETED_DATE = CURDATE() WHERE MY_ID = '$MY_ID' AND INTEREST_SENT = '$value' AND DELETED = 'No'"; $result = mysql_query($sql); if($result) { ob_start(); //start buffer include('C:\Program Files\Apache Group\Apache2\htdocs\matrimonial\Interests_Sent.php'); //we pass the output of include file to a variable $buffer = ob_get_contents(); ob_end_clean(); header("Location:http://localhost/matrimonial/templates/Interests_Sent.php"); } else echo "Could not delete"; } } ?> The above code works fine except for last but one line(header line). How do I redirect my page to Interests_Sent.php after these operations at process.php is completed? In other words how can I redirect a page after using include without getting "Headers already sent" error? Thanks. Link to comment https://forums.phpfreaks.com/topic/145034-solved-how-to-redirect-page-after-include/ Share on other sites More sharing options...
trq Posted February 13, 2009 Share Posted February 13, 2009 In other words how can I redirect a page after using include without getting "Headers already sent" error? Don't output anything in your included file. You cannot call header after output has been sent to the client. Link to comment https://forums.phpfreaks.com/topic/145034-solved-how-to-redirect-page-after-include/#findComment-761059 Share on other sites More sharing options...
Q695 Posted February 13, 2009 Share Posted February 13, 2009 You can't output data to the browser before headers are sent, so you need to keep things on the server before the page is redirected. If you need to include things from that page use a javascript redirect being called on load. Link to comment https://forums.phpfreaks.com/topic/145034-solved-how-to-redirect-page-after-include/#findComment-761080 Share on other sites More sharing options...
phplearner2008 Posted February 13, 2009 Author Share Posted February 13, 2009 I used <meta http-equiv="refresh" content="0;URL=Interests_Sent.php"> instead of header and my problem is solved. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/145034-solved-how-to-redirect-page-after-include/#findComment-761094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.