c_pattle Posted April 10, 2011 Share Posted April 10, 2011 I'm trying to use the autoload class but am having some trouble. Here is my autoload class, function __autoload($class_name) { include("classes/" . $class_name . ".class.php"); } The problem I am having is that when I include this class at the top of this page I then keep getting this error - "Warning: Cannot modify header information - headers already sent by" whenever I try to start a session or use the "header" function but I'm not sure why that's happening because surely I haven't echoed anything yet. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/ Share on other sites More sharing options...
KevinM1 Posted April 10, 2011 Share Posted April 10, 2011 Can you show an example of how/where you're including it? Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1199788 Share on other sites More sharing options...
c_pattle Posted April 11, 2011 Author Share Posted April 11, 2011 Sure. Here is my index page <?php require_once("includes/inc_theme.php"); session_start(); include("classes/autoloadClass.class.php"); By starting the session before I include the autoload class I don't get the error anymore but I still get the error when I try to use the header function late down the page. Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1200158 Share on other sites More sharing options...
KevinM1 Posted April 11, 2011 Share Posted April 11, 2011 Does inc_theme.php render any output? Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1200171 Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2011 Share Posted April 11, 2011 Ummm. The part of the error message that states where the output is occurring at (file name and line number) would be kind of helpful in finding the output that is causing the problem. Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1200174 Share on other sites More sharing options...
c_pattle Posted April 12, 2011 Author Share Posted April 12, 2011 Sorry. If I change my index.php file to this require_once("includes/inc_theme.php"); include("classes/autoloadClass.class.php"); session_start(); Then I get these error messages. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/webemail/classes/autoloadClass.class.php:9) in /var/www/webemail/index.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/webemail/classes/autoloadClass.class.php:9) in /var/www/webemail/index.php on line 4 It's saying that the error is appearing on line 9 of my autoload class put that line doesn't exist. It only goes up to line 8. This is my autoload class again. <?php function __autoload($class_name) { include("classes/" . $class_name . ".class.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1200808 Share on other sites More sharing options...
KevinM1 Posted April 12, 2011 Share Posted April 12, 2011 'Headers already sent' errors usually indicate that you have some output being rendered before you attempted session_start, which is why I asked you if you if inc_theme.php rendered any output.... See also our clearly marked sticky topic at the top of this sub-forum: http://www.phpfreaks.com/forums/index.php?topic=37442.0 Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1200837 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2011 Share Posted April 12, 2011 You have at least one new-line character after the closing ?> tag in your autoloadClass.class.php file. Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1200844 Share on other sites More sharing options...
c_pattle Posted April 13, 2011 Author Share Posted April 13, 2011 Sorry I forgot to mention that my inc_theme.php is not outputting anything to the screen. Even when I comment out that file include I still get the error. Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1201165 Share on other sites More sharing options...
c_pattle Posted April 13, 2011 Author Share Posted April 13, 2011 Problem solved though. Thanks PFMaBiSmAd. I had a new line character after ?>. I didn't realise this would make difference though. Quote Link to comment https://forums.phpfreaks.com/topic/233297-__autoload/#findComment-1201166 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.