#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    A simple autorization system. Why Errors?


    I have write a simple autorization system in PHP but I have some mistakes in Check_login.php and in adminpanel.php.

    I dont know what mistakes I have made. could you help me, please?


    login.php

    Code:
    <form action="admin.php" method="post">
    <input type="text" name="username" id="username" /><br />
    <input type="password" name="password" id="password" /><br />
    <input type="submit" name="submit" value="Login" id="submit" /><br />
    </form>

    Check_login.php

    Code:
    <?php
    $cms_username = "vakho";
    $cms_password = "123";
    $_POST['username'];
    $_POST['password'];
    
    if($username == "" || $password == "") 
    {
    echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";
    exit();
    }
    
    if($username != $cms_username || $password != $cms_password) 
    {
    echo  "YOUR NAME OR PASSWORD IS NOT CORRECT";
    exit();
    }
    
    if($username == $cms_username && $password == $cms_password)
    {
    session_start();
    $_SESSION['cms_key'] = 'openSession';
    header("Location:AdminPanel.php");
    }
    ?>


    adminpanel.php

    Code:
    <?php
    session_start();
    if ($_SESSION['cms_key'] == "openSession")
    {
    header("Location: Check_login.php");
    }
    
    else
    {
    exit();  
    }
    ?>
    <body>
    // where I'm going to Add, edit and information
    </body>



    ERRORS:

    Code:
    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:11) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 32
    
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:11) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 32
    
    Warning: Cannot modify header information - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:11) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 34
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    The error messages specify a file and a line. That's the problem.

    The check_login.php that you've provided here is clearly not the one that your actual code is using, as line 11 of this file is a closing curly brace. Perhaps it's using a different file without you realizing it?

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0
    PHP code Knows that my User "vakho" and password "123" is correct. otherwise, if user or password is not correct the Script will write:
    echo "YOUR NAME OR PASSWORD IS NOT CORRECT"

    I change code. firstly, i wrote:
    if($username == $cms_username && $password == $cms_password)

    than:
    if($username == "" || $password == "")

    than:
    if($username != $cms_username || $password != $cms_password)

    Code:
    <?php
    $_POST['username'];
    $_POST['password'];
    $cms_username = "vakho";
    $cms_password = "123";
    
    
    if($username == $cms_username && $password == $cms_password)
    {
    session_start()
    $_SESSION['cms_key'] = 'openSession';
    header("location:Admin_panel.php");
    }
    
    if($username == "" || $password == "") 
    {
    echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";
    
    exit();
    }
    
    if($username != $cms_username || $password != $cms_password) 
    {
    echo  "USER OR PASSWORD IS NOT CORRECT";
    exit();
    }

    And now i have this ERROR:
    Code:
    Parse error: syntax error, unexpected T_VARIABLE in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 22
    line 22 is
    Code:
     $_SESSION['cms_key'] = 'openSession';


    can you tell me what hapen?
  6. #4
  7. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,555
    Rep Power
    2338
    Debugging a syntax error often means going to the line BEFORE the error and making sure it's OK. For example, on line 21:
    php Code:
    session_start()
    $_SESSION['cms_key'] = 'openSession';

    What's missing there?

    Comments on this post

    • ManiacDan agrees
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0
    Code:
    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $cms_username = "vakho";
    $cms_password = "123";
    
    
    if($username == $cms_username && $password == $cms_password)
    {
    session_start();
    $_SESSION['cms_key'] = 'openSession';
    header("location:Admin_panel.php");
    exit();
    
    }
    
    if($username == "" || $password == "") 
    {
    echo  "INPUT IS NULL. PLASE ENTER USER AND PASSWORD";
    exit();
    }
    
    if($username != $cms_username || $password != $cms_password) 
    {
    echo  "USER OR PASSWORD IS NOT CORRECT";
    exit();
    }
    ?>
    Code:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:10) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 19
    
    Warning: Cannot modify header information - headers already sent by (output started at F:\Program Files\VertrigoServ\www\admin\Check_login.php:10) in F:\Program Files\VertrigoServ\www\admin\Check_login.php on line 21
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    There is nothing syntactically wrong with this code. Are you sure this is the right file? Line 10 of this file is the session_start() call, which cannot possibly conflict with session_start(). Line 21 of this file is, again, not an output line. Are you copying and pasting the actual file you're running?

    Make session_start() the very first line of this file.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Update: If there is nothing in $_POST['username'] and you have error reporting turned on, you will get an error (which is output) before trying to call your session_start function. This will generate errors.

    Although, like I said in my last post, your error messages STILL do not match your line numbers from this file. Until we see actual, for-real code, we cannot help you.

    Session_start must be the very first thing to output information. You cannot echo, print, error, or output raw HTML before session_start is called.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Since this post has been cross posted onto two other forums, I'm closing this thread.

    In the future, read the forum rules and don't waste our time by cross-posting and pasting us fake code.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo