Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 08-21-2011, 02:43 PM
just.b.jealous just.b.jealous is offline
 
Join Date: Aug 2009
Location: Middle of no where.
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default In need of a bit of help.. PHP/MySQL related

I've hit a wall and I'm in need of a bit of help. I think it's in more in the way of PHP/SQL/JS,.. meaning I need to use those instead of vbulletin be able to do it. I think. First let me explain what I'm trying to do..

First off, I'm on a non-vbulletin page- I'm just to have a link that takes you to a 'email us' that is only clickable by your IP address twice every hour. I'm hosting an hourly contest allowing 2 entries per hour, but am having trouble on finding how to restrict the link after the 2 clicks. Also- members are not required to be logged in..

I would think I'd have to have a SQL table for IP compered to link? Record amount into table as well as time/date?
Reply With Quote
  #2  
Old 08-21-2011, 03:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You mean two clicks per hour on the clock, so for instance they click twice at 1:59 then twice at 2:01, but not again until 3:00? Then yeah, I think I'd make a table with ip, time of last click, count this hour, and total count columns. Updating is a little tricky since you could get two or more near-simultaneous clicks from the same ip, so a "read, check the value, write a new record" sequence could end up with unexpected results.

You probably know that more than one user could appear to come from the same ip, and one user can come from multiple ips, so it can be a problem trying to use an ip address to award the prize (like if two users clicked from the same ip, who wins?). Not to mention the fact that if they don't have to be logged in you have to do the matching of user to ip somehow.
Reply With Quote
  #3  
Old 08-21-2011, 04:06 PM
just.b.jealous just.b.jealous is offline
 
Join Date: Aug 2009
Location: Middle of no where.
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

More or less- using it as a safe guard from users-overclicking. Our site doesn't have problems with bots or anything. Also helps filter unneeded mail.

Could you (well do you mind) helping me with what code I would need to accomplish this? I could read from the code what tables would need to be created- I just need help with actually implementing the checks on the page and what not... Total newb- yeah I know. Oh and I know the ins and out of my hosting/cpanel so you wouldn't have to hold my hand the whole way

--------------- Added [DATE]1313947385[/DATE] at [TIME]1313947385[/TIME] ---------------

I've just been told about trying:

Code:
select count(*) as last_hour_clicks
from table 
where ip_address = inet_aton('x.y.z.k') and click_time >= now() - interval 1 hour
But yeah- I'm not to sure what to actually do with it,..


My coding where it needs to be implementing is simple- just not sure how to wrap myself around it- and I'm even unsure of the guys tables, lol now that I'm looking at that code again- how's it even enter the persons last details, wthm. ^.^

Code:
<div class="newest-item">
	<div class="newest-img">
		<img src="uploads/3.png" alt="Giveaway" width="120" height="120"/>
	</div>
	<div class="newest-desc"><p>Plastic Chair</p></div>
		<a class="add-cart" href="./forms/1.html" title="Enter for you chance to win!"><span>Enter Email</span></a>
	</div> 
</div>
Reply With Quote
  #4  
Old 08-21-2011, 04:27 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by just.b.jealous View Post
I've just been told about trying:....
Yeah, I can see that. That's a little different because it checks for two clicks in any given hour period, not just hours by the clock. And I guess it just involves appending records to the table, which is good. The vbulletin "views" counting works that way - there's a process that runs hourly to roll up the counts into another table and clear the table with the records.

Was that someone here? To be honest, while I could come up with something that would work, I'm not really a database person.
Reply With Quote
  #5  
Old 08-21-2011, 04:33 PM
just.b.jealous just.b.jealous is offline
 
Join Date: Aug 2009
Location: Middle of no where.
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No it came off stackoverflow but lacked any other explanation other then- yeah I'd use this. How? Which way? Where's it go? Does it need tables? How do I get info inserted? I'm stumblin' around in the dark ^.^.

You said:
"That's a little different because it checks for two clicks in any given hour period"

That would work perfect but how do I actually use it?
Reply With Quote
  #6  
Old 08-21-2011, 04:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, with that scheme you'd have one table with just ip and time, and when someone clicked you'd do the check then if it passes, append to the table. I just reread your first post and now I realize that you don't want to count up total clicks there or use it to award the prize, just to control how often someone clicks (you *did* say that before...).

I don't know exactly how your "email us" page works, so I'm not sure where to tell you to put the check. If you're submitting a form you could check when the form is submitted. If you're just trying to control access to that page you could have a php script that does the check and either displays the page or an error message. (I may be able to post some actual code when I understand it a little more).
Reply With Quote
  #7  
