Wrox Programmer Forums
|
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
This is the forum to discuss the Wrox book PHP and MySQL: Create-Modify-Reuse by Timothy Boronczyk, Martin E. Psinas; ISBN: 9780470192429
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2011, 01:48 PM
Registered User
 
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit to User.php

Hello,

I'm working on CH1. I had some errors copying the code and when I was debugging verify.php I noticed the validate the user routine always returns an object regardless of whether the ID is valid or not. So I added the following to User.php:
PHP Code:
// added between lines 66 & 67
else
{
  
$user FALSE;

Just curious if anyone else had encountered this and/or if there was any benefit/drawback to adding this code?
 
Old August 25th, 2011, 01:32 AM
Authorized User
 
Join Date: Jul 2009
Posts: 77
Thanks: 4
Thanked 6 Times in 6 Posts
Default

Hi technicalknockout

You do not have to change anything in User.php.

In User.php, when you create the user object in function getById,
it gets some initial values. These values are the ones you see in
the beginning of the User class, in function __construct.
If the $user_id that gets passed into getById is not in the
database, then getById will return
a user object with these initial values. Notice the uid (userId) is null.
If the $user_id is in the database it will return the database record.


There is a problem in the verify.php file.

In verify.php, line 18, try changing this line from
PHP Code:
   if (!$user User::getById($_GET['uid'])) 
to two lines.
PHP Code:
   $user User::getById($_GET['uid']);
   if (
$user->userId == null 
It appears this if block was never getting entered,
control would go to the else block in all cases.
Now, in the else block, there is a safety net.
When you call $user->setActive you
must have a userId and token that match a corresponding
userId and token in the pending table in the database;
without this, you cannot activate the user.
This safety net explains why verify.php is working for a lot people,
even though there is a problem with the if statement above.

I hope this helps.





Similar Threads
Thread Thread Starter Forum Replies Last Post
pass user input of php to another php script iswariyas Pro PHP 5 May 6th, 2010 12:16 AM
Edit Page via PHP Bourne PHP How-To 0 April 23rd, 2007 04:16 PM
Edit User Profile - email garydarling BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 September 29th, 2006 06:58 AM
Php User functionalities codeprice PHP How-To 2 August 25th, 2004 05:30 PM
I cannot edit user details hdoldur Classic ASP Databases 0 April 3rd, 2004 10:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.