SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    A dark place in my mind
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not Finding The Error

    I have this login form, but I am not finding the error in it, help please, sometimes I am really stupid at finidng errors...

    PHP Code:
    <?php
    include('../includes/config.php');
    session_start();
    if (isset(
    $_POST['username']) && isset($_POST['password'])) {
        
    $username $_POST['username'] ;
        
    $password $_POST['password'];
        }
        
    if (
    $_GET['do'] == logout) {
        
    session_destroy();
        
    $warn "you have been logged out";
        }
    else {
            if(
    $username 'admin' && $password 'password') {
                
    header('location: main.php');
                
    $username $_SESSION['username'];
                
    $_SESSION['level'] = 1;
                }
            else {
                
    $warn "Invalid Username And/Or Password";
                }
                
            }
    ?>
    <html>
        <head>
            <title><?php echo $sitetitle?></title>
            <meta name = "robots" content = "noindex, nofollow">
            <link rel="stylesheet" href="../css/def.css">
        </head>
        <body>
            <table width = "100%" align="center" valign="top" cellpadding="5" cellspacing="5">
                <tr>
                     <td align="right" valgin="top">
                        <img src="../images/logintop.gif" alt="Core Content Management System" border="0"><br />
                        <br />
                     </td>
                </tr>
                <tr>
                    <td class="login" valign="top">
                        <div class="header" align="center"><?php echo $sitetitle?></div>
                        <form action="login.php"  method="post">
                            <input type="hidden" name="formname" value="login">
                                <table align="center">
                                    <tr>
                                        <td algin="center" class="loginform">
                                        <br>
                                        <?php echo $warn?><br />
                                        <br />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center">
                                            <table>
                                                <tr>
                                                    <td align="right">
                                                    Username:
                                                    </td>
                                                    <td>
                                                        <input style = "margin-left: 4px" type="text" name="username" size="30" maxlength="30"><br>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="right">
                                                    Password:
                                                    </td>
                                                    <td>
                                                        <input style = "margin-left: 4px" type="password" name="password" size="30" maxlength="30"><br>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td algin="right">
                                                        <input type="submit" value="Submit">
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                            </table>
                        </form>
                    </td>
                </tr>
            </table>
        </body>
    </html>
    It is not validating the username and password for some reason...

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if($username = 'admin' && $password = 'password') {
    header('location: main.php');
    $username = $_SESSION['username'];
    $_SESSION['level'] = 1;
    }
    You'll be wanting == there rather than = and the session stuff won't be happening as the header redirection is before it.
    Maybe try:
    PHP Code:
    if($username == 'admin' && $password == 'password') {
       
    $_SESSION['username'] = $username;
       
    $_SESSION['level'] = 1;
       
    header("Location: main.php");
       exit;



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
  •