+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Login.php

  1. #1
    Ex8roS is offline x10Hosting Member Ex8roS is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    8

    Login.php

    So i am trying to make a Register/Login system on my site. Note that i didn't write the scripts. The Registration works fine and the user info are stored in the database. But when i go to the login page i get these errors:

    PHP Code:
    Warningsession_start() [function.session-start]: Cannot send session cookie headers already sent by (output started at /home/kg/public_html/login.php:1in /home/kg/public_html/login.php on line 2

    Warning
    session_start() [function.session-start]: Cannot send session cache limiter headers already sent (output started at /home/kg/public_html/login.php:1in /home/kg/public_html/login.php on line 2 
    My original script for login.php was:

    PHP Code:
    <?php
    session_start
    ();

    $conn mysql_connect('localhost''******, '*****') or die(mysql_error());
    mysql_select_db('
    *****', $conn); 



    if(isset($_GET['
    try'])) {
     
        If(empty($_POST['
    username']) OR empty($_POST['password'])) {
     
            echo '
    Please fill in all the required fields!';
        } else {
            $username = mysql_real_escape_string($_POST['
    username']);
            $password = md5($_POST['
    password']);
     
            $query = mysql_query("SELECT id FROM login
                           WHERE username = '" . 
    $username . "' 
                           AND password = '" . 
    $password . "'
                          ") or die(mysql_error());
     
            list($user_id) = mysql_fetch_row($query);

            if(empty($user_id)) {
                echo '
    No combination of username and password found.';
            } else {
                
                $_SESSION['
    user_id'] = $user_id;
     
                header('
    locationindex.html');
            }        
        }
    }

    ?>
    After some search i was told to add ob_start(); after session_start(); and ob_end_flush(); just before the ?> tag. But that didnt work :/

    Since i am not that fond of php and my experience with it is very limited i couldnt get past this problem, although i noticed that the script isnt checking if the user is already logged in. So i tried to alter the script with the hope that if it somehow checked if the user is logged in this problem would be fixed.

    The result was that:

    PHP Code:
    <?php
    session_start
    ();
    ob_start();

    $conn mysql_connect('localhost''******''******') or die(mysql_error());
    mysql_select_db('*****'$conn); 

    if(!(isset(
    $_SESSION['user_id']))) {

    if(isset(
    $_GET['try'])) {
     
        If(empty(
    $_POST['username']) OR empty($_POST['password'])) {
     
            echo 
    'Please fill in all the required fields!';
        } else {
            
    $username mysql_real_escape_string($_POST['username']);
            
    $password md5($_POST['password']);
     
            
    $query mysql_query("SELECT id FROM login
                           WHERE username = '" 
    $username "' 
                           AND password = '" 
    $password "'
                          "
    ) or die(mysql_error());
     
            list(
    $user_id) = mysql_fetch_row($query);

            if(empty(
    $user_id)) {
                echo 
    'No combination of username and password found.';
            } else {
                
                
    $_SESSION['user_id'] = $user_id;
     
                
    header('location: index.html');
            }        
        }
    }else{
        echo 
    'You are already logged in.';
    }

    }
    ob_end_flush();
    ?>
    But it still isnt working. However it is printing the "You are already logged in" message under the errors.

    If someone doesnt mind looking into it i would appreciate it. And dont worry i will understand whatever u tell me, i have some experience with programming just not that much with php yet.

    My site is aniwalls.exofire.net. Under Constuction ofc.
    Last edited by Ex8roS; 11-19-2008 at 11:54 PM.

  2. #2
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: Login.php

    /***************Moving to Programming Help****************/
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  3. #3
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: Login.php

    are you calling login.php with another page?

  4. #4
    Ex8roS is offline x10Hosting Member Ex8roS is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    8

    Re: Login.php

    ehh i was calling it from a form in the same file (login.php). But now i changed the files so that login.php contains only php code and login.html calls the login.php through a form.

    login.html form:

    HTML Code:
    <form action="login.php?try=true" method="post" >
    
    <label for="Username">Username:</label> <input type="text" id="Username" name="username"><br>
    <br>
    <label for="Password">Password:</label> <input type="password" id="Password" name="password"><br>
    <br>
    <input type="submit" value="Login!" />
    </form>
    but now i get an extra error:

    PHP Code:
    Warningsession_start() [function.session-start]: Cannot send session cookie headers already sent by (output started at /home/kg/public_html/login.php:1in /home/kg/public_html/login.php on line 2

    Warning
    session_start() [function.session-start]: Cannot send session cache limiter headers already sent (output started at /home/kg/public_html/login.php:1in /home/kg/public_html/login.php on line 2

    Warning
    Cannot modify header information headers already sent by (output started at /home/kg/public_html/login.php:1in /home/kg/public_html/login.php on line 32 

  5. #5
    lordskid is offline x10Hosting Member lordskid is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    41

    Re: Login.php

    try to observe your character encoding try to change your file to a utf-8 or whichever you used to create the file before upload.

  6. #6
    sybregunne is offline x10Hosting Member sybregunne is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    54

    Re: Login.php

    do that if you are sure that there is no other character before your

    <?php
    session_start();

    I have read that character sets can provide those magic boxes before your file so that your session start will give an error.

  7. #7
    Ex8roS is offline x10Hosting Member Ex8roS is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    8

    Re: Login.php

    The file was saved as utf-8 and i uploaded it like that, and i made sure there were no characters or lines before <?php or aftrer ?> since i am aware of this causing a problem.

  8. #8
    mfurqanabid's Avatar
    mfurqanabid is offline x10Hosting Member mfurqanabid is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    37

    Re: Login.php

    Create a new file name login.php and paste your code in this file.

    Be sure, no space or any char before or end of the php tags (<?php ?>).

    Some times some spaces, new line or file takes this problem.

    Check it.
    Edit:
    it is due to some command like header and session cannot start after spacing or enters like
    -------------


    <?php
    session_start();
    ?>

    its

    ----------
    <?php
    session_start();
    ?>


    (----------) shows file start from here
    Last edited by mfurqanabid; 11-22-2008 at 02:58 AM. Reason: Automerged Doublepost

  9. #9
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: Login.php

    I would consider removing the ob_start and ob_end_flush functions
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  10. #10
    Ex8roS is offline x10Hosting Member Ex8roS is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    8

    Re: Login.php

    Quote Originally Posted by mfurqanabid View Post
    Create a new file name login.php and paste your code in this file.

    Be sure, no space or any char before or end of the php tags (<?php ?>).

    Some times some spaces, new line or file takes this problem.

    Check it.
    Edit:
    it is due to some command like header and session cannot start after spacing or enters like
    -------------


    <?php
    session_start();
    ?>

    its

    ----------
    <?php
    session_start();
    ?>


    (----------) shows file start from here
    Yes i have heard that this causes the problem and as i said i checked several times for blank spaces and characters. But i will do what u suggest after my site starts working since i cant access it cuz of the server move.

    Quote Originally Posted by xav0989 View Post
    I would consider removing the ob_start and ob_end_flush functions

    Well it didnt work without them either, i put them there cuz i was told that it may solve the problem.

    Anyway its not that i cant try another script but i want to get to the bottom of this.

    Is there a chance that the problem is server side (php limitations) or some files do not have the required access?
    Last edited by Ex8roS; 11-22-2008 at 08:29 PM.

+ Reply to Thread
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers