hasek522 Posted July 8, 2008 Share Posted July 8, 2008 I get the following error on one of my php pages: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/brandoo8/public_html/mrsnap/comment.php:2) in /home/brandoo8/public_html/mrsnap/config.php on line 2 This page is similiar to every other page but is the only one with this error. Here is the page code: comment.php <?php include('config.php'); include('header.php'); $id = $_GET['id']; echo '<form id="form1" method="post" action="comment.php?id='.$id.'"> Your name: <input name="user" type="text" size="50" maxlength="250" /><br /> <label>Comment <textarea name="text" cols="50"></textarea> </label> <br /> <input type="submit" name="Submit" value="Submit" />'; if(isset($_POST['Submit']) && $_POST['user'] != "" && $_POST['text'] != "") { $id = $_GET['id']; $db = mysql_connect('localhost','brandoo8_Brotsky','bb226306'); mysql_select_db('brandoo8_MrSnapPHP', $db); $sql = "INSERT INTO comments (picid, name, text) VALUES (".$id.", '".$_POST['user']."', '".$_POST['text']."');"; mysql_query($sql); mysql_close($db); echo '<a href="http://mrsnap.net/picture.php?id='.$id.'">Return to Picture</a>'; } ?> <?php include('counter.php'); include('footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/ Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 post code for config.php Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584593 Share on other sites More sharing options...
anon_login_001 Posted July 8, 2008 Share Posted July 8, 2008 Check your config.php ... Be sure that session_cache_limiter() is happening BEFORE any calls to session_start() Can you show parts of the config.php (without revealing passwords, etc) ? Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584595 Share on other sites More sharing options...
hasek522 Posted July 8, 2008 Author Share Posted July 8, 2008 config.php <?php session_start(); // new one $dbhost = "localhost"; $dbuser = "brandoo8_Brotsky"; $dbpassword = "myPasswordHere"; $dbdatabase = "brandoo8_MrSnapPHP"; $config_site = "MrSnap.net"; $config_adminemail = "[email protected]"; $config_basedir = "http://mrsnap.net/"; function isLoggedIn() { if($_SESSION['USERNAME'] <> '') { return true; } else { return false; } } ?> Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584596 Share on other sites More sharing options...
hasek522 Posted July 8, 2008 Author Share Posted July 8, 2008 user-functions.php <?PHP //Include the database connection include "config.php"; //In order to work with sessions we need use session_start() session_start(); //Return true if the session is set function is_logged_in(){ return isset($_SESSION['loggedIn']); } //Check to see if they posted a value called "login" function is_logging_in(){ return isset($_POST['submit']); } function resizeImage($originalImage,$toWidth,$toHeight){ // Get the original geometry and calculate scales list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; // Recalculate new size with default ratio if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } //Function to show the login form function loginForm(){ print ' <form method="post"> <strong>Username:</strong> <input type="text" name="username" /><br /> <strong>Password:</strong> <input type="password" name="password" /><br /> <input type="submit" name="submit" value="Login" /> </form>'; } //See if the login matches a user in the database function login($username, $password){ //Clean the values of XSS and Injections $username = trim(htmlentities(strip_tags($username), ENT_QUOTES, 'UTF-8')); $password = md5(trim($password)); //Create the MySQL Query $query = 'SELECT * FROM `registered` WHERE `username` = \''.mysql_real_escape_string($username). '\' AND password = \''. mysql_real_escape_string($password). '\''; echo mysql_real_escape_string($username) . '<br />'; echo mysql_real_escape_string($password) . '<br />'; $result = mysql_query($query); //If we found 1 or more users that matched the login if(mysql_num_rows($result) > 0) { $_SESSION['loggedIn'] = true; } else { echo '<strong>Bad login!</strong><br />'; loginForm(); //here we ask the user to login again... exit; } } ?> Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584599 Share on other sites More sharing options...
anon_login_001 Posted July 8, 2008 Share Posted July 8, 2008 Ensure that there is NO WHITESPACE before the " <?php " tag at the beginning of the comment.php file. I'm still looking over it, but that's one thing to check... Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584602 Share on other sites More sharing options...
anon_login_001 Posted July 8, 2008 Share Posted July 8, 2008 The problem could be in user-functions .... where are you using that? in config.php you use session_start().... You're including config.php in user-functions.php, and then using session_start() in user-functions.php ... That is likely the culprit. Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584606 Share on other sites More sharing options...
hasek522 Posted July 8, 2008 Author Share Posted July 8, 2008 Wow the white space thing was it. Thanks to all of you so much for helping me out so fast. This is my first time on this forum and im still amazed about how helpful it has been. Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584607 Share on other sites More sharing options...
anon_login_001 Posted July 8, 2008 Share Posted July 8, 2008 Just remember to "pay it forward" when you become an elite PHP hax0r... =) Oh, and be sure to mark this thread as "Solved" Link to comment https://forums.phpfreaks.com/topic/113760-solved-tricky-error/#findComment-584612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.