CodeIgniter Forums
Forum Submit 60 seconds time limit ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Forum Submit 60 seconds time limit ? (/showthread.php?tid=40152)



Forum Submit 60 seconds time limit ? - El Forum - 03-31-2011

[eluser]emcgfx[/eluser]
How can I force users to wait 60 seconds between sending emails. This is the code I'm using inside codeigniter controller, that doesn't seem to work for me.

contact.php = controller
Code:
function send()
{
$this->load->library('session');

$this->session->set_userdata('lastsent', microtime());

if(microtime() >= $this->session->userdata('lastsent') + 60000000)
{
// here I have all my send email code, that works.
...
$data['message'] = 'Email was sent, thank you.';
$this->load->view('contact', $data);
}
else
{
$data['message'] = 'Please wait 60 seconds.';
$this->load->view('contact', $data);
} //timeout check

} //send()



Forum Submit 60 seconds time limit ? - El Forum - 03-31-2011

[eluser]InsiteFX[/eluser]
php.net sleep Not sure if it will work with what your doing!

InsiteFX


Forum Submit 60 seconds time limit ? - El Forum - 03-31-2011

[eluser]toopay[/eluser]
You should make another function to wrapper your delay time. I think InsiteFX suggest, 'sleep()', will work for it.


Forum Submit 60 seconds time limit ? - El Forum - 03-31-2011

[eluser]exit[/eluser]
Not very nice using cookies for something like that. If you're using a database just log by ip inside that and have a date field in it.. you get the point. If you're afraid the database will be too large in size just make so that every time it inserts a new row it will also remove old rows by using the date.


Forum Submit 60 seconds time limit ? - El Forum - 03-31-2011

[eluser]JuanitoDelCielo[/eluser]
Cookie or seassion....

save now function from date helper then

Code:
if ($cokietime - now() >60 ) {
//send email
} else {
//show message
}



Forum Submit 60 seconds time limit ? - El Forum - 03-31-2011

[eluser]exit[/eluser]
If they clean their cookies you will have a problem on your hand. I suppose you can use db sessions but then we're back to a database solution again Smile