Results 1 to 5 of 5

Thread: Login Code Error

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Login Code Error

    hey, i have been working on getting a login script working, but always get an error. Here is my code:
    PHP Code:
    <?php

    if (($_POST['username']=="")) {

        echo
    "
        <html>
        <title>Login Page</title>
        <body>
        Please fill out the form below to acces that page
        <form method=\"post\" action=\"process.php\">
        Username: <input type=\"text\" name=\"username\" />
        <br />
        Password: <input type=\"text\" name=\"password\" />
        <br />
        <input type=\"button\" value=\"Submit\" />
        </form>
        </body>
        </html>"
    ;
        
    } else {
        
    $username $_POST['username'];
        
    $passowrd $_POST['password'];
            
    session_start();    
        if (
    $username == "kyle" && $password == "price") {
            
    $permission == "yes"
        
        
    $username $_POST['username'];
        
    session_register("permission");   
        
    session_register("username"); 
        
        if (
    $permission == "yes") {
        
            echo
    "
            <html>
            <title>Login Page</title>
            <body>
            You are now logged in, feel free to navigate the protected pages
            <br />
            <a href=\"page1.html\">Page 1</a>
            <br />
            <a href=\"page2.html\">Page 2</a>
            </body>
            </html>"
    ;
        } else {
        echo 
    "The username or password you entered was incorrect, please retry.";
        }
    ?>
    the error i get is this "Parse error: syntax error, unexpected T_VARIABLE in /home/echodesi/public_html/testing/login/test1.php on line 27"

    I would appreciate any help

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    I've modified your code on certain locations now it works correctly. Plz compare your code with mine to find the difference

    PHP Code:
    <?php

    if ($_POST['username'] == ""
    {

        echo 
    "<html><title>Login Page</title><body>Please fill out the form below to acces that page<form method=\"post\" action=\"process.php\">sername: <input type=\"text\" name=\"username\" /><br />Password: <input type=\"text\" name=\"password\" /><br /><input type=\"submit\" value=\"Submit\" /></form></body></html>";
        

    else 
    {
        
    $username $_POST['username'];
        
    $password $_POST['password'];

        echo 
    "$username";
        echo 
    "$password<br>";
        
        
        
    session_start();    
        
        if (
    $username == "kyle" && $password == "price")
        {
            
            
    $permission "yes";
            
            
    $username $_POST['username'];
            
            
    session_register("permission");   
            
            
    session_register("username"); 
            
            echo 
    "$permission<br>";
            
            
            if (
    $permission == "yes"
            {
        
                    echo
    "<html><title>Login Page</title><body>You are now logged in, feel free to navigate the protected pages<br /><a href=\"page1.html\">Page 1</a><br /><a href=\"page2.html\">Page 2</a></body></html>";
            }
            else 
            {
                echo 
    "The username or password you entered was incorrect, please retry.";
            }
        }
    }
    ?>

    Plz note that according to your code the file name must be process.php
    --------------------------------------------------------------------------
    Problems in your code

    1.
    Posted by Titan85
    PHP Code:
    $permission == "yes" 
    This is an assignment operation you missed two things:

    (a) You need only single = for assigning a value

    (b) You missed the ; in that line

    2. The {} used in the nested if statement are not ordered some mismatch were there. I've corrected it.

    3. In your form section you used button instead of submit button.
    Last edited by codeexploiter; 09-12-2006 at 11:49 AM.

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks a lot codeex, got it all working after fixing the errors you pointed out. However, i did run into some other errors. I am new to this so I do not know what his means error is telling me:
    "Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/echodesi/public_html/testing/login/process.php:24) in /home/echodesi/public_html/testing/login/process.php on line 28

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/echodesi/public_html/testing/login/process.php:24) in /home/echodesi/public_html/testing/login/process.php on line 28
    ".

    I know it has something to do with the code on line 28 which is my session_start(); area. What I did was i actually named the code i gave before "process.php" and then used another page called "login.html" to login. Here is the code for login.html incase you need it:
    Code:
    <html>
    <title>Login Page</title>
    <body>
    Please fill out the form below to login.
    <form method="post" action="process.php">
    Username: <input type="text" name="username" />
    <br />
    Password: <input type="text" name="password" />
    <br />
    <input type="submit" value="Submit" />
    </form>
    </body>
    </html>
    Thanks again

  4. #4
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    it means you tried to send cookie and "pragma: no-cache" header after part of HTML content was sent to client (process.php, line 24- I suspect that's "echoing" of username and password, remove it): the cookie needs to be sent BEFORE anything on page (like HTML with nested PHP code).

    BTW, I see you're using nested html code in PHP, you can use alternate PHP syntax to enclose "unescaped" html content:
    Code:
    <?php if ($_POST['username'] == "") : ?>
    I'm an unescaped HTML with all the ""'s and ''s
    <?php else : ?>
    I'm another html content with unescaped ""s and ''s, <?php=$variable?> me
    <?php endif ?>
    Last edited by ItsMeOnly; 09-12-2006 at 05:14 PM.

  5. #5
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by ItsMeOnly
    it means you tried to send cookie and "pragma: no-cache" header after part of HTML content was sent to client (process.php, line 24- I suspect that's "echoing" of username and password, remove it): the cookie needs to be sent BEFORE anything on page (like HTML with nested PHP code).

    BTW, I see you're using nested html code in PHP, you can use alternate PHP syntax to enclose "unescaped" html content:
    Code:
    <?php if ($_POST['username'] == "") : ?>
    I'm an unescaped HTML with all the ""'s and ''s
    <?php else : ?>
    I'm another html content with unescaped ""s and ''s, <?php=$variable?> me
    <?php endif ?>
    Thanks man, I did that and it worked out great

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
  •