SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member Jacob.3336's Avatar
    Join Date
    Nov 2012
    Location
    California
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Problem with sessions

    I am working on my websites login system. But when I login it goes through all my security checks and then when it is suppose to start the session it gives me this error.

    "Cannot send session cookie - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/Site/Sign_In.php:7)"

    Here is my code
    PHP Code:
                   <?php

                session_start
    ();
            
            include 
    'Include/Database.php';
            
            
    $Mail mysql_real_escape_string(strip_tags(trim($_POST['Mail'])));
            
    $Password mysql_real_escape_string(md5(strip_tags(trim($_POST['Password']))));
        
            if (
    $Mail && $Password) {
        
                
    $Query =  mysql_query("SELECT * FROM Users WHERE Email='$Mail' AND Enabled='1'");
                
                
    $Rows_Number mysql_num_rows($Query);
                
                if(
    $Rows_Number==0) {
                
                    echo 
    '<span class="Label" style="color: #CC0000;">Username or password is incorrect</span>';
                
                }else{
                
                    while(
    $Fetch_Row mysql_fetch_assoc($Query)) 
                    {
                    
    $DB_Mail $Fetch_Row['Email'];
                    
    $DB_Password $Fetch_Row['Password'];
                    }
                    
                    if(
    $DB_Mail==$Mail && $DB_Password==$Password) {
                        
                        
    $_SESSION['User_Session'] = $DB_Mail;
                        echo 
    $_SESSION['User_Session'];
                    
                    }else{
                    
                        echo 
    '<span class="Label" style="color: #CC0000;">Username or password is incorrect</span>';
                    
                    }
                    
                }
                
            }else{
            
                echo 
    '<span class="Label" style="color: #CC0000;">Your must enter you mail and password</span>';
                
            }
                    
    ?>
    Does anybody know the problem?

  2. #2
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Try getting rid of any whitespace before the session_start() function. That error means that something has output data to the browser before you call session_start.

    On a sidenote, you don't need to use mysql_real_escape_string for your $Password variable since you MD5 it. The md5() function will only return an alpha/numeric string; so you're in no danger of SQL injection.
    Keith
    Freelance web developer
    http://www.duvalltech.com/

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As pointed by kduv above, I suspect that you have some spaces before opening PHP tag:
    PHP Code:
                   <?php
    Which should start without any spaces at the very top of your PHP script file:
    PHP Code:
    <?php
    session_start
    ();
    // then do whatever you need....
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Member Jacob.3336's Avatar
    Join Date
    Nov 2012
    Location
    California
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My code it not actually like that, it is just appearing that way on this forum.

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jacob.3336 View Post
    My code it not actually like that, it is just appearing that way on this forum.
    So are you sure that there is no white space or any output (anything html tags even <html><head> tags...) above the use of session_start()? But I am sure that there is something has gone as output before the use of session_start() function. Please look at it very carefully. Maybe you have included/required some files and those files have those spaces/output/echo/print ?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,014
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    One thing that can cause it sometimes is the presence of a BOM at the start of a script, check that you've not got a BOM at the start
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •