coupe-r Posted February 18, 2011 Share Posted February 18, 2011 Hi All, I just formatted my HD and had a WAMP setup. I have not installed each component separately (newest versions). When I type in a text box and press the submit button, I get: Warning: Cannot modify header information - headers already sent by (output started at D:\Web\Apache\htdocs\projects\tms_new\functions\functions.js:304) in D:\Web\Apache\htdocs\projects\tms_new\apps\index.php on line 167 Line 304 in the functions.js file is: </script> Line 167 in index.php is: header('Location: index.php?lastname='.stripslashes($lastname)); It says I am sending header information before line 167, but there isn't any. The .JS file only has JS code. Can someone give me any suggestions? Thanks everyone!! Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/ Share on other sites More sharing options...
btherl Posted February 18, 2011 Share Posted February 18, 2011 Please read this topic: http://www.phpfreaks.com/forums/php-coding-help/header-errors-read-here-before-posting-them/ Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176033 Share on other sites More sharing options...
coupe-r Posted February 18, 2011 Author Share Posted February 18, 2011 Hello. I did read that, and putting ob_start(); at the very top of my script solves the issue, but is this truly the right way? I just don't want a quick fix, I'd rather learn the proper way. I know you deal with this a lot, so I apologize for how this came off. Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176038 Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2011 Share Posted February 18, 2011 That error has likely been there for a long time, but error reporting was off. Now that you've reinstalled php, error reporting is on (as it should always be while developing) and the error is being displayed. Anyhow, read the thread btherl pointed out. <---- Edit: I see you've done that . . . Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176040 Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2011 Share Posted February 18, 2011 The right way is to change the logic so no headers would need to be sent after output has started. Hint: since javascript is a client-side language, it has to be sent to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176043 Share on other sites More sharing options...
coupe-r Posted February 18, 2011 Author Share Posted February 18, 2011 Thank you. So I did this and everything looks OK. So basically, never user header() when you want to take the user somewhere else. Correct? Thanks again man. echo '<meta http-equiv="refresh" content="0;url=index.php?lastname='.stripslashes($lastname).'">'; //header('Location: index.php?lastname='.stripslashes($lastname)); Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176045 Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2011 Share Posted February 18, 2011 No, that isn't the case at all. You just need to order the logic in such a way that any headers are sent before any output is started. Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176047 Share on other sites More sharing options...
coupe-r Posted February 18, 2011 Author Share Posted February 18, 2011 OK, so I took require_once('../functions/functions.js'); and moved it to the very bottom of my PHP and still use the header(). This also works... Yea / Nah? Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176049 Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2011 Share Posted February 18, 2011 It should, but without seeing the code the only suggestion I can really make is to give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176050 Share on other sites More sharing options...
coupe-r Posted February 18, 2011 Author Share Posted February 18, 2011 Well, this page is 500+ lines of PHP. I took the require_once, which was on line 6 where I did all my "requires" and moved it to the end of my PHP (last line). So in essence, it comes "after" any output... Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176051 Share on other sites More sharing options...
coupe-r Posted February 18, 2011 Author Share Posted February 18, 2011 *** Solution *** I was including a .JS file at the top of my PHP code. I moved this to the last line and everything works fine. Thanks for putting up with me!! Quote Link to comment https://forums.phpfreaks.com/topic/228064-header-warning-message-after-upgrading-php/#findComment-1176058 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.