Jump to content

Smashden

Members
  • Posts

    25
  • Joined

  • Last visited

Posts posted by Smashden

  1. Hello, I have a script in JS which makes that when you click on <li> shows include PHP in DIV(load after the page loads). I want to include PHP file when I click  and show it. How can I do it in AJAX? Look at me code:

    					<ul class="task-menu" style="width: 200px;">			
    						<li class="account_buttons" data-target=".option1">Create Character</li>
    						<li class="account_buttons" data-target=".option2">Delete Character</li>
    						<li class="account_buttons" data-target=".option3">Change Password</li>
    						<li class="account_buttons" data-target=".option4">Change Email</li>
    						<li class="account_buttons" data-target=".option5">Create Guild</li>					
    					</ul>
    					<script>
    						$(document).ready(function () {
    							var $targets = $('.target');
    							$('.task-menu .account_buttons').click(function () {
    								var $target = $($(this).data('target')).toggle(600);								
    								$targets.not($target).hide(800)
    							});					
    						});
    					</script>	
    

    This I have on botttom my page:

    		<div class="option1 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option1.php"); ?> -- here I want to include when I click on option1
    			<script src="javascript/option1_script.js"></script>
    		</div>
    		<div class="option2 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option2.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option2_script.js"></script>	
    		</div>
    		<div class="option3 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option3.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option3_script.js"></script>	
    		</div>
    		<div class="option4 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option4.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option4_script.js"></script>	
    		</div>
    		<div class="option5 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option5.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option5_script.js"></script>	
    		</div>	
  2. Hello, I have a script which makes that when you click on <li> shows include PHP in DIV(load after the page loads). I want to include PHP file when I click  and show it. Look at me code:

    					<ul class="task-menu" style="width: 200px;">			
    						<li class="account_buttons" data-target=".option1">Create Character</li>
    						<li class="account_buttons" data-target=".option2">Delete Character</li>
    						<li class="account_buttons" data-target=".option3">Change Password</li>
    						<li class="account_buttons" data-target=".option4">Change Email</li>
    						<li class="account_buttons" data-target=".option5">Create Guild</li>					
    					</ul>
    					<script>
    						$(document).ready(function () {
    							var $targets = $('.target');
    							$('.task-menu .account_buttons').click(function () {
    								var $target = $($(this).data('target')).toggle(600);								
    								$targets.not($target).hide(800)
    							});					
    						});
    					</script>	
    

    This I have on botttom my page:

    		<div class="option1 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option1.php"); ?> -- here I want to include when I click on option1
    			<script src="javascript/option1_script.js"></script>
    		</div>
    		<div class="option2 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option2.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option2_script.js"></script>	
    		</div>
    		<div class="option3 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option3.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option3_script.js"></script>	
    		</div>
    		<div class="option4 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option4.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option4_script.js"></script>	
    		</div>
    		<div class="option5 target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/option5.php"); ?> -- here I want to include when I click on option2
    			<script src="javascript/option5_script.js"></script>	
    		</div>	
    
  3. Hello again :(

     

    I created two captcha on my page and I have problem with second, first captcha works fine.

     

    Look on my code, what it is wrong?

    My page

    [...]		
                    <script src="javascript/recaptcha.js"></script>
    
    		<div class="character_create target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/character_create.php"); ?>
    			<script src="javascript/character_create_script.js"></script>
    		</div>
    		<div class="character_delete target" style="display: none;">
    			<hr class="account_edit">
    			<?php include ("modules/character_delete.php"); ?>
    			<script src="javascript/character_delete_script.js"></script>	
    		</div>
    [...]	
    

    recaptcha.js

    var CaptchaCallback = function(){
    	grecaptcha.render('Captcha_Character_Create', {'sitekey' : 'my_site_key'});
    	grecaptcha.render('Captcha_Character_Delete', {'sitekey' : 'my_site_key'});
    }
    

    modules/character_create.php -- here I have first captcha, this works.

     

    modules/character_delete.php -- second captcha and not works.

    [...]
    		<div><center><span class="register_label" style="font-size: 20px;">Delete Character</div></center></span>
    		<table style="padding-top: 15px">
    			<form id="form_detete_character" class="form-horizontal" action="" method="post">		                [...]			
    				<tr>
    					<td style="vertical-align: top; padding-left: 10px;">
    						<b><label class="register_label">Verification:</label></b>
    					</td>
    					<td>
    						<div id="Captcha_Character_Delete"></div>
    					</td>
    				</tr>			
    				
    				<tr>
    					<td width="30%" style="vertical-align: bot; padding-left: 10px;">
    						<div class="controls">
    							<input class="btn btn-primary" id="delete_character" type="submit" value="Delete Character">
    						</div>					
    					</td>					
    				</tr>			
    			</form>
    		</table>
    

    character_delete_script.js

    $(function(){
    
    	var form	= $('#form_detete_character');
    	var submit 	= $('#delete_character');
    	var alert	= $('.alert');
    	var alert_error	= $('.alert_error');
    	var alert_error2 = $('.alert_error2');
    
    	// validate form
    	form.validate({
    		// validation rules
    		rules: {
    
    			character_password: {
    				required: true,
    				minlength: 5,
    				maxlength: 32
    			}
    		},
    		// submit ajax request
    		submitHandler: ajaxSubmit
    	});
    
    	/**
    	* ajax submit function
    	* sending simple ajax request
    	**/
    
    	function ajaxSubmit() {
    		console.log(form.serialize());
    		$.ajax({
    			url: 'modules/account/character_delete.php',
    			type: 'POST',
    			dataType: 'json',
    			// form serialize data
    			//data: form.serialize(),
    			data: (function() {
                    formValues = form.serializeArray();
                    // add google recapture value to serlized form field values
                    formValues.push({name: 'g-recaptcha-response', value: $('.g-recaptcha-response').val()});
                return formValues; })(),	
    			
    			beforeSend: function(){
    				alert.fadeOut();
    				alert_error.fadeOut();
    				submit.val('Sending...').attr('disabled', 'disabled');
    			},
    			success: function(data){
    				if ( data.status === 'success' ) {
    					// if response status == success redirect to success page
    					alert.fadeIn();		
    					alert_error2.html('Your character was deleted.').fadeIn();		
    					setTimeout(function(){window.location = "account.php?character_deleted"} , 1500)
    				} else {
    					// not success! show error messages
    					alert.fadeIn();
    					alert_error.html(data.status).fadeIn();
    					submit.val('Delete Character').removeAttr('disabled');
    				}
    			},
    			error: function(){
    				// show error message				
    				submit.val('Delete Character').removeAttr('disabled');
    			}
    		});
    	};
    });
    

    modules/account/character_delete.php

    <?php
    [...]
    header('Content-type: application/json');
    
    function json_status($status)
    {
        echo json_encode(array('status' => $status));
    }
    
    if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
    { 
    	[...]			
    						if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))
    						{   
    							$captchaurl = "https://www.google.com/recaptcha/api/siteverify";
    										
    							// values for verifying recaptha
    							$captcha_params = array(
    								'secret'   => 'my_secret_key',
    								'response' => $_POST['g-recaptcha-response'],
    								'ip'       => $_SERVER['REMOTE_ADDR']
    							);
    
    							$curl_init = curl_init();
    							curl_setopt($curl_init, CURLOPT_URL, $captchaurl);
    							curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, 1);
    
    							// send recapture values via POST
    							curl_setopt($curl_init, CURLOPT_POST, count($captcha_params));
    							curl_setopt($curl_init, CURLOPT_POSTFIELDS, $captcha_params);
    
    							curl_setopt($curl_init, CURLOPT_SSL_VERIFYPEER, false);
    
    							$results = curl_exec($curl_init);
    							curl_close($curl_init);
    
    							$results = json_decode($results, true);
    
    							if($results['success'])
    							{										
    								if ($player->delete()){
    									$account->logAction('Deleted character '.$player->getAttr('name'));
    									json_status('success');	
    									
    								} else {
    									json_status('ERROR');
    								}								
    							} else {
    								json_status('Invalid reCAPTCHA code');
    							}           
    						} else {
    							json_status('Please re-enter your reCAPTCHA.'); 
    						}						
    	} else { 
    		json_status('You must complete all the fields.'); 
    	}
    }
    ?>
    

    And last, in section <head> I have:

    <script src="https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&render=explicit" async defer></script>
    

    I have this error: Please re-enter your reCAPTCHA.

  4. Yeah, I have this:

    03AHJ_VuvYDqg8zAe1koLOPTyLiHp222YxqldLe3lcxt-voWMubFb7F7BL--zxqWShUrxekUe3pwTLIH63GRWvdK8Po5GM-ch82FUVmR7DkLIzuwXyjYRikv0yhLdKzpKrkM-REpN8V20JGmaEdkJODnc_1nvmUitmBoDMWv2Uh5ax2zbkJP9eT0krmAE3zKvWGwDOX_VbGaarSZdN79D0nksEjmgYkPAKZOMqKqQQ1QG7ryAaiyjFVkh9NUQMeepdEsJF7FM8PPZwkhDHPy0S_9oa_d-ugRo_PbWPctO9wSk8m1KKj9a71vMyoenLf0Y_v0UCJoIG5WK3dTBXoqGhzaojNgrjWvlwL7VHMroECUqOx24sY0cAWJNyJhs2AR2IJIr06HBgH3DhayO4RPAdOS0J5353w7CWKrlF5ehmxsharT_vHUJAJTVX9WnOETM2N0f0NczX2nl9zcwM3fdqOcZZtPBHA2_ui2knvyAphX0ETTG0u0zTM0koPpbkSD_E-ne1le-DmrR74D2n2eqVTgEuPMF7Qm6WTKJCmIoEvrZllSdsS28ZyCAmDG75r21HXs7UQS2zWB7TITUIev1Nr6URL80544Bo420TOeM2PhJFcXmVgHvitUdaDhfGJ0EvBeokA2ZW6bjKGarNnSEmtplVuncMoAdRgXRFF21H2219MGB2_GvIDuFEX5xnhEIIkX_fc-4xRkOyEk2qSRQZIhNpk2PQ6otzCUUGm7IMUjfecx_wZwEIhjpXQWPNc6t2-jnsq5xSjtErvX6ES7ys4bYfjxhEw7pTIoz0kSXUnCqEtetegQJNc1xahnwu4VC-jzPNeR6Mdl7crlQv72afYNx6gxktdpNcp2P9z6w0I3hvwYLdV3-R7D4TW_eS54Wu-Bp5L-lF6UbKo9kI728MY78diKD01-HPqY6zn1cJS7VCTw9HuDUIFodccema7UVZYcasoZe40wSO0O-r9DKY_lQ1F0_0yhHghntdJdImwnNCa5-RWqInMDU
    

    when I accept captcha

  5. 			<form id="form" class="form-horizontal" action="" method="post">		
    				<tr>	
    					<td width="30%" style="vertical-align: top; padding-left: 10px;">
    						<label for="email" class="control-label">
    							<span class="register_label">Email Address:</span> <span class="required">*</span>
    						</label>
    					</td>		
    					<td width="70%">
    						<input type="text" name="email" id="email" required placeholder="Email Address">
    						<div class="register_label_info">Please enter a valid email address if we need to contact you.</div>				
    					</td>
    				</tr>
    				
    				<tr>	
    					<td width="30%" style="vertical-align: top; padding-left: 10px;">
    						<label for="account_name" class="control-label">
    							<span class="register_label">Account Name:</span> <span class="required">*</span>
    						</label>
    					</td>		
    					<td width="70%">
    						<input type="text" name="account_name" id="account_name" required placeholder="Account Name">
    						<div class="register_label_info">Account name consists of numbers 0-9 and is at least 6 characters long.</div>				
    					</td>
    				</tr>		
    
    				<tr>	
    					<td width="30%" style="vertical-align: top; padding-left: 10px;">
    						<label for="account_password" class="control-label">
    							<span class="register_label">Choose a password:</span> <span class="required">*</span>
    						</label>
    					</td>		
    					<td width="70%">
    						<input type="password" name="account_password" id="account_password" required placeholder="Password">
    						<div class="register_label_info">Password consists of letters a-z, numbers 0-9, symbols(~!@#%&;,:\^$.|?*+()) and is at least 6 characters long.</div>				
    					</td>
    				</tr>					
    
    				<tr>	
    					<td width="30%" style="vertical-align: top; padding-left: 10px;">
    						<label for="account_password2" class="control-label">
    							<span class="register_label">Repeat Password:</span> <span class="required">*</span>
    						</label>
    					</td>		
    					<td width="70%">
    						<input type="password" name="account_password2" id="account_password2" required placeholder="Repeat Password">			
    					</td>
    				</tr>				
    
    				<tr>	
    					<td width="30%" style="vertical-align: top; padding-left: 10px;">
    						<label for="rlname" class="control-label">
    							<span class="register_label">Your name:</span>
    						</label>
    					</td>		
    					<td width="70%">
    						<input type="text" name="rlname" id="rlname" required placeholder="Your name">			
    					</td>
    				</tr>	
    
    				<tr>	
    					<td width="30%" style="vertical-align: top; padding-left: 10px;">
    						<label for="location" class="control-label">
    							<span class="register_label">Your location:</span>
    						</label>
    					</td>		
    					<td width="70%">
    						<input type="text" name="location" id="location" required placeholder="Your location">					
    					</td>
    					
    				</tr>
    				
    				<tr>	
    					<td width="30%" style="vertical-align: top; padding-left: 10px;">
    					</td>					
    					<td>
    						<label class="register_label_info"><span class="required">*</span> Required fields</label>
    					</td>				
    				</tr>				
    				
    				<tr>
    					<td style="vertical-align: top; padding-left: 10px;">
    						<b><label class="register_label">Verification:</label></b>
    					</td>
    					<td>
    						<div class="g-recaptcha" data-sitekey="my site key"></div>
                                                    <script src='https://www.google.com/recaptcha/api.js'></script>
    					</td>
    				</tr>
    								
    	
    				<tr>		
    					<td colspan="2">
    						<label for="location" class="control-label">
    							<div style="overflow-y: scroll; height: 200px;"><?php echo htmlspecialchars(@file_get_contents('documents/server_rules.txt'));?></div>						
    						</label>	
    					</td>						
    				</tr>	
    
    				<tr>
    					<td width="30%" style="vertical-align: bot; padding-left: 10px;">
    						<div class="controls">
    							<input id="rules_check" type="checkbox" onclick="onRulesCheck(this)"/>
    							<span class="register_label"><b>I agree with server rules</b></span>
    						</div>					
    					</td>					
    				</tr>
    				
    				<tr>
    					<td width="30%" style="vertical-align: bot; padding-left: 10px;">
    						<div class="controls">
    							<input class="btn btn-primary" id="sign_up" disabled="disabled" type="submit" value="Sign Up!">
    						</div>					
    					</td>					
    				</tr>
    			</form>
    

    This is my form, I have g-recaptcha here. In console I have only 

    email=&account_name=&account_password=&account_password2=&rlname=&location=

     

    so g-recaptcha-response is no send to PHP. And I don't know how to fix it.

  6. Hello, during testing reCAPTCHA from google I am having trouble that I can not fix it.

    I add:

    <td>
        <div class="g-recaptcha" data-sitekey="my site key"></div>
        <script src="https://www.google.com/recaptcha/api.js"></script>
    </td>
    

    to my form. 

    And this:

    function json_status($status)
    {
    	echo json_encode(array('status' => $status));
    }
    
    if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
    {
    	$captcha = $_POST['g-recaptcha-response'];
    	if(!empty($captcha))
    	{	
    		$google_url = "https://www.google.com/recaptcha/api/siteverify";
    		$secret = 'my secret key';
    		$ip = $_SERVER['REMOTE_ADDR'];
    		$captchaurl = $google_url."?secret=".$secret."&response=".$captcha."&remoteip=".$ip;
    												
    		$curl_init = curl_init();
    		curl_setopt($curl_init, CURLOPT_URL, $captchaurl);
    		curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, 1);
    		curl_setopt($curl_init, CURLOPT_TIMEOUT, 10);
    		$results = curl_exec($curl_init);
    		curl_close($curl_init);
    												
    		$results= json_decode($results, true);
    		if($results['success'])
    		{	
    			//my code
    		} else {
    			json_status('Invalid reCAPTCHA code.');
    		}			
    	} else {
    		json_status('Please re-enter your reCAPTCHA.'); 
    	}			
    

    is my *.php which getting POST send by JS.

     

    Here is my JS:

    function onRulesCheck(node) {
    	if (node.checked) {
    		node.disabled = true;
    		$('#sign_up').prop( "disabled", false);
    	}
    }
    
    $(function(){
    
    	var form	= $('#form');
    	var submit 	= $('#sign_up');
    	var alert	= $('.alert');
    	var alert_error	= $('.alert_error');
    	var alert_error2 = $('.alert_error2');
    
    	// validate form
    	form.validate({
    		// validation rules
    		rules: {
    			// account_name field (required , minimum length 3, max 
    			account_name: {
    				required: true,
    				minlength: 5,
    				maxlength: 11
    			},
    			// account_password field (required , minimum length 6, max 16)
    			account_password: {
    				required: true,
    				minlength: 5,
    				maxlength: 32
    			},
    			// account_password2 field must be equal to password field
    			account_password2: {
    				equalTo: '#account_password'
    			},
    			
    			// email field only required
    			email: 'required'
    		},
    		// submit ajax request
    		submitHandler: ajaxSubmit
    	});
    
    	/**
    	* ajax submit function
    	* sending simple ajax request
    	**/
    
    	function ajaxSubmit() {
    		$.ajax({
    			url: 'modules/account_create.php',
    			type: 'POST',
    			dataType: 'json',
    			// form serialize data
    			data: form.serialize(),
    			beforeSend: function(){
    				alert.fadeOut();
    				alert_error.fadeOut();
    				submit.val('Sending...').attr('disabled', 'disabled');
    			},
    			success: function(data){
    				if ( data.status === 'success' ) {
    					// if response status == success redirect to success page
    					alert.fadeIn();
    					alert_error2.html('Account Created!').fadeIn();		
    				} else {
    					// not success! show error messages
    					alert.fadeIn();
    					alert_error.html(data.status).fadeIn();
    					submit.val('Sign Up').removeAttr('disabled');
    				}
    			},
    			error: function(){
    				// show error message			
    				submit.val('Sign Up').removeAttr('disabled');
    			}
    		});
    	};
    });
    

    I always have this error: "Please re-enter your reCAPTCHA."

  7. I download Firefox and install Firebug and I think there this is error:

    		new Ajax.Request('modules/account_create.php', {
    			method: 'post',
    			parameters: params,
    			onSuccess: function(transport) {
    				var param = transport.request.options.parameters;
    				var XML = parseXML(transport.responseText);
    				var errors = XML.getElementsByTagName('error');
    				var success = XML.getElementsByTagName('success');
    				$('#submit_errors').innerHTML = '';
    				$('#submit_success').innerHTML = '';
    				$('#submit_load').innerHTML = '';
    				
    				for (var i = 0; i < errors.length; i++) {
    					$('#submit_errors').innerHTML += errors[i].attributes.getNamedItem('id').value + ': ' + errors[i].childNodes[0].nodeValue + '<br/>';
    				}
    				if (success.length > 0) {
    					$('#submit_success').innerHTML = success[0].childNodes[0].nodeValue;
    				} else {
    					$('#submit_button').prop( "disabled", false);
    				}
    
    			},
    			onFailure: function() {alert('AJAX failed.')}
    		}); 

    In response i have:

    <response><error id="email">empty email address</error><error id="accname">empty account name</error><error id="password">empty password</error></response>

  8. I added below function onSubmit() { this:

    alert("Test!!");

    and it is showed when I click.

    I look to network panel and there is: 

    Uncaught ReferenceError: Ajax is not defined

     

    Error in that line:

    new Ajax.Request('modules/account_create.php', {

     

     

    EDIT:

    I add this to main file

    <script language="javascript" type="text/javascript" src="prototype.js"></script>

     

    and now I don't have any errors but this no working again

  9. Hello, I have registration form wirtten in PHP and AJAX + MySQL. In parts written in JavaScript I totally do not understand(I taken this  from other website which I found in http://sourceforge.net/), but I do know that when I click Submit, it's nothing happens. Can someone help me with this?

     

    register.php

    <?php 
    /*
        Copyright (C) 2007 - 2008  Nicaw
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License along
        with this program; if not, write to the Free Software Foundation, Inc.,
        51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */
    include ("include.inc.php");
    
    $account = new Account();
    if ($account->load($_SESSION['account'])){
    	header('location: account.php');
    	die();
    }else{
    $ptitle="Registration - $cfg[server_name]";
    include ("header.inc.php");
    ?>
    <div id="content">
    <div class="top_page">Registration</div>
    <div class="mid_page">
    	<table>
    		<tr>
    			<td width="40%" style="vertical-align: top">
    				<label for="email"><b>Email address:</b></label>
    			</td>
    			<td width="60%"><input id="email" type="text" /> <span id="email_state"></span>
    				<div><?php
    				if ($cfg['Email_Validate']) {
    					echo 'This server requires email validation. A letter with your password will be sent to the address provided above.';
    				} else {
    					echo 'Please enter a valid email address if we need to contact you.';
    				}
    				?></div>
    			</td>
    		</tr>
    		<tr>
    			<td width="40%" style="vertical-align: top"><label for="accname"><b>Desired Account Name:</b></label></td>
    				<td width="60%"><input id="accname" type="text" /> <span id="accname_state"></span>
    				<div>Account name consists of letters a-z, numbers 0-9, underscores _ and is at least 6 characters long.</div>
    			</td>
    		</tr>
    		<?php
    		if (!$cfg['Email_Validate']) {?>
    		<tr>
    			<td style="vertical-align: top"><label for="password"><b>Choose a password:</b></label></td>
    			<td>
    				<input id="password" type="password" /> <span id="password_state"></span>
    				<div>Password consists of letters a-z, numbers 0-9, symbols(~!@#%&;,:\^$.|?*+()) and is at least 6 characters long.	</div>
    			</td>
    		</tr>
    		<tr>
    			<td style="vertical-align: top"><label for="confirm"><b>Re-enter password:</b></label></td>
    			<td><input id="confirm" type="password" /> <span id="confirm_state"></span><br/><br/></td>
    		</tr>
    		<?php } ?>
    		<tr>
    			<td style="vertical-align: top"><label for="rlname"><b>*Your name:</b></label></td>
    			<td><input id="rlname" type="text" /><br/><br/></td>
    		</tr>
    		<tr>
    			<td style="vertical-align: top"><label for="location"><b>*Your location:</b></label></td>
    			<td><input id="location" type="text" /><br/>* Optional fields<br/><br/></td>
    		</tr>
    		<?php
    		if($cfg['use_captcha']) {
    			echo '<tr><td style="vertical-align: top"><b>Verification:</b></td><td><div class="g-recaptcha" data-sitekey="my site key"></div>'.
    			'</td></tr>';
    		}
    		?>
    		<tr>
    			<td colspan="2">
    				<div style="overflow-y: scroll; height: 200px;"><?php echo htmlspecialchars(@file_get_contents('documents/server_rules.txt'));?></div>
    				<input id="rules_check" type="checkbox" onclick="onRulesCheck(this)"/> <label for="rules_check"><b>I agree with server rules</b></label> 
    				<button id="submit_button" disabled="disabled" onclick="onSubmit()">Submit</button>
    				<span id="submit_load" style="color: red; font-weight: bold; text-decoration: blink;"></span>
    				<div id="submit_errors" style="color: red; font-weight: bold;"></div>
    				<div id="submit_success" style="color: green; font-weight: bold;"></div>
    			</td>
    		</tr>
    	</table>
    
    	
    	<script type="text/javascript">
    	//<![CDATA[
    	function onRulesCheck(node) {
    		if (node.checked) {
    			node.disabled = true;
    			$('#submit_button').prop( "disabled", false);
    		}
    	}
    
    	function onSubmit() {
    		var params = new Array();
    		params['email'] = $('email').value;
    		params['accname'] = $('accname').value;
    
    		params['rlname'] = $('rlname').value;
    		params['location'] = $('location').value;
    		params['captcha'] = $('captcha').value;
    		params['submit'] = 'yes';
    		<?php if (!$cfg['Email_Validate']) {?>
    		params['password'] = $('password').value;
    		params['confirm'] = $('confirm').value;
    		<?php } else { ?>
    		$('submit_load').innerHTML = 'Please wait...';
    		<?php } ?>
    		$('submit_button').disabled = true;
    		new Ajax.Request('modules/account_create.php', {
    			method: 'post',
    			parameters: params,
    			onSuccess: function(transport) {
    				var param = transport.request.options.parameters;
    				var XML = parseXML(transport.responseText);
    				var errors = XML.getElementsByTagName('error');
    				var success = XML.getElementsByTagName('success');
    				$('submit_errors').innerHTML = '';
    				$('submit_success').innerHTML = '';
    				$('submit_load').innerHTML = '';
    				
    				for (var i = 0; i < errors.length; i++) {
    					$('submit_errors').innerHTML += errors[i].attributes.getNamedItem('id').value + ': ' + errors[i].childNodes[0].nodeValue + '<br/>';
    				}
    				if (success.length > 0) {
    					$('submit_success').innerHTML = success[0].childNodes[0].nodeValue;
    				} else {
    					$('submit_button').disabled = false;
    				}
    				$('captcha_img').src = 'doimg.php?' + Date.parse(new Date().toString());
    
    			},
    			onFailure: function() {alert('AJAX failed.')}
    		});
    	}
    
    	function updateState(id, XML) {
    			if($(id).value == '') {
    				$(id+'_state').innerHTML = '';
    				return;
    			}
    			var errors = XML.getElementsByTagName('error');
    			for (var i = 0; i < errors.length; i++) {
    				if (errors[i].attributes.getNamedItem('id').value == id) {
    					$(id+'_state').innerHTML = '<img src="resource/cross.png" alt="X" title="'+errors[i].childNodes[0].nodeValue+'"/>';
    					return;
    				}
    			}
    			$(id+'_state').innerHTML = '<img src="resource/tick.png" alt="V" />';
    		}
    
    	var observerCallback = function(el, value) {
    		var params = new Array();
    		params['el_id'] = el.id;
    		params['email'] = $('email').value;
    		params['accname'] = $('accname').value;
    	<?php if (!$cfg['Email_Validate']) {?>
    		params['password'] = $('password').value;
    		params['confirm'] = $('confirm').value;
    	<?php } ?>
    		new Ajax.Request('modules/account_create.php', {
    				method: 'post',
    				parameters: params,
    				onSuccess: function(transport) {
    					var param = transport.request.options.parameters;
    					var XML = parseXML(transport.responseText);
    					if (param.el_id == 'accname') {
    						updateState('accname', XML);
    						updateState('password', XML);
    					} else if (param.el_id == 'password') {
    						updateState('password', XML);
    						updateState('confirm', XML);
    					} else {
    						updateState(param.el_id, XML);
    					}
    				},
    				onFailure: function() {alert('AJAX failed.')}
    		});
    	}
    
    	new Form.Element.Observer('email', 2, observerCallback);
    	new Form.Element.Observer('accname', 2, observerCallback);
    	<?php if (!$cfg['Email_Validate']) {?>
    	new Form.Element.Observer('password', 2, observerCallback);
    	new Form.Element.Observer('confirm', 2, observerCallback);
    	<?php } ?>
    	//]]>
    	</script>	
    </div>
    <div class="bot_page"></div>
    </div>
    <?php 
    }
    include ("footer.inc.php");
    ?>
    

    and this is account_create.php which is include in AJAX

    <?php
    /*
        Copyright (C) 2007 - 2008  Nicaw
     
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
     
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
     
        You should have received a copy of the GNU General Public License along
        with this program; if not, write to the Free Software Foundation, Inc.,
        51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */
    include ("../include.inc.php");
     
    $errors = array();
    $account = new Account();
    
    if ($cfg['use_captcha'] && isset($_POST['submit'])) {
        // To do
    }
    
    //email formating rules
    if (empty($_POST['email'])) {
        $errors['email'] = 'empty email address';
    }elseif (!preg_match('/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i',$_POST['email'])) {
        $errors['email'] = 'not a valid email address';
    }else {
        $email = $_POST['email'];
    }
    
    //account name formating rules
    if (empty($_POST['accname'])) {
        $errors['accname'] = 'empty account name';
    }elseif (!preg_match('/^[A-Z0-9_]{6,30}$/i',$_POST['accname'])) {
        $errors['accname'] = 'not a valid account name';
    }else {
    //check for existing name
        if($account->existsName(strtolower($_POST['accname']))) {
            $errors['accname'] = 'account name is already used';
        } else {
            $accname = strtolower($_POST['accname']);
        }
    }
    
    //password formating rules
    if ($cfg['Email_Validate']) {
        $password = substr(str_shuffle(strtolower('qwertyuipasdfhjklzxcvnm12345789')), 0, ;
    } else {
        if (empty($_POST['password'])) {
            $errors['password'] = 'empty password';
        }elseif (!strlen($pass) > 5 && strlen($pass) <= 50 && preg_match('/^[a-zA-Z0-9~!@#%&;,:\\\^\$\.\|\?\*\+\(\)]*$/',$_POST['password'])) {
            $errors['password'] = 'not a valid password';
        }elseif (isset($_POST['accname']) && strtolower($_POST['password']) == strtolower($_POST['accname'])) {
            $errors['password'] = 'password cannot match account name';
        }elseif (empty($_POST['confirm'])){
            $errors['confirm'] = 'empty password';
        }elseif ($_POST['password'] != $_POST['confirm']) {
            $errors['confirm'] = 'passwords do not match';
        }else {
            $password = $_POST['password'];
        }
    }
    
    $responseXML = new SimpleXMLElement('<response/>');
    if (count($errors) > 0) {
        while ($error = current($errors)) {
            $err = $responseXML->addChild('error', $error);
            $err->addAttribute('id', key($errors));
            next($errors);
        }
    }elseif (count($errors) == 0 && isset($_POST['submit'])) {
    
        //create the account
    	$account->saveAccount($accname, $password, $email, substr($_POST['rlname'], 0, 50), substr($_POST['location'], 0, 50));
    
        if ($cfg['Email_Validate']) {
            $body = "Here is your login information for <a href=\"http://$cfg[server_url]/\">$cfg[server_name]</a><br/>
    <b>Account name:</b> $accname<br/>
    <b>Password:</b> $password<br/>
    <br/>
    Powered by <a href=\"http://nicaw.net/\">Nicaw AAC</a>";
            //send the email
            require_once("../class/class.phpmailer.php");
    
            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->IsHTML(true);
            $mail->Host = $cfg['SMTP_Host'];
            $mail->Port = $cfg['SMTP_Port'];
            $mail->SMTPAuth = $cfg['SMTP_Auth'];
            $mail->Username = $cfg['SMTP_User'];
            $mail->Password = $cfg['SMTP_Password'];
    
            $mail->From = $cfg['SMTP_From'];
            $mail->AddAddress($email);
    
            $mail->Subject = $cfg['server_name'].' - Login Details';
            $mail->Body    = $body;
    
            if ($mail->Send()) {
            //create new message
                $responseXML->addChild('success', 'Your login details were emailed to '.htmlspecialchars($_POST['email']));
            }else {
                $responseXML->addChild('success', 'Contact administrator to get your password. Mailer Error: '.$mail->ErrorInfo);
            }
        }else {
        //create new message
            $responseXML->addChild('success', 'Account created!');
            $account->logAction('Created');
        }
    }
    echo $responseXML->asXML();
    ?>
    
  10. Thanks for answer. I changed some piece of code and again not working. Can you tell me why I can't find ipn.log in my server(tested on VPS)?

    <b>PayPal Shop System.</b><br><br>
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="email">
    <input type="hidden" name="lc" value="US">
    <b>Account number: </b> <font color="black"><?php echo $_SESSION["acc"]; ?></font></br>
    <select id="item_name" name="item_name" style="width:256px; height:32px;"></select>
    <input id="amount" name="amount" type="hidden" value="">
    <script>
      var items = [
          { name: "1000 PP", amount: 5.00 },
          { name: "2500 PP", amount: 10.00 },
          { name: "6000 PP", amount: 20.00 }
      ];
      var itemNameElement = document.getElementById("item_name");
    
      itemNameElement.onchange = (function(){
          var amount = items[this.selectedIndex].amount;
          document.getElementById("amount").value = amount;
      }).bind(itemNameElement);
    
      document.getElementById("amount").value = items[0].amount;
      for(var i=0; i<items.length; i++){
          var item = document.createElement("option");
          item.value = items[i].name;
          item.text = items[i].name+" - "+items[i].amount+" EUR";
          itemNameElement.add(item);
      }
    </script>
    <input type="hidden" name="button_subtype" value="products">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="EUR">
    <input type="hidden" name="rm" value="2">
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
    <input type="hidden" name="return" value="http://site/sms_shop/">
    <input type="hidden" name="cancel_return" value="http://site/sms_shop/">
    <input type="hidden" name="notify_url" value="http://site/sms_shop/shop/ipn-test.php" />
    <input type="hidden" name="custom" value='<?php echo $_SESSION["acc"]; ?>'>
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>
    
    <?php
    	baza();
    	ob_start();	
    		
    		// CONFIG: Enable debug mode. This means we'll log requests into 'ipn.log' in the same directory.
    		// Especially useful if you encounter network errors or other intermittent problems with IPN (validation).
    		// Set this to 0 once you go live or don't require logging.
    		define("DEBUG", 1);
    
    		// Set to 0 once you're ready to go live
    		define("USE_SANDBOX", 1);
    		define("LOG_FILE", "./ipn.log");
    
    
    		// Read POST data	
    		//reading raw POST data from input stream. reading pot data from $_POST may cause serialization issues since POST data may contain arrays
    		$raw_post_data = file_get_contents('php://input');
    		$raw_post_array = explode('&', $raw_post_data);
    		$myPost = array();
    		foreach ($raw_post_array as $keyval)
    		{
    			$keyval = explode ('=', $keyval);
    			if (count($keyval) == 2)
    				$myPost[$keyval[0]] = urldecode($keyval[1]);
    		}		
    		
    		// read the post from PayPal system and add 'cmd'
    		$req = 'cmd=_notify-validate';
    		if(function_exists('get_magic_quotes_gpc'))
    		{
    		   $get_magic_quotes_exits = true;
    		} 
    		foreach ($myPost as $key => $value)
    		{        
    			if($get_magic_quotes_exits == true && get_magic_quotes_gpc() == 1)
    			{ 
    				$value = urlencode(stripslashes($value)); 
    			}
    			else
    			{
    				$value = urlencode($value);
    			}
    			$req .= "&$key=$value";
    		}		
    		
    
    		// Post IPN data back to PayPal to validate the IPN data is genuine
    		// Without this step anyone can fake IPN data
    
    		if(USE_SANDBOX == true) {
    			$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
    		} else {
    			$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
    		}
    
    		$ch = curl_init($paypal_url);
    		if ($ch == FALSE) { 
    			return FALSE; 
    		}
    		
    		curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    		curl_setopt($ch, CURLOPT_POST, 1);
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    		curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    		curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    
    		if(DEBUG == true) {
    			curl_setopt($ch, CURLOPT_HEADER, 1);
    			curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    		}
    
    		// CONFIG: Optional proxy configuration
    		//curl_setopt($ch, CURLOPT_PROXY, $proxy);
    		//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    
    		// Set TCP timeout to 30 seconds
    		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
    
    		// CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
    		// of the certificate as shown below. Ensure the file is readable by the webserver.
    		// This is mandatory for some environments.
    
    		//$cert = __DIR__ . "./cacert.pem";
    		//curl_setopt($ch, CURLOPT_CAINFO, $cert);
    
    		$res = curl_exec($ch);
    		if (curl_errno($ch) != 0) // cURL error
    		{
    			if(DEBUG == true) {
    				error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
    			}
    			curl_close($ch);
    			exit;
    
    		} else {
    			// Log the entire HTTP response if debug is switched on.
    			if(DEBUG == true) {
    				error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
    				error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
    			}
    			curl_close($ch);
    		}			
    
    		// Inspect IPN validation result and act accordingly
    		// Split response headers and payload, a better way for strcmp
    		$tokens = explode("\r\n\r\n", trim($res));
    		$res = trim(end($tokens));
    
    		if (strcmp($res, "VERIFIED") == 0) 
    		{
    			// check whether the payment_status is Completed
    			// check that txn_id has not been previously processed
    			// check that receiver_email is your PayPal email
    			// check that payment_amount/payment_currency are correct
    			// process payment and mark item as paid.
    
    			// assign posted variables to local variables
    			$item_name = $_POST['item_name'];
    			$item_number = $_POST['item_number'];
    			$payment_status = $_POST['payment_status'];
    			$mcGross = $_POST['mc_gross'];
    			$mcCurrency = $_POST['currency_code'];
    			$currency = 'EUR';
    			$txn_id = $_POST['txn_id'];
    			$receiver_email = $_POST['receiver_email'];
    			$receiver = 'email';
    			$payer_email = $_POST['payer_email'];
    			$user_id = $_POST['custom'];
    			
    			$prices = array('5.00' => 1000, '10.00' => 2500, '20.00' => 6000);
    			if ($payment_status == 'Completed') 
    			{
    				$txn_id_check = mysql_query("SELECT `txn_id` FROM `paypal_log` WHERE `txn_id` = '".$txn_id."'");
    				if (mysql_num_rows($txn_id_check) !=1) 
    				{
    					if ($receiver_email == $receiver) 
    					{
    						if (isset($prices[$mcGross]) && $mcCurrency == $currency)
    						{
    							// Process payment										
    							// add txn_id to database
    							$data = date("U");	
    							
    							/*
    							CREATE TABLE `paypal_log` (
    							  `id` int(10) NOT NULL auto_increment,
    							  `account` int(15) NOT NULL,
    							  `email` varchar(20) NOT NULL,
    							  `prices` int(15) NOT NULL,
    							  `txn_id` varchar(20) NOT NULL,
    							  `data` timestamp NOT NULL,
    							  PRIMARY KEY  (`id`)
    							) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    							*/
    							
    							$log_query = mysql_query("INSERT INTO `paypal_log` VALUES ('', '".$user_id."', '".$payer_email."'', '".$prices[$mcGross]."', '".$txn_id."', '".$data."') ");
    
    							// add points to user
    							$data = mysql_result(mysql_query("SELECT `bonus` AS `old_bonus` FROM `accounts` WHERE `id` = '".$user_id."' LIMIT 1"),0);
    							$new_points = $data['old_bonus'] + $prices[$mcGross];							
    							$update_bonus = mysql_query("UPDATE `accounts` SET `bonus` = ".$new_points." WHERE `id` = '".$user_id."'");							
    						}
    					}					
    				}				
    			}
    			
    			if(DEBUG == true) {
    				error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE); 
    			}
    			
    		} else if (strcmp ($res, "INVALID") == 0) {
    			// log for manual investigation
    			// Add business logic here which deals with invalid IPN messages
    			if(DEBUG == true) {	
    				error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE); 
    			}
    		}
    		
    ?>
    
    
  11. Hmm, I rewrite some piece of code and nothing changed :/

    <?php
    $acc = $_SESSION["acc"]
    ?>
    <b>PayPal Shop System.</b><br><br>
    The shop costs:<ul><li> 5 EUR (for 1000 points)</li><li> 10 EUR (for 2500 points)</li><li> 20 EUR (for 6000 points)</li><br>
    
    <b>Here are the steps you need to make:</b> <br>
    1. A PayPal account with a required balance [5, 10 or 20 EUR] or a creditcard. <br>
    2. Fill in your account number. <br>
    3. Click on the Buy Now button or your creditcard brand. <br>
    4. Make a transaction. <br>
    5. After the transaction 1000, 2500 or 6000 points will be automatically added to your account. <br>
    6. Go to Item shop and use your points <br> <br> <br> </b>
    
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="business email from sandbox mode">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="item_name" value="Premium Points">
    <b>Account number: </b> <font color="black"><?php echo $acc ?></font>
    <select name="amount">
      <option value="5.00">1000 PP - 5 EUR</option>
      <option value="10.00">2500 PP - 10 EUR</option>
      <option value="20.00">6000 PP - 20 EUR</option>
    </select>
    <input type="hidden" name="button_subtype" value="products">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="currency_code" value="EUR">
    <input type="hidden" name="rm" value="2">
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
    <input type="hidden" name="return" value="http://127.0.0.1/sms_shop/">
    <input type="hidden" name="cancel_return" value="http://127.0.0.1/sms_shop/">
    <input type="hidden" name="notify_url" value="http://127.0.0.1/sms_shop/shop/ipn/ipn.php" />
    <input type="hidden" name="custom" value="<?php echo $acc; ?>">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>
    
    <?php
    	baza();
    	ob_start();		
    	$account = $_SESSION["acc"];
    	if ($_SERVER['REQUEST_METHOD'] == "POST")
    	{
    		if ($account == "111111" || $account == "1") 
    			{ $error='Dla bezpieczeństwa ten numer jest zablokowany!';	}
    		elseif (empty($account)) 
    			{ $error='Podaj Numer Konta!'; } 
    		elseif (!is_numeric($account)) 
    			{ $error='Numer konta może składać się wyłącznie z cyfr!'; } 			
    		if (empty($error)) 
    			{$query=mysql_query('SELECT * FROM accounts WHERE (id = '.$account.')');
    				if (mysql_num_rows($query) == 0)
    					{$error= "Numer nie istnieje";}	
    			}
    
    		$query2 = mysql_query("SELECT `bonus` FROM `accounts` WHERE (`id` = '$account') ") or die(mysql_error());
    
    
    		//reading raw POST data from input stream. reading pot data from $_POST may cause serialization issues since POST data may contain arrays
    		$raw_post_data = file_get_contents('php://input');
    		$raw_post_array = explode('&', $raw_post_data);
    		$myPost = array();
    		foreach ($raw_post_array as $keyval)
    		{
    			$keyval = explode ('=', $keyval);
    			if (count($keyval) == 2)
    				$myPost[$keyval[0]] = urldecode($keyval[1]);
    		}
    		// read the post from PayPal system and add 'cmd'
    		$req = 'cmd=_notify-validate';
    		if(function_exists('get_magic_quotes_gpc'))
    		{
    			$get_magic_quotes_exits = true;
    		} 
    		foreach ($myPost as $key => $value)
    		{        
    			if($get_magic_quotes_exits == true && get_magic_quotes_gpc() == 1)
    			{ 
    				$value = urlencode(stripslashes($value)); 
    			}
    			else
    			{
    				$value = urlencode($value);
    			}
    			$req .= "&$key=$value";
    		}
     
    		$ch = curl_init();
    		curl_setopt($ch, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr');
    		curl_setopt($ch, CURLOPT_POST, 1);
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    		curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
    		// In wamp like environment where the root authority certificate doesn't comes in the bundle, you need
    		// to download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
    		// of the certificate as shown below.
    		// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
    		$res = curl_exec($ch);
    		curl_close($ch);
     
    		if (strcmp ($res, "VERIFIED") == 0) {
    			// check the payment_status is Completed
    			// check that txn_id has not been previously processed
    			// check that receiver_email is your Primary PayPal email
    			// check that payment_amount/payment_currency are correct
    			// process payment
    			
    			// Assign posted variables to local variables
    			$item_name = mysql_real_escape_string($_POST['item_name']);
    			$item_number = mysql_real_escape_string($_POST['item_number']);
    			$payment_status = mysql_real_escape_string($_POST['payment_status']);
    			$mcGross = mysql_real_escape_string($_POST['mc_gross']);
    			$mcCurrency = mysql_real_escape_string($_POST['mc_currency']);
    			$txn_id = mysql_real_escape_string($_POST['txn_id']);
    			$receiver_email = mysql_real_escape_string($_POST['receiver_email']);
    			$payer_email = mysql_real_escape_string($_POST['payer_email']);
    			$user_id = $_POST['custom']; // Our user's ID
    			// Prices
    			$prices = array('5.00' => 1000, '10.00' => 2500, '20.00' => 6000);
    			// Setup
    			$receiver = 'business email from sandbox mode';
    			$currency = 'EUR';			
    			
    			if ($payment_status == 'Completed') 
    			{
    				// Builds a string to insert into the db so you can see everything that has come across from paypal.
    				// Pairs are separated by commas and paired key-to-value with a / forward slash
    				foreach($_POST as $k => $v)
    				{ $valu.= $k.' / '.$v.', '; }
    
    				$txn_id_check = mysql_query("SELECT `txn_id` FROM `log` WHERE `txn_id` = '".$txn_id."'");
    				if (mysql_num_rows($txn_id_check) !=1) 
    				{
    					if ($receiver_email == $receiver) 
    					{
    						if (isset($prices[$mcGross]) && $mcCurrency == $currency) 
    						{
    							$data = date("U");					
    							// Process payment
    							// add txn_id to database
    							// Add a column to hold the $valu var info
    							$log_query = mysql_query("INSERT INTO `paypal_log` VALUES ('', '".$user_id."', '".$txn_id."', '".$payer_email."', '".$valu."', '".$data."') ");
    
    							
    							$data = mysql_select_single("SELECT `bonus` AS `old_bonus` FROM `accounts` WHERE `id` = '".$user_id."';");
    							$new_points = $data['old_bonus'] + $prices[$mcGross];							
    							$update_bobus = mysql_query("UPDATE `accounts` SET `bonus` = ".$new_points." WHERE `id` = '".$user_id."'");
    						}
    					}
    				}
    			}
    
    		}
    		else if (strcmp ($res, "INVALID") == 0) {
    			// log for manual investigation
    			//$db->query("INSERT INTO `".PURCHASES."` SET `test` = 'not valid response'");
    		}
    	}
    ?>
    
  12. Hey, I'm trying to integrate paypal into my site. When the purchase is complete, I want update my mysql database with the relevant values. However, when I test, the database does not update.I don't get any errors.

    This is my paypal.htm and ipn.php

    <?php
    $acc = $_SESSION["acc"]
    ?>
    <b>PayPal Shop System.</b><br><br>
    The shop costs:<ul><li> 5 EUR (for 1000 points)</li><li> 10 EUR (for 2500 points)</li><li> 20 EUR (for 6000 points)</li><br>
    
    <b>Here are the steps you need to make:</b> <br>
    1. A PayPal account with a required balance [5, 10 or 20 EUR] or a creditcard. <br>
    2. Fill in your account number. <br>
    3. Click on the Buy Now button or your creditcard brand. <br>
    4. Make a transaction. <br>
    5. After the transaction 1000, 2500 or 6000 points will be automatically added to your account. <br>
    6. Go to Item shop and use your points <br> <br> <br> </b>
    
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="my business email from sandbox mode(for testing)">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="item_name" value="Premium Points">
    <b>Account number: </b> <font color="black"><?php echo $acc ?></font>
    <select name="amount">
      <option value="5.00">1000 PP - 5 EUR</option>
      <option value="10.00">2500 PP - 10 EUR</option>
      <option value="20.00">6000 PP - 20 EUR</option>
    </select>
    <input type="hidden" name="button_subtype" value="products">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="currency_code" value="EUR">
    <input type="hidden" name="rm" value="0">
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>
    
    
    <?
    		baza(); // -- connecting with database
    		ob_start();		
    		$account = $_SESSION["acc"];
    	if ($_SERVER['REQUEST_METHOD'] == "POST")
    	{
    		if ($account == "111111" || $account == "1") 
    			{ $error='Dla bezpieczeństwa ten numer jest zablokowany!';	}
    		elseif (empty($account)) 
    			{ $error='Podaj Numer Konta!'; } 
    		elseif (!is_numeric($account)) 
    			{ $error='Numer konta może składać się wyłącznie z cyfr!'; } 			
    		if (empty($error)) 
    			{$query=mysql_query('SELECT * FROM accounts WHERE (id = '.$account.')');
    				if (mysql_num_rows($query) == 0)
    					{$error= "Numer nie istnieje";}	
    			}
    
    		$query2 = mysql_query("SELECT `bonus` FROM `accounts` WHERE (`id` = '$account') ") or die(mysql_error());
    		
    		
    		if($_REQUEST['debug'])
    		{
    			ini_set('display_errors', true);
    			error_reporting(E_ALL);
    		}
    		
    		// Variables, don't touch!
    		$receiverEmail = $_REQUEST['receiver_email'];
    		$paymentStatus = $_REQUEST['payment_status'];
    		$mcGross = $_REQUEST['mc_gross'];
    		$mcCurrency = $_REQUEST['mc_currency'];
    		// Prices
    		$prices = array('5.00' => 1000, '10.00' => 2500, '20.00' => 6000);
    		// Setup
    		$receiver = 'my business email from sandbox mode(for testing)';
    		$currency = 'EUR';
    		
    		if($paymentStatus == 'Completed' && $receiverEmail == $receiver && isset($prices[$mcGross]) && $mcCurrency == $currency)
    		{		
    			$data = date("U");
    			mysql_query("INSERT INTO archiwum(user, kod, data, typ) values('$account', 'Paypal', '$data', '1')");	
    			
    			// Process payment
    			$data = mysql_select_single("SELECT `bonus` AS `old_bonus` FROM `accounts` WHERE (`id` = '$account');");
    
    			// Give points to user
    			$new_points = $data['old_bonus'] + $prices[$mcGross];
    			mysql_query("UPDATE `accounts` SET `bonus`='$new_points' WHERE (`id` = '$account'));	
    		}
    		else
    		{	
    			exit();
    		}
    	
    	}
    ?>
    
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.