Jump to content
Larry Ullman's Book Forums

knot22

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by knot22

  1. Hi - While working through the ch. 2 script examples, and simultaneously working on separate a website project, I noticed a subtle difference in strings provided to require().  Here is an example:

    require ('Includes/Config.php');

    vs.

    require ('./Includes/Config.php');

    The second command contains a period and forward slash before the folder and file are stated.  As far as I can tell, the web page behaves the same no matter which string is provided to require().  What does "./" mean?  What is the purpose of prefixing the required file string with "./"?  I'm guessing it has something to do with folder structure...

     

  2. Hi,

     

    I am attempting to do the Pursue point 6 at the end of chapter 18 and seem to be stuck. How I envision executing this is as follows (also see code snippet below which shows just the relevant lines of script 18.8 plus lines that were added):

    1. in script 18.8 in the select statement add another column that gets NOW() AS NewLastLogin

    2. put $_SESSION['LastLogin'] and $_SESSION['NewLastLogin'] into separate variables

    3. calculate the time difference between the two date/time variables in step 2

    4. display to the user the last login date/time as well as the time between that date and the "new last login" date

    5. update the LastLogin column, replacing the existing value with the date/time stored in the variable from step 2 that contains the NewLastLogin date/time

     

    The part that's not working is echo $interval. It needs to show the number of days, hours, minutes, and seconds since the last login. What is the correct format to apply to get it to display this information?

     

    Thanks, knot22

    if ($e && $p) { // If everything's OK.
    // Query the database:
    $q = "SELECT UserID, FirstName, UserLevel, LastLogin, NOW() as NewLastLogin FROM Users WHERE (Email='$e' AND Pass=SHA1('$p')) AND Active IS NULL";
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
    
    if (@mysqli_num_rows($r) == 1) { // A match was made.
    
    // Register the values:
    $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC);
    mysqli_free_result($r);
    mysqli_close($dbc);
    
    //calculate difference between last login and new last login
    $o = strtotime($_SESSION['LastLogin']);
    $n = strtotime($_SESSION['NewLastLogin']);
    $old = date_create(date('Y-m-d', $o));
    $new = date_create(date('Y-m-d', $n));
    echo $o . "<br />\n" . $n . "<br />\n";
    $interval = date_diff($old, $new);
    echo $interval->format('%R%a days') . "<br />";
    

×
×
  • Create New...