The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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? |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
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 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> |
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
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? |
#6
|
|||
|
|||
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). |
#7
|
|||
|
|||
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 } ?> |
#8
|
|||
|
|||
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.
|
#9
|
|||
|
|||
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, ^.^. |
#10
|
|||
|
|||
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? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|