Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
In a php contact, how do i limit it to one send per user
Old 08-16-2009, 03:47 PM In a php contact, how do i limit it to one send per user
Junior Talker

Posts: 4
Name: Rob
Trades: 0
In my contact form there is no database involved, the details from the user get emailed straight to me. What i want to do is put a limit so that each ip can only use the contact form once? How do i do this?
robsdabest is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-16-2009, 03:58 PM Re: In a php contact, how do i limit it to one send per user
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
There are a couple ways you could go about this.

1) Make it so that when the user clicks the 'submit' button, it creates a session. If the user attempts to click the 'submit' button again after that, the script will check and see if that user has any sessions, and if so, it won't send the message. The downside is that after a while, these sessions expire. They also create additional strain (though insignificant) for the server.

2) Make it so that when the user clicks the 'submit' button the script writes the user's IP address to a .txt file (not quite my classification of a database). If the user attempts to click the 'submit' button again after that, the script will check the .txt file for their IP address, and if it's in there, it won't send the message.

I'd recommend option 2.
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
stevej is offline
Reply With Quote
View Public Profile
 
Old 08-16-2009, 08:47 PM Re: In a php contact, how do i limit it to one send per user
Junior Talker

Posts: 4
Name: Rob
Trades: 0
Great, thanks for the reply. Im a novice when it comes to this stuff, so could you help me out a bit. Could you give me any code examples of option 2? Thanks.
robsdabest is offline
Reply With Quote
View Public Profile
 
Old 08-16-2009, 09:07 PM Re: In a php contact, how do i limit it to one send per user
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
Well, I normally don't really like giving code, because it usually keeps the learner from understanding exactly what he's doing. Have you had any previous experience with PHP? If not, it's not too hard to get up to speed fairly quickly. You can read up on php.net, which contains a full documentation on the language. And a few Google searches never really hurt anyone. It's a pretty simple project.

If I have time, maybe I can draft up a little code for you. BTW, that's a rather large 'if'.
__________________
if($stevej == "helpful") { $talkupation += $user_power; }

Last edited by stevej; 08-16-2009 at 09:08 PM..
stevej is offline
Reply With Quote
View Public Profile
 
Old 08-17-2009, 06:37 PM Re: In a php contact, how do i limit it to one send per user
Registered User

Posts: 1
Name: Mathew
Trades: 0
i'm learning PHP nowadays only, i saw your conversation of both of u, nice conversation., will u please write the code and explain me or else just put the code, me myself will try it... thankuuuuuuuuuu
smnbx is offline
Reply With Quote
View Public Profile
 
Old 08-17-2009, 08:05 PM Re: In a php contact, how do i limit it to one send per user
Junior Talker

Posts: 4
Name: Rob
Trades: 0
I havent got much php experience at all. I am having a go at trying to create the script now, ill let you know how i get on. If you could post any example code though, that would be great.
robsdabest is offline
Reply With Quote
View Public Profile
 
Old 08-17-2009, 08:17 PM Re: In a php contact, how do i limit it to one send per user
Junior Talker

Posts: 4
Name: Rob
Trades: 0
Ok, so ive got the ip addresses of users to be stored in a text file each time they submit the form. Now, how do i go about reading the file to see if their ip address is in their before the submit the form?
robsdabest is offline
Reply With Quote
View Public Profile
 
Old 08-17-2009, 08:46 PM Re: In a php contact, how do i limit it to one send per user
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Here is something really basic to give you a start. You will need write permissions set in the directory you want to create the text file for it to work.

PHP Code:
  $file 'ip_ignore_list.dat';
  
  
$enable_contact_form false;
  
  if (
file_exists($file))
  {
    
$ip_array explode(PHP_EOLtrim((string)@file_get_contents($file)));
    if (!
in_array($_SESSION['REMOTE_ADDR'], $ip_array)) $enable_contact_form true;
  }
  
  if (
$enable_contact_form) @file_put_contents($file$_SESSION['REMOTE_ADDR'] . PHP_EOLFILE_APPEND);
  
  if (isset(
$_POST['submit']) AND $enable_contact_form)
  {
    
// Process form here...
    
    
    
  

__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-18-2009, 03:26 PM Re: In a php contact, how do i limit it to one send per user
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
Sorry about not replying earlier, I've been out of town. I'd post a little code, but it looks like mgraphic has it all under control. He's a far better programmer than I am anyway.
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
stevej is offline
Reply With Quote
View Public Profile
 
Old 08-18-2009, 03:35 PM Re: In a php contact, how do i limit it to one send per user
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by stevej View Post
looks like mgraphic has it all under control. He's a far better programmer than I am anyway.
You are giving me WAY TOO MUCH credit!
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to In a php contact, how do i limit it to one send per user
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30622 seconds with 12 queries