Jump to content
Larry Ullman's Book Forums

kir

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by kir

  1. Ok, I can not log in on my own site?  I have access premitted for user (myself) on go daddy data base?  I can sign in under me@example.com password testpass.  Here's my code:

    <?php
    /* This page lets people log into the site. */
     
    // Set tow variable with default values:
    $loggedin = false;
    $error = false;
     
     
    //Check if the form has been submitted:
    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
     
        // Handle for form:
        if (!empty($_POST['email']) && !empty($_POST['password'])) 
        {
            
            if ( (strtolower($_POST['email']) == 'me@example.com') && ($_POST['password'] == 'testpass') )
            {
                // Correct!
                
                    // Create the cookie
                    setcookie('Sade', 'Adu', time()+3600);
                    
                    // Indicate they are logged in:
                    $loggedin = true;
                    
            }else{ // Incorrect!
                
                    $error = 'The submitted email address and password do not match those on file!';
            }
        }else{ // Forgot a field.
                $error = 'Please make sure you enter both an email address and a passoword!';
    }
    }
        // Set the page title and include the header file:
        define('TITLE', 'Login');
        include('template/header.html');
        
        // Print an error if one exist
        if ($error)
        {
            print '<p class="error">' . $error .  '</p>';
        }
        
        // Indicate the user is logged in, or show the form:
        if ($loggedin)
        {
            
            print '<p>You are now logged in!</p>';
            
        }else{
        
            print '<h2>Login Form</h2>
            <form action="login.php" method="post">
            <p><label>Email Address <input type="text" name="email" /></label></p>
            <p><label>Password<input type="password" name="password" /></label></p>
            <p><input type="submit" name="submit" value="Log In!" /></p></form>';
        }
         include('template/footer.html');
         // Need the footer
        ?>
  2. Please help me Larry, 

    I want to get this so bad so I can move on to databases.  

     

    I have the same problem as the last person. I first tried the relative path, exactly in the book and that didn't work. So now I am trying the absolute path and it isn't working either.  I am getting the same mssg as on 325. I am using PHP 5.4. Here's my code:

    $dir = 'home/kireaton/users/';
                $file = 'home/kireaton/users/users.txt';
                
                if ($_SERVER['REQUEST_METHOD'] == 'POST')
                {
                    // Handle the form.
                    $problem = FALSE; // No problems so far.
                    // Check for each value...
                    if (empty($_POST['username']))
                    {
                        $problem = TRUE;
                        print '<p class="error">Please enter a user name!</p>';
                    }
                     if (empty($_POST['password1']))
                    {
                        $problem = TRUE;
                        print '<p class="error">Please enter a password!</p>';
                    }
                      if ($_POST['password1'] != $_POST['password2'])
                      {
                        $problem = TRUE;
                        print '<p class="error">Your password did not match your confirmed password!</p>';
                    }
                        if (!$problem)
                        { // If there were not any problems 
                            if (is_writable($file))
                            
                            { // If its writable then write it!
                              // Create the data to vbe written:
                                $subdir = time() . rand(0, 4596);
                                $data = $_POST['username'] . "\t" . md5(trim($_POST['password1']))  . "\t" . $subdir . PHP_EOL;
                              // Write the data:
                                file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
                                
                                // Create the directory
                                mkdir ($dir. $subdir);
                                 
                                // Print a mssg:
                                print '<p>You are now registered!</p>';
                            }else{
                                print '<p class="error">You could not be registered due to a system error.</p>';
                            }
                        }else{
                                 // Forgot to enter a field
                                    print '<p class="error">Please try again.</p>';
                        }
                    }else{
                      // Display the form
     
                ?>
                <form action="register.php" method="post">
                    <p>Username: <input type="text" name="username" size="20" /></p>
                    <p>Password: <input type="password" name="password1" size="20" /></p>
                    <p>ConfirmPassword: <input type="password" name="password2" size="20" /></p>
                    <input type="submit" name="submit" value="Register" />
                </form>
                <?php } ?>
            </body>
        </html>
     
×
×
  • Create New...