View Single Post
  #1 (permalink)  
Old July 14th, 2012, 09:12 AM
podzol podzol is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How I got Chapter 1 code to work (My summary of corrections)

Hello folks, I ran into many of the common problems with the source code. I thought I would summarize the changes that I made to the file downloads in order to get things up and running. Many of these corrections come from other helpful posters here in this forum:

1. I made the changes that are in the errata. These are (as of July 14 2012):

login.php Line 21:
PHP Code:
if ($user->userId && $user->password == sha1($_POST['password'])) 
Should be

PHP Code:
if ($user->userId && $user->isActive && $user->password == sha1($_POST['password'])) 
and
forgotpass.php lines 63 and 64:

PHP Code:
$user->password $password;
$user->save(); 
Should be:
PHP Code:
$user->password sha1($password);
$user->save(); 
2. I replaced the 401.php with the file of the same name from Chapter 2.

3. main.php line 13

PHP Code:
 $user User::getById([1]); 
to
PHP Code:
$user User::getById($_SESSION['userId']); 
4. main.php line 9 removed comment slashes from
PHP Code:
include '401.php'
5. main.php line 36
replaced
HTML Code:
   <td><input type="submit" value="Save"/></td>
with
HTML Code:
   <td><input type="submit" value="Save"/>&nbsp;&nbsp;<a href="login.php?logout">LOG OUT</a></td>
6. register.php line ~88 I switched out the ineffective link verification to the email verification at around line 88, which looks like this as I entered it from the book:
PHP Code:
            // create an inactive user record
            
$u = new User();
            
$u->username $_POST['username'];
            
$u->password $password;
            
$u->emailAddr $_POST['email'];
            
$token $u->setInactive();

            
$message 'Thank you for signing up for an account! Before you' .
                
' can login you need to verfy your account. You can do so ' 
                
'by visiting <a href="YOUR FILE STRUCTURE/ch_01/public_files/verify.php?uid=' 
                
$u->userId '&token=' $token '.';
            
            if (@
mail($u->emailAddr'Activate your new account'$message))
            {                 
            
$GLOBALS['TEMPLATE']['content'] = '<p><strong>Thank you for ' .
                
'registering.</strong></p> <p>You will be receiving' .
                
' an email shortly with instructions on activating your ' .
                
'account.</p>';
               }
    
    
// there was invalid data
            
else
        {
        
$GLOBALS['TEMPLATE']['content'] .= '<p><strong>There was an ' .
            
'error sending you an activation link.</strong></p> ' .
            
' <p>Please contact the site administrator at ' .
            
'<a href="mailto:YOU@YOUREMAIL.com?subject=Boronczyk Registration">blake@blakeketchum.com</a> for ' .
            
'assistance.</p>';
              } 
I think that's all the changes that I made. I hope this helps. There may be something I forgot, but I for one, am glad to put this chapter to rest.

Last edited by podzol; July 14th, 2012 at 09:30 AM.
Reply With Quote