@ 2014-02-25T12:15:53Z <?
// Phil Blackman <phil.blackman@tmnplc.com> 2009
// feed.php
// arse over tit script for dealing with PureLead data
$start_time = date("c");
set_time_limit(180000);
//include("/home/phil/uploads/database.php");
// Connect to the Database
//$con_ptr = mysql_connect('db-02-03.tmnplc.com:3306','campaigns_web','pH4q.fQB23!');
//$con_ptr = connect_sym_live();
//$con_ptr = connect_sbm();
// Connect to the Database
$con_ptr = mysql_connect("db-08-02.tmnplc.com", "keila_web","Zircon500");
//$con_ptr = mysql_connect("db-08-01.tmnplc.com", "mailman","6Zyj8xj7");
// database
//$db = "mailman"; // testing
$db = "surveycentral"; // live
// telephone validation stuff
$phone_db = "surveycentral";
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$user_tbl = $db.".Users";
$mobile_tbl = $db.".MobileData";
$landline_tbl = $db.".LandLineData";
// data8 login details
$d8username = "tmngroup_data8";
$d8password = "AxUcmOkj12";
$telephone = 07450968006;
if($_POST)
{
foreach($_POST as $key => $value)
{
// for form debugging
//echo $key." --- ".$value."<br>";
$$key = $value;
}
}
if($_GET)
{
foreach($_GET as $key => $value)
{
// for form debugging
//echo $key." --- ".$value."<br>";
$$key = $value;
}
}
error_reporting(E_ALL);
$logdir = "/var/www/purelead/log_files/external_feed_log/";
$time = date("c");
function blacklist($ip, $time = '')
{
global $con_ptr, $ip_blacklist_table;
if(!empty($time))
{
$update = "UPDATE ".$ip_blacklist_table." SET active = 0 WHERE ip = '".$ip."' AND ts < '".$time."'";
//echo $update; die;
if(mysql_query($update)){
return true;
}
}
// check to see if the IP exists
$sql = "SELECT * FROM ".$ip_blacklist_table." WHERE ip = '".$ip."'";
$res = mysql_query($sql, $con_ptr);
$num_rows = mysql_num_rows($res);
if($num_rows == 1){
$update = "UPDATE ".$ip_blacklist_table." SET active = 1, ts = '".date("c")."' WHERE ip = '".$ip."'";
mysql_query($update);
return true;
} else {
$insert = "INSERT INTO ".$ip_blacklist_table." (ip) VALUES ('".$ip."')";
mysql_query($insert);
return true;
}
}
function checkIP($ip)
{
global $con_ptr, $UsersTbl, $ip_blacklist_table;
// first remove the entries from the blacklist
$fiveminsago = date("c", mktime(date("H"), date("i")-5, date("s"), date("m") , date("d"), date("Y")));
blacklist($ip, $fiveminsago);
// then check to see if we've had a reg from the same IP
$sql = "SELECT * FROM ".$UsersTbl." WHERE ip = '".$ip."' ORDER BY time DESC";
//echo $sql; die;
$res = mysql_query($sql, $con_ptr);
$num_rows = mysql_num_rows($res);
if($num_rows > 1)
{
$row = mysql_fetch_array($res);
$reg_timestamp = strtotime($row['time']);
$timestamp_now = time();
$difference = $timestamp_now - $reg_timestamp;
if($difference < 60)
{
blacklist($ip);
return false;
} else
{
// now check they aren't in the blacklist table
$sql = "SELECT * FROM ".$ip_blacklist_table." WHERE ip = '".$ip."' AND active = 1";
$res = mysql_query($sql, $con_ptr);
$num_rows = mysql_num_rows($res);
if($num_rows == 1){
blacklist($ip);
return false;
} else {
return true;
}
}
} else
{
return true;
}
}
// data8 bits
function LineIsValid($telephone, $d8username, $d8password)
{
global $landline_tbl, $phone_ptr;
// first we check to see if we've already searched for this number in the 3 months so we don't cane our credits
$three_months_ago = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m")-3, date("d"), date("Y")));
$sql = "SELECT * FROM ".$landline_tbl." WHERE Number = '".$telephone."' AND dos > '".$three_months_ago."'";
//echo "sasf".$d8username.$d8password;
$res = mysql_query($sql, $phone_ptr);
$numrows = mysql_num_rows($res);
if($numrows > 0)
{
$row = mysql_fetch_array($res);
if($row['Result'] != 'Invalid')
{
return true;
} else
{
return false;
}
}
$params = array(
"username" => $d8username,
"password" => $d8password,
"number" => $telephone
);
//$client = new SoapClient("http://webservices.data-8.co.uk/TelephoneValidation.asmx?WSDL");
$client = new SoapClient("http://webservices.data-8.co.uk/TelephoneLineValidation.asmx?WSDL");
$result = $client->IsValidAdvanced($params);
//echo $number."\n";
//var_dump($result);
//echo "\n";
$data = iterateObject($result);
$sql = "INSERT INTO ".$landline_tbl." VALUES ('', '".$telephone."', '".$data['Success']."', '".$data['CreditsRemaining']."', '".$data['Result']."', NOW())";
//echo $sql;
mysql_query($sql, $phone_ptr);
logResults($result, date("c"), "LandLineCheck.log", $telephone);
if ($result->IsValidAdvancedResult->Result != "Valid")
{
return false;
}
else
{
return true;
}
}
function MobileIsValid($telephone, $d8username, $d8password)
{
global $mobile_tbl, $phone_ptr;
// first we check to see if we've already searched for this number in the 3 months so we don't cane our credits
$three_months_ago = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m")-3, date("d"), date("Y")));
$sql = "SELECT * FROM ".$mobile_tbl." WHERE Number = '".$telephone."' AND dos > '".$three_months_ago."'";
//echo $sql;
$res = mysql_query($sql, $phone_ptr);
$numrows = mysql_num_rows($res);
if($numrows > 0)
{
$row = mysql_fetch_array($res);
if($row['Result'] != 'Invalid')
{
return true;
} else
{
return false;
}
}
$params = array(
"username" => $d8username,
"password" => $d8password,
"number" => $telephone
);
$client = new SoapClient("http://webservices.data-8.co.uk/MobileValidation.asmx?WSDL");
if($numrows == 0)
{
$result = $client->IsValid($params);
}
logResults($result, date("c"), "MobileCheck.log", $telephone);
// insert into the mobile table
$data = iterateObject($result);
$sql = "INSERT INTO ".$mobile_tbl." VALUES ('', '".$telephone."', '".$data['Success']."', '".$data['CreditsRemaining']."', '".$data['Result']."', '".$data['CountryISO']."', '".$data['Organisation']."', '".$data['NetworkName']."', '".$data['NetworkType']."', '".$data['Ported']."', '".$data['PortedFromOrganisation']."', '".$data['PortedFromNetwork']."', '".$data['LocationISO']."', NOW())";
//echo $sql;
mysql_query($sql, $phone_ptr);
//print_r($result);
if ($result->IsValidResult->Result != "Success")
{
return false;
}
else
{
return true;
}
}
// function for checking if the number is on TPS
function IsCallable($telephone, $d8username, $d8password)
{
$params = array(
"username" => $d8username,
"password" => $d8password,
"number" => $telephone
);
$client = new SoapClient("http://webservices.data-8.co.uk/TPS.asmx?WSDL");
$result = $client->IsCallable($params);
//var_dump($result);
if ($result->IsCallableResult->Status->Success == 0)
{
//echo "Error: " . $result->IsCallableResult->Status->ErrorMessage;
// didn't get a response so we'll assume it's callable - we'll validate it anyway
return true;
}
else
{
// Results can be extracted from the following fields:
if($result->IsCallableResult->Callable == false)
{
return false;
} else
{
// then it's callable
return true;
}
}
}
// function for validating the phone number with our 3rd party supplier
function validateTelephoneNumber($telephone)
{
global $d8username, $d8password;
// first do the freebie check
if(telephoneNumber($telephone) == false)
{
return false;
} else
{
// now do the data8 check
$match = "/^07[0-9]{9,10}/";
if(preg_match($match, $telephone))
{
// then it's a mobile
if(MobileIsValid($telephone, $d8username, $d8password) != true)
{
return false;
}
} else
{
// then it's a landline
if(LineIsValid($telephone, $d8username, $d8password) != true)
{
return false;
}
}
// if we get to here than we can assume it's valid
return true;
}
}
// todays date
$today = date("Ymd");
// Call the getAge function
if (isset($_POST['birth_date']))
{
$age = getAge($birth_date);
}
//Or fail
else echo'false - no dob provided';
{
}
function getAge($birth_date){
list($year, $month, $day) = explode("-", $birth_date);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0)
{
$month_diff--;
}
if ($month_diff < 0)
{
$year_diff--;
}
return $year_diff;
}
// logs the reuslts
function logResults($values, $logfile){
global $logdir, $time;
// count the values
$num_vals = count($values);
// open the log file
$resfile = fopen($logdir.$logfile, "a");
//write data to the log file
foreach($values as $key => $value){
$value = str_replace("'", "", $value);
$value = trim($value, "\n\r");
$value = ereg_replace("\r", " ", $value);
$value = ereg_replace("\n", " ", $value);
fwrite($resfile, $key." --> ".$value);
fwrite($resfile, ",");
}
fwrite($resfile, $time);
fwrite($resfile, "\n");
// close the log file
fclose($resfile);
}
LineIsValid(($_POST['telephone']), $d8username, $d8password);
MobileIsValid(($_POST['telephone']), $d8username, $d8password);
IsCallable(($_POST['telephone']), $d8username, $d8password);
validateTelephoneNumber(($_POST['telephone']));
$curl = curl_init();
if ( !$curl )
{
print "Failed to initalise cURL object\n";
} else {
$url = "https://v3.lolagrove.com/data.ashx?id=7941.1674&paid_creditors_six_months=Yes&email=".urlencode($email)."&firstname=".urlencode($firstname)."&lastname=".($lastname)."&address1=".urlencode($address1)."&towncity=".urlencode($towncity)."&postcode=".urlencode($postcode)."&telephone=".urlencode($telephone)."&age=".urlencode($age)."&debt_amount=".urlencode($debt_amount)."&debt_with=".urlencode($debt_with)."&disposable_income=".urlencode($disposable_income)."&iva_bankruptcy=".urlencode($iva_bankruptcy)."&securekey=6e5af886-22e5-4f04-b97b-946539aa70f1";
$curl_opts = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_FAILONERROR => true,
);
if ( !curl_setopt_array( $curl, $curl_opts ) )
{
print "Unable to set properties on CURL object\n";
} else
{
$response = curl_exec( $curl );
$responseCode = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
if ( is_bool( $response ) && $response == false )
{
// Failed to make HTTP request to tracking URL
echo 'Error from CURL in livefeed: "', curl_error( $curl ), '" ', var_export( curl_getinfo( $curl ), TRUE );
} else if ( ! ( $responseCode >= 200 && $responseCode <= 299 ) )
{
// We got an HTTP response, but it was not successful
print "Error: Tracking URL returned HTTP $responseCode\n";
} else {
// All good
print "Success, response was:\n";
echo var_export( $response ), "\n";
}
}
}
curl_close( $curl );
// log the values
$values[] = $response;
$values[] = $responseCode;
$values[] = $url;
logResults($values, 'Madison_financial');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.010 0.005 18.05 8.3.5 0.007 0.009 20.96 8.3.4 0.013 0.007 18.55 8.3.3 0.008 0.008 18.92 8.3.2 0.004 0.004 20.21 8.3.1 0.009 0.000 22.26 8.3.0 0.005 0.003 22.52 8.2.18 0.010 0.010 18.23 8.2.17 0.013 0.007 22.96 8.2.16 0.014 0.000 20.35 8.2.15 0.000 0.007 24.18 8.2.14 0.004 0.004 24.66 8.2.13 0.011 0.004 26.16 8.2.12 0.009 0.000 19.54 8.2.11 0.007 0.010 20.64 8.2.10 0.007 0.004 19.32 8.2.9 0.000 0.007 19.05 8.2.8 0.008 0.000 19.38 8.2.7 0.008 0.000 17.25 8.2.6 0.000 0.008 17.90 8.2.5 0.005 0.003 18.07 8.2.4 0.004 0.004 18.03 8.2.3 0.002 0.005 17.98 8.2.2 0.000 0.007 17.48 8.2.1 0.007 0.000 17.63 8.2.0 0.003 0.005 17.45 8.1.28 0.007 0.007 25.92 8.1.27 0.008 0.000 20.19 8.1.26 0.007 0.000 26.35 8.1.25 0.004 0.004 28.09 8.1.24 0.008 0.000 23.97 8.1.23 0.011 0.000 18.99 8.1.22 0.003 0.006 17.74 8.1.21 0.008 0.000 18.77 8.1.20 0.004 0.004 17.13 8.1.19 0.005 0.003 17.28 8.1.18 0.004 0.004 18.62 8.1.17 0.004 0.004 18.52 8.1.16 0.003 0.003 22.19 8.1.15 0.005 0.002 18.41 8.1.14 0.000 0.007 17.25 8.1.13 0.003 0.005 17.73 8.1.12 0.003 0.003 17.43 8.1.11 0.011 0.000 17.32 8.1.10 0.000 0.007 17.41 8.1.9 0.000 0.007 17.31 8.1.8 0.000 0.007 17.24 8.1.7 0.008 0.000 17.25 8.1.6 0.004 0.004 17.39 8.1.5 0.000 0.008 17.32 8.1.4 0.000 0.007 17.43 8.1.3 0.006 0.003 17.41 8.1.2 0.000 0.008 17.47 8.1.1 0.005 0.003 17.40 8.1.0 0.003 0.006 17.43 8.0.30 0.007 0.000 18.77 8.0.29 0.004 0.004 17.16 8.0.28 0.003 0.003 18.39 8.0.27 0.007 0.000 17.21 8.0.26 0.000 0.007 16.78 8.0.25 0.003 0.003 16.85 8.0.24 0.000 0.007 16.84 8.0.23 0.000 0.008 16.82 8.0.22 0.000 0.007 16.70 8.0.21 0.007 0.000 16.76 8.0.20 0.003 0.003 16.87 8.0.19 0.003 0.005 16.89 8.0.18 0.004 0.003 16.69 8.0.17 0.000 0.007 16.73 8.0.16 0.007 0.000 16.80 8.0.15 0.007 0.000 16.69 8.0.14 0.002 0.005 16.64 8.0.13 0.003 0.003 13.33 8.0.12 0.000 0.009 16.66 8.0.11 0.005 0.002 16.74 8.0.10 0.005 0.002 16.75 8.0.9 0.003 0.005 16.73 8.0.8 0.015 0.000 16.77 8.0.7 0.000 0.007 16.79 8.0.6 0.004 0.004 16.75 8.0.5 0.000 0.008 16.79 8.0.3 0.011 0.013 17.13 8.0.2 0.010 0.008 17.40 8.0.1 0.003 0.005 16.89 8.0.0 0.013 0.009 16.60 7.4.33 0.003 0.003 15.00 7.4.32 0.006 0.000 16.48 7.4.30 0.000 0.007 16.38 7.4.29 0.000 0.007 16.50 7.4.28 0.007 0.000 16.40 7.4.27 0.000 0.007 16.50 7.4.26 0.007 0.000 16.38 7.4.25 0.005 0.002 16.35 7.4.24 0.005 0.002 16.33 7.4.23 0.003 0.003 16.54 7.4.22 0.006 0.012 16.36 7.4.21 0.003 0.012 16.44 7.4.20 0.000 0.007 16.61 7.4.19 0.004 0.004 16.35 7.4.16 0.009 0.006 16.29 7.4.15 0.011 0.006 17.40 7.4.14 0.012 0.006 17.86 7.4.13 0.007 0.010 16.44 7.4.12 0.015 0.004 16.45 7.4.11 0.014 0.003 16.53 7.4.10 0.006 0.016 16.49 7.4.9 0.010 0.007 16.39 7.4.8 0.009 0.009 19.39 7.4.7 0.000 0.016 16.25 7.4.6 0.009 0.008 16.44 7.4.5 0.000 0.009 16.25 7.4.4 0.003 0.010 22.77 7.4.3 0.016 0.006 16.39 7.3.33 0.005 0.000 13.22 7.3.32 0.000 0.006 12.89 7.3.31 0.000 0.007 16.23 7.3.30 0.007 0.000 16.14 7.3.29 0.010 0.005 16.18 7.3.28 0.006 0.011 16.15 7.3.27 0.000 0.017 17.40 7.3.26 0.006 0.010 16.20 7.3.25 0.011 0.007 16.34 7.3.24 0.007 0.010 16.03 7.3.23 0.003 0.019 16.44 7.3.21 0.010 0.007 16.04 7.3.20 0.009 0.009 19.39 7.3.19 0.006 0.013 16.23 7.3.18 0.007 0.013 16.10 7.3.17 0.011 0.011 16.38 7.3.16 0.009 0.006 16.19 7.2.33 0.006 0.013 16.45 7.2.32 0.010 0.010 16.32 7.2.31 0.007 0.010 16.33 7.2.30 0.004 0.016 16.22 7.2.29 0.013 0.009 16.46 5.5.9 0.010 0.077 20.15 5.5.8 0.007 0.077 20.25 5.5.7 0.010 0.060 20.05 5.5.6 0.010 0.057 20.23 5.5.5 0.000 0.080 20.14 5.5.4 0.003 0.057 20.23 5.5.3 0.010 0.073 20.23 5.5.2 0.010 0.067 20.08 5.5.1 0.003 0.083 20.12 5.5.0 0.003 0.083 20.00 5.4.25 0.007 0.073 19.02 5.4.24 0.013 0.067 19.12 5.4.23 0.003 0.067 19.06 5.4.22 0.000 0.063 19.24 5.4.21 0.010 0.070 19.15 5.4.20 0.003 0.067 19.13 5.4.19 0.003 0.080 18.89 5.4.18 0.000 0.080 19.12 5.4.17 0.003 0.063 18.91 5.4.16 0.003 0.077 19.21 5.4.15 0.010 0.073 19.03 5.4.14 0.013 0.063 16.53 5.4.13 0.010 0.060 16.49 5.4.12 0.003 0.067 16.34 5.4.11 0.003 0.077 16.58 5.4.10 0.000 0.063 16.49 5.4.9 0.003 0.060 16.56 5.4.8 0.007 0.060 16.52 5.4.7 0.000 0.057 16.52 5.4.6 0.000 0.063 16.48 5.4.5 0.000 0.057 16.39 5.4.4 0.010 0.067 16.51 5.4.3 0.007 0.067 16.38 5.4.2 0.007 0.057 16.47 5.4.1 0.007 0.067 16.50 5.4.0 0.010 0.033 16.34 5.3.29 0.003 0.073 16.34 5.3.28 0.000 0.077 16.34 5.3.27 0.007 0.073 16.34 5.3.26 0.003 0.073 16.34 5.3.25 0.003 0.073 16.34 5.3.24 0.003 0.067 16.34 5.3.23 0.003 0.073 16.34 5.3.22 0.000 0.073 16.34 5.3.21 0.007 0.073 16.34 5.3.20 0.000 0.053 16.34 5.3.19 0.007 0.060 16.34 5.3.18 0.007 0.070 16.34 5.3.17 0.013 0.063 16.34 5.3.16 0.007 0.070 16.34 5.3.15 0.013 0.063 16.34 5.3.14 0.007 0.070 16.34 5.3.13 0.003 0.073 16.34 5.3.12 0.010 0.070 16.34 5.3.11 0.003 0.073 16.34 5.3.10 0.003 0.057 16.34 5.3.9 0.007 0.067 16.34 5.3.8 0.000 0.077 16.34 5.3.7 0.000 0.077 16.34 5.3.6 0.000 0.067 16.34 5.3.5 0.000 0.047 16.34 5.3.4 0.003 0.073 16.34 5.3.3 0.007 0.063 16.34 5.3.2 0.000 0.050 16.34 5.3.1 0.007 0.037 16.34 5.3.0 0.007 0.070 16.34
preferences:dark mode live preview
41.74 ms | 401 KiB | 5 Q