Simsonite Posted November 17, 2008 Share Posted November 17, 2008 Hi I have found another CMS tutorial however i am still having problems =( This CMS uses a cache to reduce server load however i dont think it is saving properly and when i add a new article it comes up with the error message :Warning: Cannot modify header information - headers already sent by (output started at /home/dancdoit/public_html/admin/includes/config.php:6) in /home/dancdoit/public_html/admin/article.php on line 30. Config .php only contains my MySql details to log in. Here is the complete code <?php include 'includes/config.php'; include 'includes/dbopen.php'; /* This is the directory where we store the cache file, you can change it any directory you want as long as PHP can write to it. */ $cacheDir = dirname(__FILE__) . '/cache/'; /* Generate the cache filename, the cache name is simply an underscore followed by the article id. In case this script is called without any id (i.e. we want to show the article list ) then use index.html as the cache name */ if (isset($_GET['id'])) { $cacheFile = $cacheDir . '_' . $_GET['id'] . '.html'; } else { $cacheFile = $cacheDir . 'index.html'; } /* If we found the the cache file read it and send to the client */ if (file_exists($cacheFile)) { header("Content-Type: text/html"); readfile($cacheFile); exit; } /* If the script reaches this point, then the cache file is not found. Now we fetch the info from the database */ // if no id is specified, list the available articles if(!isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT id, title FROM cmsarticles ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $content = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($id, $title) = $row; $content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n"; } $content .= '</ol>'; $title = 'Available Articles'; } else { // get the article info from database $query = "SELECT title, content FROM cmsarticles WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } include 'includes/dbclose.php'; // start output buffering ( we need the generated html // page to create the cache file ) ob_start(); ?> <html> <head> <title> <?php echo $title;?> </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699"> <tr> <td bgcolor="#FFFFFF"> <h3 align="center"><?php echo $title;?></h3> <?php echo $content;?> </td> </tr> </table> </body> </html> <?php // get the buffer $buffer = ob_get_contents(); // end output buffering, the buffer content // is sent to the client ob_end_flush(); // now we create the cache file $fp = @fopen($cacheFile, "w"); @fwrite($fp, $buffer); @fclose($fp); ?> This is line 30 header("Content-Type: text/html"); Thanks Sims Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/ Share on other sites More sharing options...
rhodesa Posted November 17, 2008 Share Posted November 17, 2008 what is the contents of config.php though? replace any private info with *****. my guess is you have an extra line after the close php tag in that file Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692161 Share on other sites More sharing options...
Simsonite Posted November 17, 2008 Author Share Posted November 17, 2008 I have edited the config.php file to get rid of that error however i am still having problems because the index.html file in the cache directory isnt updating. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692184 Share on other sites More sharing options...
rhodesa Posted November 17, 2008 Share Posted November 17, 2008 remove the @ signs from the front of your functions at the end of the script...then see if they produce any errors Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692186 Share on other sites More sharing options...
Simsonite Posted November 17, 2008 Author Share Posted November 17, 2008 When i delete the '@'s i get the error messages Warning: fopen(/home/dancdoit/public_html/admin/cache/index.html) [function.fopen]: failed to open stream: No such file or directory in /home/dancdoit/public_html/admin/article.php on line 102 Warning: fwrite(): supplied argument is not a valid stream resource in /home/dancdoit/public_html/admin/article.php on line 103 Warning: fclose(): supplied argument is not a valid stream resource in /home/dancdoit/public_html/admin/article.php on line 104 Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692190 Share on other sites More sharing options...
Simsonite Posted November 17, 2008 Author Share Posted November 17, 2008 I deleted the files in the cache folder and the error went away however the index.html file is still not updating when i add a new article to the database. Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692194 Share on other sites More sharing options...
rhodesa Posted November 17, 2008 Share Posted November 17, 2008 ok, first, add a + to the w: $fp = fopen($cacheFile, "w+"); that will create the file if id doesn't exist ...this caching method has no way of telling when the DB has been updated. you need to either check for a change, or just delete the cache file whenever you update the DB. Then when someone visits the page, it will recreate the cache file with the new info Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692199 Share on other sites More sharing options...
Simsonite Posted November 17, 2008 Author Share Posted November 17, 2008 Ok thanks i think that works however i want to make it that instead of just showing the link it shows the whole article but i cant find out how to do that. Heres the part of the code if(!isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT id, title, content FROM cmsarticles ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $content = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($id, $title) = $row; $content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n"; } $content .= '</ol>'; $title = 'Available Articles'; } else { // get the article info from database $query = "SELECT title, content FROM cmsarticles WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } include 'includes/dbclose.php'; How do i add to the second $content variable to include the content from the row 'content'? Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692275 Share on other sites More sharing options...
rhodesa Posted November 17, 2008 Share Posted November 17, 2008 Everything looks right to me...when there is no ID passed to GET, it shows the list...then when you click the link, it should show the article. are you expecting something different? Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692392 Share on other sites More sharing options...
Simsonite Posted November 18, 2008 Author Share Posted November 18, 2008 I understand how it works however i want to change it to show a preview of the article and then the title is a link to the article on its own. Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692636 Share on other sites More sharing options...
rhodesa Posted November 18, 2008 Share Posted November 18, 2008 ah, in that case: if(!isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT id, title, content FROM cmsarticles ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $content = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($id, $title, $text) = $row; $content .= "<li>\r\n"; $content .= "<a href=\"$self?id=$id\">$title</a><br />\r\n"; $content .= "<p>$text</p>\r\n"; $content .= "</li>\r\n"; } $content .= '</ol>'; $title = 'Available Articles'; } else { // get the article info from database $query = "SELECT title, content FROM cmsarticles WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } include 'includes/dbclose.php'; I had to use $text to hold the variable, as $content is already used. Does that send you in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-692922 Share on other sites More sharing options...
Simsonite Posted November 19, 2008 Author Share Posted November 19, 2008 Thatnks for your help this is great Quote Link to comment https://forums.phpfreaks.com/topic/133087-solved-more-cms-problems/#findComment-693657 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.