Jump to content
Larry Ullman's Book Forums

HartleySan

Members
  • Posts

    3047
  • Joined

  • Last visited

  • Days Won

    243

Posts posted by HartleySan

  1. Every time a new page is loaded, store the time in a session variable, and then check that it has not exceeded a certain limit since the last time a user has viewed a page. For example:

     

    function checkTimeout($timeout = 600) {
      if ($timeout !== 0 && isset($_SESSION['last_time']) && time() - $_SESSION['last_time'] > $timeout)  {
        // Log user out.
      }
      
      $_SESSION['last_time'] = time();
    }
     
    Note that the above defaults the timeout time to 10 minutes, but it can be set to whatever you want, and by passing an argument of 0, no timeout will ever occur.
  2. Antonio is right in that it is very trivial for someone to submit to your PHP script from anywhere any which way. As such, you have to assume that any text can come in any way, and you need to guard against that accordingly.

     

    If you are expecting a number, simply typecasting the submitted value as an integer or float with (int) or (float) accordingly should be more than sufficient.

    However, if you are expecting text and you are going to display that text back to users in one form or another, then you should absolutely use htmlspecialchars or whatever.

     

    As a side note, because numbers are much easier to validate and less subject to funny business, I try to make as many things number inputs as possible.

  3. kamaboko, that code snippet in your previous post is designed to handle cross-browser variances.

    Specifically, whenever an event occurs for a DOM object, the associated event listener method (i.e., function) is called, and the Event object is automatically passed to the event listener method as the first parameter.

     

    Traditionally, people call this parameter "e", "evt" or something similar (because it's the Event object), but really, you can call it whatever you want.

    Normally, that would be all you need to go about your merry way, but unfortunately, old versions of IE (<= IE8) do not support the Event object being passed to event listener methods.

     

    As such, to make your code work in all browsers, you have to check if "e" is defined or not, and if it isn't, you know you're in old IE, in which case, you can then access the Event object via window.event.

     

    Once you have the correct Event object, you then need to use that to get the correct event target, which, as you have probably guessed, has two ways of being accessed: the standard and the old IE way.

     

    The standard way is Event.target, whereas old IE is Event.srcElement. (Note that Event in the previous sentence is the same thing as "e" in the code snippet.)

     

    The last thing that might be causing you confusion is the || operator.

    The || (logical OR) operator in JS allows you to quickly get a value by first checking the value to the left of the ||. If that value exists (i.e., it's not undefined, etc.), then that value is used. Otherwise, the value to the right of || is checked for its existence.

    It's basically just a quick way of checking which value exists and assigning that to the variable.

     

    That all make sense?

  4. You need to use the move_uploaded_file function to both name the file and specify the file path for the file.

    Details on the function can be found here:

    http://php.net/manual/en/function.move-uploaded-file.php

     

    Basically, post the form, and in the PHP script that is called from the form post, used the specified values to name the file.

    For example:

    move_uploaded_file($tmp_file, "/uploads/file_{$_POST['category']}_{$_POST['class']}_{$_POST['title']}");
  5. I totally agree with you, Edward. You don't have to justify to me why you are going with one solution over another. If something saves you three months of dev time, then obviously, that's worth it, and I'd do the same thing.

     

    Also, I think the reason I am usually able to figure out a problem someone is having is because it's kind of a, "Been there, struggled with that," sort of thing. Most of the problems people have had, I've had as well, so I can usually relate, which helps a lot.

     

    Anyway, best of luck with your site, and it sounds like you're learning a lot in the process.

  6. I would just use the built-in in_array function to check whether a value has been selected or not.

    For example:

    $all_skills = some-array-with-all-of-the-possible-skills;
    $selected_skills = another-array-with-only-the-selected-skills;
    
    foreach ($all_skills as $skill) {
      echo '<option' . (in_array($skill, $selected_skills) ? ' selected="selected"' : '') . '></option>';
    }

    Of course, you need the extra markup for the option text to be displayed, and the actual select element itself, but I wanted to keep the code simple for the sake of focusing on the key point.

  7. Beltic, certainly, anything is possible, but I think it might be best to look around the web and see what other people are doing.

    Here are a few ideas:

    1. Provide more results per page.
    2. Do what Larry suggested, which is calculate the total number of pages, and then calculate the middle, or allow jumping to 2-3 pages on both sides of the current page, etc.
    3. Provide a search feature or filters that allow the user to find what they really need. If you really have so many rows that you have that many pages, no one is going to search through all of that for what they need. As such, some sort of searching/filtering is necessary, I think.

     

    Thanks.

  8. Sorry for the ultra late (and now likely useless) reply, Edward.

    There was a long period of time where I was on these forums daily (usually multiple times a day), but over the past few years, I have slowly grown out of these forums.

     

    I still love all the people here and all the help Larry has provided me with over the years, but it just feels like it's time to move on. Besides, there are still lots of great people on these forums to help out.

     

    I imagine that I'll still once every month or so stop by to look for any topics that pique my interest, but I will no longer be contributing at nearly the level I used it.

     

    Please be sure to let me know how your site is coming along though, and I will try to read up on it and respond in kind when I'm around.

    Thanks.

×
×
  • Create New...