Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Warning: Cannot modify header information PHP Warning(Heres How to fix)

Featured Replies

So i see this posted over and over again by users wondering how to fix the PHP warning Warning: Cannot modify header information headers already sent . So I am going to list the known causes of this warning and any other member feel free to add onto the list if i missed anything.

 

 

Known Causes/How to fix

 

  1. Having HTML output/Php echos before calling header('Location:page.html');(Call the redirect before any output or turn on output buffering)
  2. Having white space before calling session_start() can result in headers already sent warning(Remove any white space before calling session_start also note session_start must be called before any output at the top of a page)
  3. Having HTML output/Php echos before calling setcookie()(Only set cookies before any other output)

 

these are just the main 3 I can think of off the top of my head and most the time the 3 I have listed are the cause more often then not. But feel free to reply and add to the list.

Edited by webdesigner93

  • 6 months later...
  • 2 months later...
  • 1 month later...

Wow! this is really great. I'm having a hard time fixing mine, thanks a lot for this!

  • 1 month later...

MYSQL error before header location, similar to `HTML outputted before header function, but sometimes overlooked.

  • 2 months later...

I ever have this error with my joomla and wordpress, but did not success with just remove the white spaces. In joomla I just turn the send error report to off. I stil did not know what causing it. I havent try another solution. True, this somehow related to the cookies, but sometimes did not know what cookies running on the website, especially CMS website

  • 4 weeks later...
  • Author

@ - Great list of fixes.

 

It can also be whitespace before <?php or after ?>

Very true thanks for the addition to what I had said :) also if you want a quick fix you could do

if(!headers_sent()){
//Use PHP to redirect
}else{
//Use JavaScript to redirect
}
  • 1 month later...

Good tips but sometimes its a really hard to fix this error.

 

I am building a script but most of time I get this error or Invalid "}", ] String error

  • 2 years later...
  • Jo 90 locked this topic
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.