Old 08-21-2011, 04:58 PM
just.b.jealous just.b.jealous is offline
 
Join Date: Aug 2009
Location: Middle of no where.
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for helping me out by the way--

Yup- just to control how many times they click it in an hour..

Main page is index.html- this page has the link needing to be limited... regular page with a button on it.

Code:
<div class="newest-item">
	<div class="newest-img"><img src="uploads/items-here/47-plastic-chair-3.png" alt="Plastic Chair" width="120" height="120"/></div>
	<div class="newest-desc"><p>Plastic Chair</p></div>
	<a class="add-cart" href="./forms/form1.html" title="Enter for you chance to win!"><span>Enter Email</span></a>
</div>


clicking it takes you to ./forms/form1.html (this page is a simple email form which submits/post to form1.php:

Code:
<?php
	if(isset($_POST['email'])) {
		$email_to = "contact@mail.com"; // YOUR EMAIL ADDRESS
		$email_subject = "[_ENTRY_]";    // THE EMAILS SUBJECT
		function died($error) {
			echo "We are very sorry, but there were error(s) found with the form you submitted. ";
			echo "These errors appear below.<br /><br />";
			echo $error."<br /><br />";
			echo "Please go back and fix these errors.<br /><br />";
			die();
		}
		if(!isset($_POST['email'])) {
			died('We are sorry, but there appears to be a problem with the form you submitted.');      
		}
		$email_from = $_POST['email'];
		$error_message = "";
		$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
		if(!preg_match($email_exp,$email_from)) {
			$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
		}
		if(strlen($error_message) > 0) {
			died($error_message);
		}
		$email_message = "Form details below.\n\n";
		function clean_string($string) {
			$bad = array("content-type","bcc:","to:","cc:","href");
			return str_replace($bad,"",$string);
		}
		$email_message .= "Email: ".clean_string($email_from)."\n";
		$headers = 'From: ' . $email_from . "\r\n".'Reply-To: ' . $email_from."\r\n" . 'X-Mailer: PHP/' . phpversion();
		@mail($email_to, $email_subject, $email_message, $headers); 
?>
<!-- ############################################################################################# -->
<!-- ##################### BEG: Provide your custom HTML or use what's there ##################### -->
<!-- ############################################################################################# -->
<?php
header("Location: http://site.com/");
?>
<!-- ############################################################################################# -->
<!-- ##################### END: Provide your custom HTML or use what's there ##################### -->
<!-- ############################################################################################# -->
<?php
	}
?>
After emailing- it takes them to the homepage.
Reply With Quote
  #8  
Old 08-21-2011, 05:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alright, I have a couple more questions - are you trying to definetely keep someone from submitting more than two emails per hour? Because that's harder, once someone gets the email form page they can look at it and see what it's submitting, then bypass any checks you do before they get to the form. But if you just want to discourage the "honest" people from submitting too many times, then it's not that hard.
Reply With Quote
  #9  
Old 08-21-2011, 05:18 PM
just.b.jealous just.b.jealous is offline
 
Join Date: Aug 2009
Location: Middle of no where.
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nah, not worried about emails too, and I think I'll change the "hidden" .php and make it sorta sporadic, update the html to repoint to it. (and so on.) but I don't think it will be needed once they can't click the button more then twice an hour from the same IP. All in all it's not tooo important as the prizes are virtual items to begin with , so yeah. But man- thanks for helpin me out... I'm not sure how to connect to the DB in the file or anything really man. I'm pretty new to SQL.

--------------- Added [DATE]1313950836[/DATE] at [TIME]1313950836[/TIME] ---------------

I would assume to put some kind of check into the email form to make sure the user came from front page and didn't just go directly to the form? How would I go about that one?

--------------- Added [DATE]1313953547[/DATE] at [TIME]1313953547[/TIME] ---------------

I'd say it would be best to make the form.php do the actual checks- (not the button itself?) so no email is sent if it's failed (or even be accessed by that IP until the hour is up),- then make it so you have to be referred from the front page to the form (so they can't just click the button), Users have no idea who's being mailed- just that it's the admin. And if they're willing to go through alllll that hassle for some free virtual items- I guess they earned it, ^.^.
Reply With Quote
  #10  
Old 08-21-2011, 06:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Actually, I'm wrong again - you just need to do a check in your php file and you're OK. (To be honest, I'm being distracted by other things...). (ETA: And I just read what you added to your post above - I guess you figured out that I was wrong...).

I'm working on it now, give me a few....

one more question though: can you include your vb config.php file in the form1.php, or would you rather just set the database access info again in that file?
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 08:51 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04183 seconds
  • Memory Usage 2,260KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete