Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Help with User System

    Trying to set up a portal for my user system. But when I use this
    PHP Code:
    <?php
     
    include("login.php");
    ?>
    I get
    Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/index.php:15) in /home/mysite/public_html/login.php on line 47

    Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/public_html/index.php:15) in /home/mysite/public_html/login.php on line 48
    Thank You! You will be redirected
    Lines 47 & 48 of Login:
    PHP Code:
    setcookie("id"$user[id],time()+(60*60*24*5), "/""");
    setcookie("pass"$user[password],time()+(60*60*24*5), "/"""); 
    Entire login file
    PHP Code:
    <?
    oB_start
    ();
    // allows you to use cookies.
    include("config.php");
    if(
    $logged[username] && $logged[banned] ==yes)
    echo(
    "<META HTTP-EQUIV=\"Refresh\"
          CONTENT=\"0; URL=banned.php\">"
    );
    if (!
    $logged[username])
    {
    if (!
    $_POST[login])
    {
    echo(
    "<font color='white'>
    <link rel='stylesheet' type='text/css' href='style-2.css' media='screen,projection'>
    <center><form method=\"POST\">
    <table>
    <tr>
    <td align=\"right\">
    Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
    </td>
    </tr>
    <tr>
    <td align=\"right\">
    Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
    </td></tr><tr>
    <td align=\"center\">
    <input type=\"submit\" name=\"login\" value=\"Login\">
    </td></tr><tr></font>
    <td align=\"center\">
    <a href=\"register.php\" target='1'>Register Here</a>
    </td></tr></table></form></center>"
    );
    }
    if (
    $_POST[login]) {
    // the form has been submitted.  We continue...
    $username=$_POST['username'];
    $password md5($_POST[password]);
    // the above lines set variables with the submitted information.  
    $info mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
    $data mysql_fetch_array($info);
    if(
    $data[password] != $password) {
    // the password was not the user's password!
    echo "Incorrect username or password!";
    }else{
    // the password was right!
    $query mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
    $user mysql_fetch_array($query);
    // gets the user's information
    setcookie("id"$user[id],time()+(60*60*24*5), "/""");
    setcookie("pass"$user[password],time()+(60*60*24*5), "/""");
    // the above lines set 2 cookies. 1 with the user's id and another with his/her password.  
    echo ("<meta http-equiv=\"Refresh\" content=\"0; URL=../~sbdthru/index.php\"/>Thank You! You will be redirected");
    // modify the above line...add in your site url instead of yoursite.com
    }
    }
    }
    else
    {
    // we now display the user controls.
    $new mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'"); 
    $new mysql_num_rows($new);
    echo (
    "
    <link rel='stylesheet' type='text/css' href='style-2.css' media='screen,projection'>
    <center>Welcome <b>$logged[username]</b><br /></center>
       - <a href=\"editprofile.php\" target='1'>Edit Profile</a><br />
       - <a href=\"messages.php\" target='1'>Private Messages ($new New)</a><br />
       - <a href='contact.php' target='1'>Contact Admin</a><br />
       - <a href=\"logout.php\" target='1'>Logout</a><br>
    </font></body>"
    );
    if(
    $logged[level] == Admin)
    {
    echo(
    "
       - <a href='admincp.php' target='1'>Admin</a><br>
       - <a href=\"members.php\" target='1'>Member List</a><br />"
    );
    }
    }
    ?>

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I can't remember what fixes this, but it means your sending the same information twice, usually cookies is the problem on my website that causes this. Or else it's my session_start's
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • Users who have thanked masterofollies for this post:

    SBDTHRU (02-25-2010)

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by masterofollies View Post
    I can't remember what fixes this, but it means your sending the same information twice, usually cookies is the problem on my website that causes this. Or else it's my session_start's
    Figured that was the problem too, I just couldn't find out what exactly was causing it.

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Unless it's a custom function, you've misspelt oB_start and disabled your output buffering. Lowercase it: ob_start();

  • Users who have thanked MattF for this post:

    SBDTHRU (02-25-2010)

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    20
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Make sure you get rid of any whitespace. Extra spaces, unneeded empty lines can all cause the error.

    Looks like the code you pasted has a extra space before include("login.php");

  • Users who have thanked Courtney for this post:

    SBDTHRU (02-25-2010)

  • #6
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I changed the oB_start(); and tried to find any whitespace. Still have the same problem.

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You need to put that function at the top of whichever files sends the initial headers then. You're getting that error because body content has already been transmitted to the browser when you try setting the cookies. Buffer all of the output and you'll be fine.

  • #8
    New Coder
    Join Date
    Feb 2010
    Posts
    20
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Yep I agree with MattF. Relooking at it you are sending html (echo) before the header info. The header needs to be before any html or anything else is sent to be displayed.

  • #9
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    You need to put that function at the top of whichever files sends the initial headers then. You're getting that error because body content has already been transmitted to the browser when you try setting the cookies. Buffer all of the output and you'll be fine.
    Could you n00bify this? I'm still learning.

    I'm assuming you mean
    PHP Code:
    setcookie("id"$user[id],time()+(60*60*24*5), "/""");
    setcookie("pass"$user[password],time()+(60*60*24*5), "/"""); 

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Remove the ob_start(); line from login.php and put that ob_start(); line just after the opening php tag in the index.php file.

  • #11
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Remove the ob_start(); line from login.php and put that ob_start(); line just after the opening php tag in the index.php file.
    Nope, same error.

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Post your index.php.

  • #13
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Post your index.php.
    Login and everything works fine, if I just use login.php it redirects to the index and I can go as usual.

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>StakeBeast&trade;</title>
        
        <link rel="stylesheet" type="text/css" href="style.css" media="screen,projection">
    </head>
    <body>
        
    <div id="container" class="clearfix">
        
        <h1><em></em></h1>
        
        <h2></h2>
     
     <div id="content">
       <iframe src ="../~sbdthru/content.php" width="515px" height="100%" id="1">
      <p>Your browser does not support iframes.</p>
    </iframe>

                
        </div>
    <div id="nav"><?php
    ob_start
    ();
    include(
    "login.php");
    ?>
    </div>
    </div>
     
            <address>
            &copy; 2008 All Rights Reserved.
            </address>

    </body>
    </html>

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    PHP Code:
    <?php
    ob_start
    ();
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>StakeBeast&trade;</title>
        
        <link rel="stylesheet" type="text/css" href="style.css" media="screen,projection">
    </head>
    <body>
        
    <div id="container" class="clearfix">
        
        <h1><em></em></h1>
        
        <h2></h2>
     
     <div id="content">
       <iframe src ="../~sbdthru/content.php" width="515px" height="100%" id="1">
      <p>Your browser does not support iframes.</p>
    </iframe>

                
        </div>
    <div id="nav">
    <?php
    include("login.php");
    ?>
    </div>
    </div>
     
            <address>
            &copy; 2008 All Rights Reserved.
            </address>

    </body>
    </html>
    <?php
    ob_end_clean
    ();
    exit(
    ob_get_contents());
    ?>

  • #15
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    You cannot set cookies after output has begun. Place ob_start() before ANYTHING has been sent to the client.

    And function names are case-insensitive.

  • Users who have thanked kbluhm for this post:

    SBDTHRU (02-25-2010)


  •  
    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
    •