Jump to content
Larry Ullman's Book Forums
daddytiger

Error In (Ex1) Login.Inc.Php In Setting $_Session['User_Not_Expired']

Recommended Posts

Working my way through this the 3rd of your books, great great stuff.

 

Got to page 132 - in testing category.php, took your suggestion to test viewing page.php as guest, expired, active and noticed I was always coming up expired, even after changing date_expires field directly in users table in phpmyadmin.

 

I commented out the line (#52?):

 

if ($row['expired'] === 1) $_SESSION['user_not_expired'] = true; and set same to true, and it worked.

 

This seems to fix that line of code:

if ($row['expired'] == true) $_SESSION['user_not_expired'] = true;

 

(Same line above wouldn't even work with 3 equals/identity, e.g., === true). Am I wrong???

 

Thx again for your your great work Larry, you're the man!!

daddytiger

Share this post


Link to post
Share on other sites

Thanks for the nice words! MySQL should be returning the value true as the number 1, which is why I used === 1. However to allow for some flexibility, you could use == true, which also recognizes the fact that PHP treats 1 as being true-ish. 

Share this post


Link to post
Share on other sites

You're very welcome.

 

Interesting that it should return 1 but it doesn't. Maybe my version (5.4.3) on Wamp/Windows64 or the alignment of the stars..

 

Feel free to delete and/or repost the following if need be:

 

ERRATA:     ipn.php, line 69:

 

$q = "INSERT INTO orders (user_id, transaction_id, payment_status, payment_amount) ...

 

Should be users_id in the query to match the column name in orders table as created in your sql, yes?

 

Will it matter in later chapters which of the two is changed? (I changed the script, not the database, for now).

 

Share this post


Link to post
Share on other sites

Similar problem with lines 38-44 in ipn.php:

 

// Check for the right values:
 if ( isset($_POST['payment_status'])

&& ($_POST['payment_status'] === 'Completed')
         && ($_POST['receiver_email'] === 'seller_1281297018_biz@mac.com')
         && ($_POST['mc_gross'] === 10.00)
         && ($_POST['mc_currency']  === 'USD') ..

 

Had to change to == to make it work, noticed ipn_log.php used 2 equals signs

Share this post


Link to post
Share on other sites

Yes, it should be `users_id`. I'll get that corrected. And I'll check this other issue, too. I expect it's the 10.00 that shouldn't be === (because it'll come in as a string, not a number). Thanks for keeping me honest!

Share this post


Link to post
Share on other sites

Working my way through this the 3rd of your books, great great stuff.

 

Got to page 132 - in testing category.php, took your suggestion to test viewing page.php as guest, expired, active and noticed I was always coming up expired, even after changing date_expires field directly in users table in phpmyadmin.

 

I commented out the line (#52?):

 

if ($row['expired'] === 1) $_SESSION['user_not_expired'] = true; and set same to true, and it worked.

 

This seems to fix that line of code:

if ($row['expired'] == true) $_SESSION['user_not_expired'] = true;

 

(Same line above wouldn't even work with 3 equals/identity, e.g., === true). Am I wrong???

 

Thx again for your your great work Larry, you're the man!!

daddytiger

Thank you for your post! This has helped me to understand better what may have happened.

 

I had zero problem logging in, adding pages.  However, as you point out I did have an issue when trying to view the pages.  I was told that I had to renew (that I had expired). (BTW -  this is in relation to login.inc.php line 52 which affects category.php line 35)

However, what I did was change the comparison operator form === to == and problem fixed.  I am unsure what PHP is returning, and unsure if each version is returning something different. The PHP manual says:

 

$a == $b Equal TRUE if $a is equal to $b after type juggling.

 

$a === $b Identical TRUE if $a is equal to $b, and they are of the same type.

 

Maybe something to do with PHP casting differences in each version?  I have no idea, such a newbie here... but I am curios. My guess is one is an INT and the other a String?

 

Retrieved From:

http://php.net/manual/en/language.operators.comparison.php

Share this post


Link to post
Share on other sites

Yes, exactly. One is probably a number (of some type) and the other a string. In fact, most text transferred over the internet would be in string format. 

Share this post


Link to post
Share on other sites

The php documentation for mysqli_fetch_array indicates that the return value is, in fact, an array of strings.  Therefore if you wish to perform an identity comparison on any of the values (even numbers), you need to enclose the comparison value in quotes.  The code will work like this:

 

if ($row['expired'] === '1') $_SESSION['user_not_expired'] = true;

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...