Jump to content

[SOLVED] Tricky Error


hasek522

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.