SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard bronze trophy Tailslide's Avatar
    Join Date
    Feb 2006
    Location
    Bedford, UK
    Posts
    1,687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking time taken to submit form

    Hi all - me again!

    I'm trying to check the difference in seconds between a session on a contact page:

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['time']  = time();
    ?>
    and the current time on the form processing page:

    PHP Code:
    $now time() 
    and if it's less than x amount of seconds - die() but I'm a bit lost on how to actually compare them - does that make any sense?
    Little Blue Plane Web Design
    Blood, Sweat & Rust - A Land Rover restoration project

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hey tailslide.

    As the time is in seconds since 1970, simply subtract one from the other to get the difference in seconds:
    PHP Code:
    <?php
    session_start
    ();
    if(
    array_key_exists('time'$_SESSION)){
        
    $difference time() - $_SESSION['time'];
    }else{
        
    $difference 0;
    }
    if(
    $difference 10){
        die(
    'Oy, no bots!');
    }
    That also helps filter forms submitted through other sites etc.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Wizard bronze trophy Tailslide's Avatar
    Join Date
    Feb 2006
    Location
    Bedford, UK
    Posts
    1,687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked a treat thanks!

    I'm trying to build my own reasonably secure php form (don't all fall of your chairs laughing!). I'd got as far as getting honeypot fields, checking referrers and anti-spam questions working but I thought this might be a good addition.

    Thanks!
    Little Blue Plane Web Design
    Blood, Sweat & Rust - A Land Rover restoration project

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'd got as far as getting honeypot fields, checking referrers and anti-spam questions working but I thought this might be a good addition.
    A landmine-field for bots. All thats left is a captcha-based math question and no bot can get past you (And some users too )!

    Off Topic:

    As to your sig - Nominations are over
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Post the full script when you have finished it H (not for us to laugh at but to have a look through!!)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Wizard bronze trophy Tailslide's Avatar
    Join Date
    Feb 2006
    Location
    Bedford, UK
    Posts
    1,687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh lord that's a bit scary! Can't I post some CSS instead - I'm reasonable at that!!
    Little Blue Plane Web Design
    Blood, Sweat & Rust - A Land Rover restoration project

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    lol, no.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can't I post some CSS instead
    You don't want to make us disappointed now, do you?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  9. #9
    SitePoint Wizard bronze trophy Tailslide's Avatar
    Join Date
    Feb 2006
    Location
    Bedford, UK
    Posts
    1,687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Me again!

    Having got the basic processor page working well yesterday I started to look at getting decent validation working... and ran into problems.

    It looks like I might be better off having the whole thing on the form page itself - looks like getting the validation messages working nicely would be easier that way.

    (feel free to argue though - I'm feeling my way through this as I go).

    So (finally) the question is if I use the code related to the time check Arkinstall posted then the instant I go to the form page I'm dumped out because $difference will always be less than whatever I set as I'm on the same page.

    So how do I check the time at the point of submit being pressed rather than page being loaded?

    Ta chaps!
    Little Blue Plane Web Design
    Blood, Sweat & Rust - A Land Rover restoration project


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •