gotornot Posted March 11, 2010 Share Posted March 11, 2010 Hi I am trying to use a header redirect AFTER html output which is obviously not going to work. I want to run a script in the background get a return code ie a 1 or 0 from the page that data is submitted to then after send the user on to the next step i cant seem to get it to work any ideas // now we must send the data that is collected to the url ob_start(); ignore_user_abort(true); set_time_limit(5); // MAXIMUM RUNNING TIME CAN BE SET TO WHATEVER IN SECONDS I BELIVE //THE HTML BELOW CAN BE CHANGED. echo '<img src="waitani.gif" width="250" height="250">'; echo str_repeat("<!-- Flush that stuff --->\n", 256); header('Connection: close'); header("Content-length: ".ob_get_length()); ob_end_flush(); // fly my pretties! flush(); // browser should now stop rolling //ANDY WHATEVER YOU WANT TO HERE. #header('Location:'.$final_url); $handle = fopen("$final_url", "r"); $contents2 = fread($handle, 1); if ($contents2=="1") { $test = "1 seen and read"; }else{ $test = "Nothing seen im broke"; } //now send to a url + $test exit(); Link to comment https://forums.phpfreaks.com/topic/194894-header-not-working/ Share on other sites More sharing options...
cags Posted March 11, 2010 Share Posted March 11, 2010 Re-order your code. There is no reason whatsoever to have a redirect AFTER output code. Since if you are being redirected you will not see any code that is output, what's the point in outputting it. Move logic to the top of the script and only output afterwards. Link to comment https://forums.phpfreaks.com/topic/194894-header-not-working/#findComment-1024738 Share on other sites More sharing options...
gotornot Posted March 11, 2010 Author Share Posted March 11, 2010 there is an awfull lot more of outputted code above this that handles the data popping it into data bases etc . the bit ive shown is where it contacts a script on another server irrespective of wether the user closes the window and processes that data i just wondered how the best way to move to the next stage Link to comment https://forums.phpfreaks.com/topic/194894-header-not-working/#findComment-1024741 Share on other sites More sharing options...
cags Posted March 11, 2010 Share Posted March 11, 2010 I find it impossible to believe the code cannot be restructured to have the logic at the top. But since you are using ob_start() anyway, just don't flush the data until after the redirect. Link to comment https://forums.phpfreaks.com/topic/194894-header-not-working/#findComment-1024743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.