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.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts

    errors with login script

    I'm creating a login script for something, but I'm having a few problems with it. Whenever I log in, I get errors.

    Code:
    Warning: session_register(): Cannot send session cookie - headers already sent by (output started at /home/pokethi1/public_html/pokedex/24r/php/authentication.php:1) in /home/pokethi1/public_html/pokedex/24r/php/authentication.php on line 15
    
    Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at /home/pokethi1/public_html/pokedex/24r/php/authentication.php:1) in /home/pokethi1/public_html/pokedex/24r/php/authentication.php on line 15
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/pokethi1/public_html/pokedex/24r/php/authentication.php:1) in /home/pokethi1/public_html/pokedex/24r/php/authentication.php on line 17
    Here's the authentication.php script where everything is in. I have the form for entering the username and password on a separate HTML page, but I don't think you need that.

    Code:
    <?php
    
    mysql_connect("localhost", "username", "password")or die(mysql_error());
    mysql_select_db("database")or die(mysql_error());
    
    $username=$_POST['username'];
    $password=$_POST['password'];
    
    $sql="SELECT * FROM admins WHERE username='$username' and password='$password'";
    $result=mysql_query($sql);
    
    $count=mysql_num_rows($result);
    
    if($count==1){
    session_register("username");
    session_register("password");
    header("location:login_success.php");
    }
    
    else {
    echo "<center><font size='5'>Stop trying to hack the PokÚdex!</font><br><img src='463_berobelt.jpg'>";
    }
    
    ?>
    Yes, I edited out the mysql_connect info. What's wrong with the script?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You have a space, or some other character(s) before your <?php tag at the beginning of your file.

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    53
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Try putting session_start(); at the top, Not sure if it will help
    but it's worth a try.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts
    There aren't any spaces before the <?php tag.

    I replaced <?php with <?php session_start(); and I still get the same errors.

  • #5
    New Coder
    Join Date
    Nov 2007
    Location
    St.Louis MO
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hey,

    session_start(); needs to be the second line and then instead of session_register do $_SESSION['username'] = $username; $_SESSION['password'] = $password;.
    PHP Code:
    <?php
    session_start
    ();

    mysql_connect("localhost""username""password")or die(mysql_error());
    mysql_select_db("database")or die(mysql_error());

    $username=$_POST['username'];
    $password=$_POST['password'];

    $sql="SELECT * FROM admins WHERE username='".$username."' and password='".$password."'"
    $result=mysql_query($sql);

    $count=mysql_num_rows($result);

    if(
    $count==1){
    $_SESSION['username'] = $username
    $_SESSION['password'] = $password;
    header("location:login_success.php");
    }

    else {
    echo 
    "<center><font size='5'>Stop trying to hack the PokÚdex!</font><br /><img src='/463_berobelt.jpg' alt='Berobelt' />";
    }

    ?>
    Last edited by Corey; 11-04-2007 at 06:00 AM.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    This is a pretty common problem, I have answered it a number of times in this Forum -
    My guess is that you have edited or opened/saved this file using an editor that saved it as a UTF-8 or Unicode file.

    Make sure the file is saved in ANSI/ASCII mode.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ah yes, thank you. That did the trick.


  •  

    Posting Permissions

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