PDA

View Full Version : [GUIDE/MODULE] Invite a Friend w/ CAPTCHA


Manor
09-12-2007, 03:18 PM
Thanks go out to akulion for first coming up with the original of this module.

After another posted brining up that the akulion's version didn't have a CAPTCHA verification, and, after having this module installed for only one day, having a botter attempt to use my form for illicit purposes, I decided to add a CAPTCHA functionality... and re-work the coding.

In this version I did a couple things different than akulion did.

The form does not submit to another PHP file somewhere on your server, it recurses back on itself.
Added the CAPTCHA functionality.
Added functionality to alert the webmaster of when this is used. (I'll explain how to remove this if you do not want it.)


Ok, so "how do I install it?" you ask, well, here it goes.

Install

Download and install the module adding it to any/whatever styles you have. Then, rename the js_ajax_imagereg.js.txt to js_ajax_imagereg.js. Here you're just removing the .txt extension.
Now, upload the file to the clientscript/ directory in your forums. This javascript file will not overwrite the default vbulletin file. It's needed to correct vbulletin's pathing in the javascript file.

vBulletin tries to link to the "ajax.php" file without pointing to the vBulletin directory. Basically, if your forum is located in a directory like "http://www.myhost.com/forum/" and you have the module running on a page that is located at "http://www.myhost.com/" it wouldn't be able to do a refresh on the CAPTCHA image. This javascript file fixes that by declaring the vbulletin bburl path in a snippet of JS code.

Some Assembly Required
Create a new page in CMPS named "referfriend" and include the new module as the only module on the page. This is how the module recurses back on itself. I did this so someone can't try to direct link to the PHP file.

Next, depending on how you have your CMPS page identifier set up, you'll need to create the adv_portal_referfriend template and adv_portal_referfriend_imagereg template in your style(s).

adv_portal_referfriend:

<script type="text/javascript">
function checkRFForm() {
rfname=document.getElementById('rf_name');
rftoname=document.getElementById('rf_toname');
rfemail=document.getElementById('rf_email');
rftoemail=document.getElementById('rf_toemail');
rfmsg=document.getElementById('rf_msg');
rfimage=document.getElementById('imagestamp');

if(rfemail.value.indexOf("@")==-1 || rfemail.value.indexOf(".")==-1) {
alert("You must supply a valid email address!");
rfemail.focus();
return false;
}
if(rftoemail.value.indexOf("@")==-1 || rftoemail.value.indexOf(".")==-1) {
alert("You must supply a valid recpient email address!");
rftoemail.focus();
return false;
}
if(rfname.value.length < 2) {
alert("How are they gonna know who sent the email if you don't enter your name? ");
rfname.focus();
return false;
}
if(rftoname.value.length < 2) {
alert("You have to enter the recipient's name! Or atleast some cute nickname.");
rftoname.focus();
return false;
}
if(rfmsg.value.length < 2) {
alert("You need to enter a message to accompany the email!");
rfmsg.focus();
return false;
}
if(rfimage.value.length==0) {
alert("You must enter the verify the CAPTCHA image by entering the text into the box!");
rfimage.focus();
return false;
}
return true;
}
</script>
<tr>
<td class="alt1">
<form method="post" action="$vboptions/page/referfriend" onsubmit="return checkRFForm();">
<input type="hidden" name="do" value="doemail" />
<if condition="$show['rf_error']"><div class="alt2">$rf_err</div></if>

<div align="center">
Your Name<br />
<input type="text" name="name" id="rf_name" class="bginput" value="<if condition="$name!=='Unregistered'">$name</if>"><br />

Your Email<br />
<input type="text" name="email" id="rf_email" class="bginput" value="$email"><br />

Your Friend's Name<br />
<input type="text" name="toname" id="rf_toname" class="bginput" value="$toname"><br />

Friend's Email<br />
<input type="text" name="toemail" id="rf_toemail" class="bginput" value="$toemail"><br />

Your Message<br />
<textarea name="msg" id="rf_msg" rows=5 cols=20 class="bginput">$msg</textarea><br />

$imagereg
</div>
</td>
</tr>
<tr>
<td align="center" class="alt2">
<input type=submit value='Send' class="bginput" onclick="return checkRFForm();">
</td>
</tr>
</form>

[B]adv_portal_referfriend_imagereg:

<div class="thead" style="margin-left: -10px; margin-right: -10px;">
<legend>$vbphrase[image_verification]</legend>
</div>

Please enter the four letters or digits that appear in the image below. <br />
<img id="progress_imagereg" style="display: none; float:$stylevar[right]" src="$stylevar[imgdir_misc]/progress.gif" alt="" />
<center><input id="imagestamp" type="text" class="bginput" name="imagestamp" size="6" maxlength="6" /></center>
<input id="imagehash" type="hidden" name="imagehash" value="$imagehash" />

<center>
<img id="imagereg" src="image.php?$session[sessionurl]type=regcheck&amp;imagehash=$imagehash" alt="$vbphrase[registration_image]" width="150" height="50" border="0" /><br />
<span id="refresh_imagereg" style="display:none"><a href="#">$vbphrase[refresh_image]</a></span>
</center>
<script type="text/javascript" src="clientscript/js_ajax_imagereg.js?v=$vboptions[simpleversion]"></script>
<script type="text/javascript">
<!--

bburl = '$vboptions/';

vB_AJAX_ImageReg_Init();
//-->
</script>


Example:
On my site I have .htaccess set up to handle CMPS. So, when a browser is pointed to "http://www.myhost.com/page/mypage" it gets pointed to "http://www.myhost.com/cmps_index.php?page=mypage" (If you're wanting to know how to set up the "/page/mypage" thing, click here (http://www.vbadvanced.com/forum/showthread.php?t=24318)).

However, if you just use the (cmps_)index.php?page=mypage scheme, then you'll need to change the form's action url in the template.

To do this, open up the template adv_portal_referfriend and find this line:
<form method="post" action="$vboptions[bburl]/page/referfriend" onsubmit="return checkRFForm();">

Change the "$vboptions[bburl]/page/referfriend" to however you have your CMPS scheme setup.
[B]NOTE: Be sure to leave the $vboptions part in there. This is crucial for the module to recurse on itself.

If you don't get this last step right, then the form will not be able to submit to the correct place.

So, that's it. Now anybody (including non-registered members) who visit your site can invite others to view that specific page.

[B]How to remove the Webmaster alert
This is actually fairly simple. Open the "referfriend.php" file in the "/modules" directory on you site. Find the line:

rfmail($vbulletin->options['webmasteremail'], "DUPLICATE: " . $subject, "Sent by: $name ($email)<br />\n" . $message, $email, $u_headers, $name);


Add // before this line. This will comment the line of code out and will not send the webmaster a copy of the email when some uses this addon.

Anyway. I hope this helps.

Cheers!

Edit:
Ok, apparently I inadvertently missed a security hole. But, it's an easy fix.

Open referfriend.php in your modules folder and search for this line of code:
if (!verify_regimage_hash($vbulletin->GPC['imagehash'], $vbulletin->GPC['imagestamp']))

And replace it with this:
if (!verify_regimage_hash($vbulletin->GPC['imagehash'], $vbulletin->GPC['imagestamp']) || !$vbulletin->userinfo['userid'])

I didn't realize it but, some botters had found a way around the CAPTCHA scheme by just botting the correct info into the imagehash. Don't ask me how, I'm into that, so...

The one downside to this is that only those registered on your site will be able to use this functionality. So, if you want anyone who visits your site, member and guest alike, then don't do this fix. :)

Tom_S
09-23-2007, 03:35 AM
Some Assembly Required
Create a new page in CMPS named "referfriend" and include the new module as the only module on the page. This is how the module recurses back on itself. I did this so someone can't try to direct link to the PHP file.
Create what type page?
Module Page?
BB Code Page?
Template Page?
Php Page?
Html Page?

Sorry...New to me

Our Sponsors
 

jay-mob
09-23-2007, 06:06 PM
there is no template adv_portal_referfriend installed with the module, there is some problem mate.

Manor
09-24-2007, 12:26 PM
Toms_S,
Sorry about that. Create a "Module" page.

jay-mob,
You have to specify a Style to install the module to, otherwise the template won't be installed. Also, the template will most likely be located in the "Custom Templates" listed in the Style Manager.

Our Sponsors
 

jay-mob
10-09-2007, 02:24 PM
Mate I have installed it like 5 times into my style, and I am stillt not able to see the template, I told you there is something wrong with it.

At least provide the template seperately!

Manor
10-10-2007, 02:55 PM
jay-mob,

I don't know what to tell you. The template IS included in the .module file. I downloaded it and installed it on a fresh install of vB and vBa CMPS, and it installed fine. Are you sure you are selecting a style:

http://i132.photobucket.com/albums/q21/josh_en/style.jpg

If so, must be something wrong. Make sure the template is listed:
http://i132.photobucket.com/albums/q21/josh_en/template-1.jpg

And, if you have multiple styles, make sure you're installing it to each style, otherwise you'll only have the template on the style you installed it to.

jay-mob
10-12-2007, 04:46 PM
First of all I do have only one style, and i have chosen the default value for the style, and I have still nothing coming up, after I have uploaded the module. And that is in the style template.

That is why I am saying that at least you can put the templates up here as well.

Manor
10-17-2007, 01:25 PM
Ok, no need to take offense, was just asking to make sure. Second, look up at the OP. I added both templates.

Hope you enjoy!

Cheers.

jay-mob
10-30-2007, 12:59 PM
oK cheers I got this sorted out, so how to I access it now?

Ok i improved your code,

Well what I did is that I put the invitation at my homepage, and as the module page is

index.php/?im=home

so instead of sending it to index.php/?im=referfriend, I am sending it to the homepage e.g. index.php/?im=home, hope that makes some sense!

Cheers mate!

basilrath
11-07-2007, 07:08 PM
little problem if anyone has answer

the whole things up and running but

it wont send any invite........................it does send the duplicate if not commented out



stranges any ideas

ps it takes to correct page ie page=referfriend as set up

christian8a
11-27-2007, 02:05 AM
any screenshots please? This sounds cool but would like to see it :)

Manor
11-28-2007, 01:15 AM
@ basilrath:
Make sure that you're putting the email address in there correctly. If that's not it, I'm sorry. I can't think of any reason why it wouldn't be working... :(

@ christian8a:
http://i132.photobucket.com/albums/q21/josh_en/invite_a_friend_screenie.jpg
Enjoy. :D

Manor
12-01-2007, 12:01 AM
Updated a security hole. See bottom of original post for details.

nyunyu
12-08-2007, 11:46 AM
Nice..thank you
Installed and works.
take a peek ---> http://www.animeheist.com

[edited]

I tried to send one invite to my other email. But no email received???

Manor
12-09-2007, 01:12 AM
Ah, I think I see what's wrong with yours. You don't link to the page created, the page in CMPS is only a way to people able to bring the information back to the script to send the email out.

Just add the module to one of your other pages and it should work. Also, you should take it out of your navigation module.

nyunyu
12-09-2007, 06:55 AM
Ah, I think I see what's wrong with yours. You don't link to the page created, the page in CMPS is only a way to people able to bring the information back to the script to send the email out.

Just add the module to one of your other pages and it should work. Also, you should take it out of your navigation module.

Manor, I dont get it..can you help me on this?
Thanks.

basilrath
12-09-2007, 12:17 PM
whats the problem with it................

set a page........with module on it and set correct path in referfriend.php

nyunyu
12-09-2007, 02:45 PM
i still cant get this to work..please anyone, can you help me..

basilrath
12-09-2007, 03:09 PM
ye but wats the exact problem

basilrath
12-09-2007, 03:24 PM
firstly make sure you made a page .......call it referfriend.

Then add the module to the referfriend page making sure its the only one on that specific page.....the ONLY one

Next as stated....... in your referfriend template change the path to whatever your path is to your referfriend page ie mine is .........http://www.tabletennistalk.co.uk/forum/index.php?pageid=referfriend
(obviously you can use /forum/index.php?pageid=referfriend in my case just make sure its correct in your template) make sure you leave ........$vboptions[bburl]

You can leave the link to your referfriend page in your nav it still works, it just takes members to the referfriend page to allow them to send a mail.

I have it set that way as you can see............HERE (http://www.tabletennistalk.co.uk/forum/interactive.php)

i also have added the "enter forums here" so when the recipient gets the invite they are taken to referfriend page but know how to enter forums etc..........

should work works for me

Manor
12-10-2007, 01:26 AM
nyunyu, the problem is that you don't have the module on a page. Having it in the navigation will only take someone to the referfriend page.

Muldvalpen2
10-07-2008, 01:36 PM
MySQL Error : Table 'crossyourlimits_se.regimage' doesn't exist

any ideas?

Manor
10-08-2008, 03:27 PM
Well, from the error message, you edited the script. Without knowing what you've changed, I can't speculate how to fix it.

Muldvalpen2
10-08-2008, 04:49 PM
the only thing I have edited was the /forumdisplay.php? display end. Othre then that I followed your installguide step by step :(