lonewolf217 Posted May 2, 2009 Share Posted May 2, 2009 I am having an issue on one of my pages where my header redirect isn't working, and have scoured the page to find out where I may be outputting something before I redirect and I cannot find anything. The bulk of the changes I have made recently have been adding more javascript onto the page so I cannot figure out what the error could be besides that. Also, for some reason, the error gives an error on a line that is smack in the middle of the javascript in the head of the document which I just cannot understand. Any ideas on the theory of the question without having to post way too much code ? Link to comment https://forums.phpfreaks.com/topic/156521-is-it-possible-for-javascript-on-a-page-to-prevent-header-redirect/ Share on other sites More sharing options...
kenrbnsn Posted May 2, 2009 Share Posted May 2, 2009 No, we need to see your code and the exact error message. Ken Link to comment https://forums.phpfreaks.com/topic/156521-is-it-possible-for-javascript-on-a-page-to-prevent-header-redirect/#findComment-824173 Share on other sites More sharing options...
lonewolf217 Posted May 2, 2009 Author Share Posted May 2, 2009 it seems to be an issue with this javascript function. as soon as I remove it, redirect works fine. I actually have to delete the function though, just commenting it out doesn't seem to help which is wierd function selectSpecificProduct(x) { switch(x) { case 'Exchange': document.getElementById('exproduct').style.display=''; document.getElementById('sppproduct').style.display='none'; document.getElementById('nasproduct').style.display='none'; document.getElementById('commonproduct').style.display='none'; break; case 'Sharepoint': document.getElementById('exproduct').style.display='none'; document.getElementById('sppproduct').style.display=''; document.getElementById('nasproduct').style.display='none'; document.getElementById('commonproduct').style.display='none'; break; case 'NAS': document.getElementById('exproduct').style.display='none'; document.getElementById('sppproduct').style.display='none'; document.getElementById('nasproduct').style.display=''; document.getElementById('commonproduct').style.display='none'; break; case 'Common': document.getElementById('exproduct').style.display='none'; document.getElementById('sppproduct').style.display='none'; document.getElementById('nasproduct').style.display='none'; document.getElementById('commonproduct').style.display=''; break; default: document.getElementById('exproduct').style.display='none'; document.getElementById('sppproduct').style.display='none'; document.getElementById('nasproduct').style.display='none'; document.getElementById('commonproduct').style.display='none'; break; } } error message: [02-May-2009 08:54:52] PHP Warning: Cannot modify header information - headers already sent by (output started at page.php:135) in page.php on line 243 line 135 is three lines down in the function. 243 is where i redirect Link to comment https://forums.phpfreaks.com/topic/156521-is-it-possible-for-javascript-on-a-page-to-prevent-header-redirect/#findComment-824175 Share on other sites More sharing options...
lonewolf217 Posted May 2, 2009 Author Share Posted May 2, 2009 just mentioning here, I wasn't sure if this was a javascript error, or a php error since it is a PHP redirect, so move the post if necessary Link to comment https://forums.phpfreaks.com/topic/156521-is-it-possible-for-javascript-on-a-page-to-prevent-header-redirect/#findComment-824182 Share on other sites More sharing options...
SirXaph Posted May 2, 2009 Share Posted May 2, 2009 I think you have the function declaration in the wrong place, ie before the headers are sent. Javascript is client side, anything client side needs to be in the code AFTER the headers are sent. see also http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Link to comment https://forums.phpfreaks.com/topic/156521-is-it-possible-for-javascript-on-a-page-to-prevent-header-redirect/#findComment-824186 Share on other sites More sharing options...
lonewolf217 Posted May 2, 2009 Author Share Posted May 2, 2009 all of my javascript functions are in the <head> portion of the document . I have the several functions before this one. all of them are before any PHP code is started, but when my validation script comes here, shouldn't it process the PHP validation and redirect before sending any javascript to the client ? I have read the sticky, many times Link to comment https://forums.phpfreaks.com/topic/156521-is-it-possible-for-javascript-on-a-page-to-prevent-header-redirect/#findComment-824189 Share on other sites More sharing options...
kenrbnsn Posted May 2, 2009 Share Posted May 2, 2009 Please show us the PHP that comes before this section of your code. My best guess is that you have an unterminated string in your PHP code that starts with a single quote. The single quote that starts the case statement is terminating that string and the rest of the case string is output to the browser. The reason commenting the code out doesn't work is that the single quote is still there and the PHP interpreter is looking for it. Ken Link to comment https://forums.phpfreaks.com/topic/156521-is-it-possible-for-javascript-on-a-page-to-prevent-header-redirect/#findComment-824213 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.