/    Sign up×
Community /Pin to ProfileBookmark

mail every 15 min

I got the following script to let ppl send me a msg.
I thought i made it so ppl can only send me a msg, every 15 minutes, but i screwed this part up.
hope someone can fix this for me,heres the code:

[code=php]
if(isset($_POST[‘submit’])){
if($_POST[‘message’] != “” AND $_POST[‘message’] != ” “){
if(!isset($_SESSION[‘msg’])){
$_SESSION[‘msg’] = time();
$sender = $_SESSION[‘user’];
$headers = “From: $sender”;
$message = HTMLSPECIALCHARS($_POST[‘message’]);
if($_POST[‘do’] == “Report Bug”){
if(mail(“[email protected]”, “Bug Report”, $message, $headers)){
header(“Location: index.php?done=reportbug”);
}
else{
$error = “<p id=’error’>ERROR: Bug report could not be send.</p>”;
}
}
else if($_POST[‘do’] == “Msg acemo”){
if(mail(“[email protected]”, “Msg acemo”, $message, $headers)){
header(“Location: index.php?done=msgacemo”);
}
else{
$error = “<p id=’error’>ERROR: Message could not be send.</p>”;
}
}
}
else{
$current_time = time();
$last_message = $_SESSION[‘msg’];
$time_since_last_message = $current_time – $last_message;
if($time_since_last_message <= “900”){
$_SESSION[‘msg’] = time();
$sender = $_SESSION[‘user’];
$headers = “From: $sender”;
$message = HTMLSPECIALCHARS($_POST[‘message’]);
if($_POST[‘do’] == “Report Bug”){
if(mail(“[email protected]”, “Bug Report”, $message, $headers)){
header(“Location: index.php?done=reportbug”);
}
else{
$error = “<p id=’error’>ERROR: Bug report could not be send.</p>”;
}
}
else if($_POST[‘do’] == “Msg acemo”){
if(mail(“[email protected]”, “Msg acemo”, $message, $headers)){
header(“Location: index.php?done=msgacemo”);
}
else{
$error = “<p id=’error’>ERROR: Message could not be send.</p>”;
}
}
}
else{
$error = “<p id=’error’>ERROR: U have sended a msg/bug report in the last 15 minutes.</p>”;
}
}
}
else{
$error = “<p id=’error’>ERROR: Message left empty.</p>”;
}
}
[/code]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@acemoauthorDec 10.2005 — i think the bug is somewhere in here:

[code=php]
$current_time = time();
$last_message = $_SESSION['msg'];
$time_since_last_message = $current_time - $last_message;
if($time_since_last_message <= "900"){
[/code]
Copy linkTweet thisAlerts:
@chazzyDec 10.2005 — well since you're not using anything server side to keep track of the last time a user sent a message, you can't really count on the session information.
Copy linkTweet thisAlerts:
@acemoauthorDec 10.2005 — if there aint no msg send yet, it should notice that by that $_SESSION['msg'] aint set, and should set this, then when user tries to send another msg it should see that $_SESSION['msg'] is set and check the time since that, but i guess i did it wrong.
Copy linkTweet thisAlerts:
@NewZealandDec 10.2005 — Yes but just using sessions to track this is not going to work that well, What if the close the browser window or open your link in a new tab, get disconnected? the session dies, maybe a database logging their email address, ip, name and time would be better, then before you send , match the ip/name/email to the one in the databse, if the match is found then check the time, if with in specified time, print error message.
Copy linkTweet thisAlerts:
@acemoauthorDec 10.2005 — well.. the sessions thingy i made dun even works..

could someone help me fix this sessions thingy..

Then when i got this to work, i will work on sum like this for wif a database and use both.
Copy linkTweet thisAlerts:
@NewZealandDec 11.2005 — try writing in understandable english, no matter is english is your second langauge you must still no "with" and "wif" and what does "the sessions thingy i made dun even works" mean?

I really dont think just sessions will provide you with a decent system, maybe try setting a cookie with a 15minute expirey and check to see if it isset?
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 11.2005 — no matter[B] is[/B] english is your second lang[B]au[/B]ge[/QUOTE]
sorry newzealand but double check your own posts too :p
Copy linkTweet thisAlerts:
@acemoauthorDec 11.2005 — i made the script with sessions so users cant send mails more as once per 15 minute.

but i did something wrong and i cannot find what i did wrong.

i was hoping someone could help me fix this script.

ur saying sessions wont stop it because people can just close and open there browser.

they can also remove cookies, so i dont see that as a good idea.

i would like to use this script when its fixed, in combination with a database.
Copy linkTweet thisAlerts:
@Reli4ntDec 11.2005 — If it's really important then require people to login in order to message you and then simply track the time in the database.

No precaution in this world cannot be foiled but this in conjunction with sessions and cookies can provide enough of a deterrent as to make "serial messengers" a minor issue.
Copy linkTweet thisAlerts:
@acemoauthorDec 11.2005 — there already logged in when they get to send a message.
>.<

even tho this script might be totaly useless, would be nice for me to learn what i did wrong in here..
×

Success!

Help @acemo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...