SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Skookum's Avatar
    Join Date
    Sep 2006
    Location
    Idaho
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Logistical Time Problem

    My brain is fried today.

    I have a form that once submitted sends an e-mail to someone. My problem is I do not want to get spammed so I tried setting up a 5 minute delay on the submission page. Basically after the first submission I do not want the person to submit the same form again for at least another 5 minutes.

    Here is my code.
    PHP Code:
    <?php
    require_once 'Includes/Header.php';

    session_start();

    if(
    $_SESSION['SessSemName'] == $_GET['SemName']){
    $SpamGuard = (time() - $_SESSION['TimeOut']);
    }
    else{
    $_SESSION['SessSemName'] = $_GET['SemName'];
    $_SESSION['TimeOut'] = time();
    }



    if(
    $_SESSION['SessSemName'] == $_GET['SemName'] && $SpamGuard <= 300){
        Echo 
    "<font color='White' size='+2'><b><br><br>We are sorry but it appears you have already submitted a request for more information or to register for this event in the last 5 minutes<br><br>";
        Echo 
    "Please wait for at least 5 minutes before submitting the same request<br><br>Thank you</b></font><br>";
        Echo 
    $SpamGuard;
        exit;
    }

    if(isset(
    $_GET['Registering'])){
        
    $MailSubject "Register for "$_GET['SemName'];
    }
    else{
        
    $MailSubject $_GET['SemName'];
    }

         
    $Message "Hello Example, \nMy Name is "$_POST['FName'] .". and I have a question about "$_GET['SemName'] ."\n\nYou can contact me at \n"$_POST['EMail'] ."\n"$_POST['PhoneNum'] ."\n\n User Input: \n"$_POST['QuestionBox'];
         
    $Header 'From: Seminars@Example.com';
         
    $EMailAddy 'Example@Example.com';
         
    mail($EMailAddy$MailSubject$Message$Header);    

    Echo <<<Table
    <tr align='Center'>
    <td width='100%' align='Center' bgcolor='White'>Thank you for your interest in Example Seminars <br>
    A request has been sent to a Seminar admin and they will be in touch with you shortly
    </td></tr>
    <tr>
    <td width='100%' bgcolor='White' align='Center'>
    <a href=Default.php>Home</a>
    </td>
    </tr>
    <tr>
    <td width='100%' bgcolor='White' align='Center'>
    <a href=SearchForm.php>Search</a><br>
    </td>
    </tr>

    Table;

    $_SESSION['TimeOut'] = "";

    require_once 
    'Includes/Footer.php';
    ?>
    Sorry for the simple question but for some reason I just can't wrap my mind around this yet.

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But what is the problem?

  3. #3
    SitePoint Addict Skookum's Avatar
    Join Date
    Sep 2006
    Location
    Idaho
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that when you first submit the form it is giving the error that you have already submitted the form, and then any time after that it works fine.

    I think it is because I am clearing the $_SESSION['TimeOut'] variable at the bottom of the script. And then that variable does not get set again so it will allow any number of submissions after that.

  4. #4
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    strip away $_SESSION['TimeOut'] = "" from teh buttom of the page.

  5. #5
    SitePoint Addict Skookum's Avatar
    Join Date
    Sep 2006
    Location
    Idaho
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem with removing $_SESSION['TimeOut'] = "" from the bottom is that when they first try to submit the form they get the error stating they can't submit the form again until 5 minutes has passed. And since I never clear the $_SESSION['TimeOut'] variable after they wait the alotted 5 minutes they will be able to submit the form over and over and over again without check.

  6. #6
    SitePoint Addict Skookum's Avatar
    Join Date
    Sep 2006
    Location
    Idaho
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay I think I have finally woken up today.

    Here is the solution (I think).
    PHP Code:
    <?php
    require_once 'Includes/Header.php';

    session_start();

    if(
    $_SESSION['SessSemName'] == $_GET['SemName']){
    $SpamGuard = (time() - $_SESSION['TimeOut']);
    }
    else{
    $_SESSION['SessSemName'] = $_GET['SemName'];
    $_SESSION['TimeOut'] = time();
    $SpamGuard 301;
    }



    if(
    $_SESSION['SessSemName'] == $_GET['SemName'] && $SpamGuard <= 300){
        Echo 
    "<font color='White' size='+2'><b><br><br>We are sorry but it appears you have already submitted a request for more information or to register for this event in the last 5 minutes<br><br>";
        Echo 
    "Please wait for at least 5 minutes before submitting the same request<br><br>Thank you</b></font><br>";
        Echo 
    $SpamGuard;
        exit;
    }

    if(isset(
    $_GET['Registering'])){
        
    $MailSubject "Register for "$_GET['SemName'];
    }
    else{
        
    $MailSubject $_GET['SemName'];
    }

        
    $Message "Hello Example, \nMy Name is "$_POST['FName'] .". and I have a question about "$_GET['SemName'] ."\n\nYou can contact me at \n"$_POST['EMail'] ."\n"$_POST['PhoneNum'] ."\n\n User Input: \n"$_POST['QuestionBox'];
        
    $Header 'From: Seminars@Example.com';
        
    $EMailAddy 'Example@Example.com';
        
    mail($EMailAddy$MailSubject$Message$Header);    

    Echo <<<Table
    <tr align='Center'>
    <td width='100%' align='Center' bgcolor='White'>Thank you for your interest in Example Seminars <br>
    A request has been sent to a Seminar admin and they will be in touch with you shortly
    </td></tr>
    <tr>
    <td width='100%' bgcolor='White' align='Center'>
    <a href=Default.php>Home</a>
    </td>
    </tr>
    <tr>
    <td width='100%' bgcolor='White' align='Center'>
    <a href=SearchForm.php>Search</a><br>
    </td>
    </tr>

    Table;

    $_SESSION['TimeOut'] = time();

    require_once 
    'Includes/Footer.php';
    ?>


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
  •