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 18
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Cannot login after register globals was switched offf

    Any way to fix this??

    Here's the form tag:

    <form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="if(q&&!q.closed)q.close();return true">

    Here is some supplemental code:

    PHP Code:
    if ($action == "logout")
    {
        
    Setcookie("logincookie[pwd]","",time() -86400);
        
    Setcookie("logincookie[user]","",time() - 86400);
        include(
    $logout_page);
        exit;
    }
    else if (
    $action == "login")
    {
        if ((
    $loginname == "") || ($password == ""))
        {
            include(
    $invalidlogin_page);
            exit;
        }
        else if (
    strcmp($user_passwords[$loginname],$password) == 0)
        {
            
    Setcookie("logincookie[pwd]",$password,time() + 86400);
            
    Setcookie("logincookie[user]",$loginname,time() + 86400);
        }
        else
        {
            include(
    $invalidlogin_page);
            exit;
        }
    }
    else
    {
        if ((
    $logincookie[pwd] == "") || ($logincookie[user] == ""))
        {
            include(
    $login_page);
            exit;
        }
        else if (
    strcmp($user_passwords[$logincookie[user]],$logincookie[pwd]) == 0)
        {
            
    Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 86400);
            
    Setcookie("logincookie[user]",$logincookie[user],time() + 86400);
        }
        else
        {
            include(
    $invalidlogin_page);
            exit;
        }
    }
    ?> 

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Put this at the top:

    PHP Code:
    $loginname $_POST['loginname'];
    $password $_POST['password']; 
    And change the last bit to this:
    PHP Code:
    if (($_COOKIE['logincookie[pwd]'] == "") || ($_COOKIE['logincookie[user]'] == ""))
        {
            include(
    $login_page);
            exit;
        }
        else if (
    $user_passwords[$_COOKIE['logincookie[user]']] == $_COOKIE['logincookie[pwd]']))
        {
            
    Setcookie("logincookie[pwd]",$_COOKIE['logincookie[pwd]'],time() + 86400);
            
    Setcookie("logincookie[user]",$_COOKIE['logincookie[user]'],time() + 86400);
        }
        else
        {
            include(
    $login_page);
            exit;
        } 
    Last edited by Mwnciau; 08-29-2007 at 01:52 AM.

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    That didn't work. I tried placing it at the top and at the top of protect.php (which is where the supplemental code was/is from)

    What else can I try?

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    oh:

    PHP Code:
    $action $_POST['action']; 
    aswell

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Still having issues

    Here's all the code:

    Form page:
    PHP Code:
    <?
    $loginname 
    $_POST['loginname'];
    $password $_POST['password'];
    $action $_POST['action'];
    ?>

    <? include("protect.php"); ?>



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
        <title></title>
        <link rel="stylesheet" href="styles.css" type="text/css">
    </head>

    <body>

    <table>
        <form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="if(q&&!q.closed)q.close();return true">
        <tr>
            <td>...</td>
        </tr>
        </form>
    </table>

    </body>
    </html>
    protect.php

    PHP Code:
    <?


    $user_passwords 
    = array (

        
    "demo" => "demo"
        
    );

    $logout_page "logout.php";

    $login_page "login.php";
     
    $invalidlogin_page "invalidlogin.php";



    if (
    $action == "logout")
    {
        
    Setcookie("logincookie[pwd]","",time() -86400);
        
    Setcookie("logincookie[user]","",time() - 86400);
        include(
    $logout_page);
        exit;
    }
    else if (
    $action == "login")
    {
        if ((
    $loginname == "") || ($password == ""))
        {
            include(
    $invalidlogin_page);
            exit;
        }
        else if (
    strcmp($user_passwords[$loginname],$password) == 0)
        {
            
    Setcookie("logincookie[pwd]",$password,time() + 86400);
            
    Setcookie("logincookie[user]",$loginname,time() + 86400);
        }
        else
        {
            include(
    $invalidlogin_page);
            exit;
        }
    }
    else
    {
        if ((
    $logincookie[pwd] == "") || ($logincookie[user] == ""))
        {
            include(
    $login_page);
            exit;
        }
        else if (
    strcmp($user_passwords[$logincookie[user]],$logincookie[pwd]) == 0)
        {
            
    Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 86400);
            
    Setcookie("logincookie[user]",$logincookie[user],time() + 86400);
        }
        else
        {
            include(
    $invalidlogin_page);
            exit;
        }
    }
    ?>

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    protect.php
    PHP Code:
    <?

    $loginname 
    $_POST['loginname'];
    $password $_POST['password'];
    $action $_POST['action']; 

    $user_passwords = array (

        
    "demo" => "demo"
        
    );

    $logout_page "logout.php";

    $login_page "login.php";
     
    $invalidlogin_page "invalidlogin.php";



    if (
    $action == "logout")
    {
        
    Setcookie("logincookie[pwd]","",time() -86400);
        
    Setcookie("logincookie[user]","",time() - 86400);
        include(
    $logout_page);
        exit;
    }
    else if (
    $action == "login")
    {
        if ((
    $loginname == "") || ($password == ""))
        {
            include(
    $invalidlogin_page);
            exit;
        }
        else if (
    strcmp($user_passwords[$loginname],$password) == 0)
        {
            
    Setcookie("logincookie[pwd]",$password,time() + 86400);
            
    Setcookie("logincookie[user]",$loginname,time() + 86400);
        }
        else
        {
            include(
    $invalidlogin_page);
            exit;
        }
    }
    else
    {
       if ((
    $_COOKIE['logincookie[pwd]'] == "") || ($_COOKIE['logincookie[user]'] == ""))
        {
            include(
    $login_page);
            exit;
        }
        else if (
    $user_passwords[$_COOKIE['logincookie[user]']] == $_COOKIE['logincookie[pwd]']))
        {
            
    Setcookie("logincookie[pwd]",$_COOKIE['logincookie[pwd]'],time() + 86400);
            
    Setcookie("logincookie[user]",$_COOKIE['logincookie[user]'],time() + 86400);
        }
        else
        {
            include(
    $login_page);
            exit;
        }
    }
    ?>

  • #7
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Still doesn't work. Anything else?

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    Define: "Still doesn't work" What is your code doing, what results do you get, a blank page? Error? Login does not work? Form does not display? Is this on a live server that you could post a link to?

    If you are getting a blank page, do a "view source" in your browser and tell us what is present.

    Also, in any case, check your web server log for errors and/or turn on full php error reporting to see if there are is anything that would explain why it is not working.
    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.

  • #9
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Sorry. I'm getting a parse error on the following line:

    else if ($user_passwords[$_COOKIE['logincookie[user]']] == $_COOKIE['logincookie[pwd]']))

    PHP Code:
    <?

    $loginname 
    $_POST['loginname'];
    $password $_POST['password'];
    $action $_POST['action']; 

    $user_passwords = array (

        
    "news" => "demo"
        
    );

    $logout_page "logout.php";

    $login_page "login.php";
     
    $invalidlogin_page "invalidlogin.php";



    if (
    $action == "logout")
    {
        
    Setcookie("logincookie[pwd]","",time() -86400);
        
    Setcookie("logincookie[user]","",time() - 86400);
        include(
    $logout_page);
        exit;
    }
    else if (
    $action == "login")
    {
        if ((
    $loginname == "") || ($password == ""))
        {
            include(
    $invalidlogin_page);
            exit;
        }
        else if (
    strcmp($user_passwords[$loginname],$password) == 0)
        {
            
    Setcookie("logincookie[pwd]",$password,time() + 86400);
            
    Setcookie("logincookie[user]",$loginname,time() + 86400);
        }
        else
        {
            include(
    $invalidlogin_page);
            exit;
        }
    }
    else
    {
       if ((
    $_COOKIE['logincookie[pwd]'] == "") || ($_COOKIE['logincookie[user]'] == ""))
        {
            include(
    $login_page);
            exit;
        }
        else if (
    $user_passwords[$_COOKIE['logincookie[user]']] == $_COOKIE['logincookie[pwd]']))
        {
            
    Setcookie("logincookie[pwd]",$_COOKIE['logincookie[pwd]'],time() + 86400);
            
    Setcookie("logincookie[user]",$_COOKIE['logincookie[user]'],time() + 86400);
        }
        else
        {
            include(
    $login_page);
            exit;
        }
    }
    ?>
    Here's the login page:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
        <title></title>
    </head>

    <body>

                <table>
                    <form method="post" action="<? echo $PHP_SELF ?>?action=login">
                    <tr>
                        <td><b>Login name:</b><br>
                        <input type="text" size="30" name="loginname"></td>
                    </tr>
                    <tr>
                        <td><b>Password:</b><br>
                        <input type="password" size="30" name="password"></td>
                    </tr>
                    <tr>
                        <td><p><? if (substr($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always link to the protected file!</p>"; } else { echo "<input class=send type=submit value=\"Login!\">"; } ?></p></td>
                    </tr>
                    </form>
                </table>        

    </body>
    </html>
    Last edited by Errica; 08-29-2007 at 05:45 PM.

  • #10
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    So, the whole parse error - Parse error: syntax error, unexpected ')' in ... tells you what the problem is. There is one extra ) on the end of that line.

    The references to $PHP_SELF in the form don't work with register globals off either. These need to be $_SERVER['PHP_SELF'] Edit: This statement applies to the last form you posted as the earlier forms are different from this one and they do already use $_SERVER...
    Last edited by CFMaBiSmAd; 08-29-2007 at 07:13 PM. Reason: qualify last statement as it appears different pieces of code are getting posted
    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.

  • #11
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    The error doesn't state an unexpected ')'

    Further, when I remove the ) at the end of that line, I go back to the same issue in the beginning...I cannot log in. Anything else? This is maddening!


    Here's the latest:

    PHP Code:
    <?

    $loginname 
    $_POST['loginname'];
    $password $_POST['password'];
    $action $_POST['action']; 

    $user_passwords = array (

        
    "news" => "demo"
        
    );

    $logout_page "logout.php";

    $login_page "login.php";
     
    $invalidlogin_page "invalidlogin.php";



    if (
    $action == "logout")
    {
        
    Setcookie("logincookie[pwd]","",time() -86400);
        
    Setcookie("logincookie[user]","",time() - 86400);
        include(
    $logout_page);
        exit;
    }
    else if (
    $action == "login")
    {
        if ((
    $loginname == "") || ($password == ""))
        {
            include(
    $invalidlogin_page);
            exit;
        }
        else if (
    strcmp($user_passwords[$loginname],$password) == 0)
        {
            
    Setcookie("logincookie[pwd]",$password,time() + 86400);
            
    Setcookie("logincookie[user]",$loginname,time() + 86400);
        }
        else
        {
            include(
    $invalidlogin_page);
            exit;
        }
    }
    else
    {
       if ((
    $_COOKIE['logincookie[pwd]'] == "") || ($_COOKIE['logincookie[user]'] == ""))
        {
            include(
    $login_page);
            exit;
        }
        else if (
    $user_passwords[$_COOKIE['logincookie[user]']] == $_COOKIE['logincookie[pwd]'])
        {
            
    Setcookie("logincookie[pwd]",$_COOKIE['logincookie[pwd]'],time() + 86400);
            
    Setcookie("logincookie[user]",$_COOKIE['logincookie[user]'],time() + 86400);
        }
        else
        {
            include(
    $login_page);
            exit;
        }
    }
    ?>

    and the login

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
        <title></title>
    </head>

    <body>

                <table>
                    <form method="post" action="<? echo $_SERVER['PHP_SELF'?>?action=login">
                    <tr>
                        <td><b>Login name:</b><br>
                        <input type="text" size="30" name="loginname"></td>
                    </tr>
                    <tr>
                        <td><b>Password:</b><br>
                        <input type="password" size="30" name="password"></td>
                    </tr>
                    <tr>
                        <td><p><? if (substr($_SERVER['PHP_SELF'],-9) == "login.php") { echo "<p>Never link directly to this file, always link to the protected file!</p>"; } else { echo "<input class=send type=submit value=\"Login!\">"; } ?></p></td>
                    </tr>
                    </form>
                </table>        

    </body>
    </html>
    Last edited by Errica; 08-29-2007 at 08:44 PM.

  • #12
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    The code in post #9 in this thread generates the error I mentioned (tested.)

    A parse error is a fatal error. Your code in post #9 never executes. Since you have removed the extra ), the code is executing now.

    I go back to the same issue in the beginning...I cannot log in.
    Telling us step by step what you do and what happens at each step is the only way for us to "see" what you see when you try this. Give more specific details of what you see.

    You have not corrected the problem I pointed out in the form with the $PHP_SELF variable.
    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.

  • #13
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Actually I did correct the problem in the form (I just inadvertently posted the wrong code). It's now corrected.

    What I mean by the same issue is that after I enter the correct username and password, the text fields (for username and password) clear out and I do not proceed. In addition the url goes from /index.php to /index.php?action=login but I'm still stuck at the login page.

  • #14
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    I've attached the files (I've removed everything extraneous). Can someone PLEASE take a look?

    Start at /edit/index.php
    Attached Files Attached Files

  • #15
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    I just looked more closely at the code in the post (will probably try it to see what it does.) However, the following line is incorrect -
    PHP Code:
    $action $_POST['action']; 
    The ?action parameter on the end of the url is a $_GET parameter. Change the above line to the following -
    PHP Code:
    $action $_GET['action']; 
    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.


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