patriotfan Posted September 7, 2009 Share Posted September 7, 2009 I keep getting the headers sent error :/ Cannot modify header information - headers already sent function download($id){ $p1 = rand('000000','999999'); $new = 'uploads/downloads/' . $p1 . '' . $id . ''; $old = 'uploads/downloads/' . $id . ''; copy($old,$new); header('Location: $new'); unlink($new); } Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/ Share on other sites More sharing options...
mikesta707 Posted September 7, 2009 Share Posted September 7, 2009 this means that you have output sent beore that line. Make sure there is no output at all (even HTML output) where that function is called. preferably, put the function call at the very top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/#findComment-913845 Share on other sites More sharing options...
kratsg Posted September 7, 2009 Share Posted September 7, 2009 Also, read the stickied notes before posting. http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/#findComment-913848 Share on other sites More sharing options...
patriotfan Posted September 7, 2009 Author Share Posted September 7, 2009 this means that you have output sent beore that line. Make sure there is no output at all (even HTML output) where that function is called. preferably, put the function call at the very top of the page. Did, but I still get it <?php session_start(); function download($id){ $p1 = rand('000000','999999'); $new = 'uploads/downloads/' . $p1 . '' . $id . ''; $old = 'uploads/downloads/' . $id . ''; copy($old,$new); header('Location: $new'); unlink($new); } ?> Also, read the stickied notes before posting. http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Sorry, won't do it again Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/#findComment-913852 Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2009 Share Posted September 7, 2009 Well, read the error message, it states where the output is occurring at that is preventing the headers from working. If you cannot determine what the actual output is, post the whole error message and the file where the output is occurring. Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/#findComment-913853 Share on other sites More sharing options...
kratsg Posted September 7, 2009 Share Posted September 7, 2009 I'm going to gather that it's WHEN you run the function, rather than the actual function. You are probably echoing out something before running your function. Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/#findComment-913856 Share on other sites More sharing options...
mikesta707 Posted September 7, 2009 Share Posted September 7, 2009 dont put the function at the very top, put where the function is called. IE //the following call $id = "whatever"; download($id); should be at the top of the page. If in whatever script you have it can't be, then you are going to have to take the header out of the function. Besides, Having header calls in functions like that tends to lead problems like you are having. alternatively, you can put ob_start(); at the top of the page and ob_flush(); at the very bottom to get around this. However, make sure you put a die() after the header, as things can go awry if you don't. However, if you find you must take this route, you may want to rethink the design of your function. take a read of ob_start() and flush in the php manual for more info Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/#findComment-913858 Share on other sites More sharing options...
patriotfan Posted September 7, 2009 Author Share Posted September 7, 2009 I got it to work, thanks Quote Link to comment https://forums.phpfreaks.com/topic/173360-solved-headers-sent/#findComment-913866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.