Hey guys i have a email webform script that collects email address on optin and sends the correct data to the autoresponder account..


The issue i am facing is this

Steps - you enter your name and email in the form and submit

The data is collected and put into a database
tables

Name , email, Ip address

Its collecting it perfectly into the database. But then i run a cron file which sends the collected data to the autoresponder account. Basicly the IP thats sending every time is the server ip and not the actual ip in the database.

Could anyone maybe spot the mistake in this file.


cron.php
PHP Code:
<?php
    
include_once('../../../wp-load.php');
    
$optin_forms get_option('optin_forms');
    
$referer_urls get_option('referer_urls');    
    
    global 
$wpdb;
    
$query "SELECT * FROM " $wpdb->get_blog_prefix() . "rem_signup WHERE submitted = 0";
    
$results $wpdb->get_results$queryARRAY_A );
    foreach (
$results as $row){    
            
$fname $row['name'];
            
$email $row['email_address'];
            
//Submit each subscriber details to each autoresponder
            
for($i 0$i count($optin_forms); $i++) {
                if (
trim($optin_forms[$i]) != '') {
                    
$form $optin_forms[$i];
                    
$referer $referer_urls[$i];            
                    
form_submitter($fname,$email,$form,$referer);
                    
sleep(5); 
                }
            }
            
$query "UPDATE " $wpdb->get_blog_prefix() . "rem_signup SET submitted = 1 WHERE email_address = LCASE('" $email "')";                        
            
$wpdb->query($query);
    }
        
    
    function 
form_submitter($fname,$email,$form,$referer) {
        
//Get the form action URL    
        
$action_url '';    
        
$nvlAr = array();
        if (
preg_match('!(?<=action=\")(http[s]*?://[\S]+)(?=\")!',$form,$matches)) {
            
$action_url $matches[0];        
            
//Get an array of input fields
            
if (preg_match_all('!<input\s[\w+][^<]*>!',$form,$matches)) {            
                foreach(
$matches[0] as $inputfield) {
                    
//Get NVL pairs in each input field into an array                
                    
$name '';
                    
$value '';
                    
//Get name
                    
if (preg_match('!(?<=name=\")(\S)*(?=\")!',$inputfield,$name)) {
                        
//Get value                                
                        
preg_match('!(?<=value=\")([^"])*(?=\")!',$inputfield,$value);
                        if(isset(
$value[0])) {
                            
$nvlAr[$name[0]] = $value[0];
                        } else {
                            
$nvlAr[$name[0]] = '';
                        }    
                        
                    }
                }
            }
            
            
//Search NVL array for name/email and place values.
            
$name_alias = array('name','fullname','fname','firstname','NAME','FULLNAME','FNAME','FirstName');
            foreach(
$name_alias as $alias) {                
                if (
array_key_exists($alias,$nvlAr)) {                    
                    
$nvlAr[$alias] = $fname;                    
                }
            }
            
            
$email_alias = array('email','Email','EMAIL');
            foreach(
$email_alias as $alias) {                        
                if (
array_key_exists($alias,$nvlAr)) {                    
                    
$nvlAr[$alias] = $email;                                        
                }
            }            
            
            
//Post the form using cURL            
            
$query '';
            foreach(
$nvlAr as $key => $value) {
                
$query .= $key.'='.$value.'&';
            }    
            
$query substr($query,0,-1);                
            
$ch curl_init();
            
//If the action URL contains a partial querry, add '&' to end
            
if(strpos($action_url,'?')) {
                
$action_url .= '&';
            }                    
            
curl_setopt($ch,CURLOPT_URL,$action_url);
            
curl_setopt($chCURLOPT_VERBOSE1);
            
curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
curl_setopt($chCURLOPT_POST1);
            
curl_setopt($ch,CURLOPT_POSTFIELDS,$query);    
            
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
            
curl_setopt($chCURLOPT_SSL_VERIFYHOSTFALSE);
            if (
$referer != '') {    
                
curl_setopt($chCURLOPT_REFERER,$referer);        
            }
            
$response curl_exec($ch);        
            echo 
$response;                        
            
curl_close($ch);            
        }        
    }
?>
The process file of where the data is collected
PHP Code:
<?php


    
include_once('../../../wp-load.php');
    
error_reporting(0);

    
$redirect_url get_option('redirect_url');


$redirect_already_registered get_option("redirect_already_registered");


    if(isset(
$_POST['fname'],$_POST['email'])) {


        global 
$form;        


        global 
$redirect_url;


global 
$redirect_already_registered ;


        global 
$wpdb;


        


        
$fname $_POST['fname'];


        
$email $_POST['email'];        


        


        
/* Save results to database */


        


        
if (isset($_SERVER['HTTP_CLIENT_IP'])) {


            
$ip $_SERVER['HTTP_CLIENT_IP'];


        } else if (isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])) {


            
$ip $_SERVER['HTTP_X_FORWARDED_FOR'];


        } else if (isset(
$_SERVER['REMOTE_ADDR'])) {


            
$ip $_SERVER['REMOTE_ADDR'];


        }


        


        
//$query = "SELECT * FROM " . $wpdb->get_blog_prefix() . "rem_signup WHERE email_address = LCASE('". $email . "') OR ip_address = '" . $ip . "' ";
        
$query "SELECT * FROM " $wpdb->get_blog_prefix() . "rem_signup WHERE email_address = LCASE('"$email "')";
        

        
$result $wpdb->get_row($query);
        

        if( 
$result != NULL) {


if(
$redirect_already_registered)


{


//wp_redirect( $redirect_already_registered , true );


            
header("Location:$redirect_already_registered");    





}else{


            echo 
'Already Registered !!!';


}





        } else {


            
$date date("Y-m-d H:i:s");


            
$table $wpdb->get_blog_prefix() . 'rem_signup'


            
$wpdb->query($wpdb->prepare("INSERT INTO " $table " SET email_address = LCASE('"$email "'), name = '" $fname "', ip_address = '" $ip "', reg_time = '" $date "', referral_id = '".$_SESSION['ref_id']."',submitted = 0"), null);  


                     

            
            
header("Location:$redirect_url");    
            
        }


    }


    


    


?>