PHP Coding Help...

Discussion in 'PHP' started by bessnik, Aug 24, 2009.

  1. #1
    Hello,

    I would like to request from you guys to help me with an php script if you can be so kind.

    I would like to create an php script but I dont have any Idea how to create it but I know that it is simple...

    I need to have 2 button Vote and No Vote
    But eather to Vote or not, the visitor have submit an valid email address and go through reCAPTCHA process...

    Thats all

    Can someone help me doiing this ?

    Regards
     
    bessnik, Aug 24, 2009 IP
  2. tobydawson13

    tobydawson13 Active Member

    Messages:
    645
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I may be able to help you for a small fee.
    Could you PM me some more details?
     
    tobydawson13, Aug 24, 2009 IP
  3. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #3
    yeah i can even make you complete script for a reasonable able fee - pm me your details.
     
    AdnanAhsan, Aug 24, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here's a core example of how you can do what you mentioned above. IF this is roughly what you wanted in terms of functionality, I can fix it up the rest of the way to suit your needs.

    Live Example : http://kbeezie.com/examples/jquery-recaptcha/

    Main Page (uses some JQuery for the dynamic loading effect, in your case you may submit a straight form)
    
    <?
    require_once('recaptchalib.php');
    $publickey = "your-public-key";
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Vote or No Vote</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="site.js"></script>
        <style type="text/css">
            html * { outline: none; margin: 0px; padding: 0px; }
            body { background: #fff none no-repeat 0 0; }
            #_container { width: 100%; }
            #container { width: 600px; margin: 5px auto; }
          	#error { display: none; padding: 5px; width: 400px; border: 1px solid blue; background-color: #eee; text-align: center; }
          	#error p { font-family: monospace; font-size: 16px; color: #000; text-align: center; line-height: 20px; }
          	#error a { font-family: monospace; color: blue; font-size: 14px; text-decoration: none; }
        </style>
    </head>
    <body>
    	<div id="_container">
    		<div id="container">
    			<div id="error"><p id="msg"></p><br/><a href="index.php" id="close">[Close]</a></div>
    			<form action="" method="post">
    			<input type="text" value="Valid Email" name="uemail" id="uemail"/><br/>
    			<div id="rec"><?=recaptcha_get_html($publickey);?></div>
    			<input type="button" rel="1" class="button" value="Vote"/>
    			<input type="button" rel="2" class="button" value="No Vote"/>
    			</form>
    		</div>
    	</div>
    </body>
    </html>
    
    PHP:
    The Page's Javascript (for the button actions)
    
    
    	$(document).ready(function() {
    		$('#uemail').one("focus", function(){
    			$(this).val('');
    		});	
    		$('.button').bind("click", function(e){
    			$.post("process.php", { email: $('#uemail').val(), vote: $(this).attr('rel'), recaptcha_response_field: $('#recaptcha_response_field').val(), recaptcha_challenge_field: $('#recaptcha_challenge_field').val() },
    				function(data){
    				$('#msg').html(data);
    				$('#error').fadeIn('slow');
    			});
    		});
    		$('#close').bind("click", function(e){
    			e.stopPropagation();
    			e.preventDefault();
    			$('#error').fadeOut('fast');
    			Recaptcha.reload();
    		})
    	});
    
    
    Code (markup):
    The PhP of process.php
    
    <?
    require_once('recaptchalib.php');
    $privatekey = "your-private-key";
    
    //only checks to see if its in a *@*.* format
    function isValidEmail($email){
    	return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
    }
    
    $vote = array("1" => "Vote", "2" => "No Vote" );
    
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);
    
    if (!$resp->is_valid) {
      echo "The reCAPTCHA wasn't entered correctly. Go back and try it again.<br/>(reCAPTCHA said: " . $resp->error . ")<br/><br/>";
      exit(); //if captcha failed don't bother going further
    }
    else
    {
    	echo "reCAPTCHA was entered correctly<br/>";
    }
    
    if(!(isValidEmail($_POST['email'])))
    {
    	echo "Email Address could not be validated<br/>";
    	exit(); //if email failed, don't bother going further
    }
    else
    {
    	echo "Email has been validated<br/>";
    }
    
    echo "\nYou clicked: \"".$vote["{$_POST['vote']}"]."\"";
    ?>
    
    PHP:
    That's basically it in a nutshell.
     
    Last edited: Aug 24, 2009
    kblessinggr, Aug 24, 2009 IP
  5. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #5
    KB, about your email regex.

    - eregi is deprecated since PHP 5.3.0 and will be removed in PHP 6. Best to just use preg_match with /i modifier.
    - What about .info, .museum and other long extensions?

    You may want to check out this page that does a comparison of regexes: http://fightingforalostcause.net/misc/2006/compare-email-regex.php + http://www.dominicsayers.com/isemail/

    Yes, I know in most cases the regex you currently have will suffice, but it's important to be forward looking.. With the opening up of domain extensions, we'll see alot more that are longer than 3 chars.
     
    Last edited: Aug 25, 2009
    premiumscripts, Aug 25, 2009 IP
  6. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I tried a few other regex prior to using that, even this one rather complex one and they kept throwing back false every time :p

    That first link is a rather nifty case study of various regex methods, looks like this one is the best one, it only mis-validates an extremely long email.
    
    /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?$/i
    
    Code (markup):
    I guess if you wanted to go a step further, there is this class that will actually attempt to resolve the domain's MX/A records.
    http://www.tienhuis.nl/files/email_verify_source.php
     
    Last edited: Aug 25, 2009
    kblessinggr, Aug 25, 2009 IP