@ 2014-02-25T12:17:14Z <?
// 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($telephone, $d8username, $d8password);
MobileIsValid($telephone, $d8username, $d8password);
IsCallable($telephone, $d8username, $d8password);
validateTelephoneNumber($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.011 0.004 18.43 8.3.5 0.012 0.006 17.17 8.3.4 0.007 0.007 18.70 8.3.3 0.012 0.003 18.57 8.3.2 0.003 0.006 18.68 8.3.1 0.003 0.005 20.36 8.3.0 0.006 0.003 19.00 8.2.18 0.009 0.009 18.00 8.2.17 0.017 0.003 22.96 8.2.16 0.011 0.007 18.96 8.2.15 0.004 0.004 24.18 8.2.14 0.007 0.000 24.66 8.2.13 0.007 0.003 26.16 8.2.12 0.004 0.004 19.77 8.2.11 0.007 0.004 21.03 8.2.10 0.004 0.008 17.72 8.2.9 0.000 0.007 19.09 8.2.8 0.000 0.008 17.97 8.2.7 0.003 0.007 17.63 8.2.6 0.004 0.004 17.80 8.2.5 0.003 0.005 18.07 8.2.4 0.004 0.004 18.03 8.2.3 0.006 0.003 17.88 8.2.2 0.000 0.007 17.53 8.2.1 0.000 0.008 17.56 8.2.0 0.000 0.008 17.67 8.1.28 0.013 0.010 25.92 8.1.27 0.007 0.000 23.99 8.1.26 0.004 0.004 26.35 8.1.25 0.005 0.002 28.09 8.1.24 0.003 0.006 22.34 8.1.23 0.004 0.007 20.88 8.1.22 0.003 0.006 18.77 8.1.21 0.008 0.000 18.93 8.1.20 0.006 0.003 17.00 8.1.19 0.004 0.004 17.39 8.1.18 0.004 0.004 18.10 8.1.17 0.003 0.005 18.75 8.1.16 0.004 0.004 18.73 8.1.15 0.005 0.002 18.58 8.1.14 0.007 0.000 17.26 8.1.13 0.000 0.007 17.71 8.1.12 0.004 0.004 17.34 8.1.11 0.003 0.006 17.29 8.1.10 0.004 0.004 17.18 8.1.9 0.000 0.007 17.27 8.1.8 0.004 0.004 17.33 8.1.7 0.000 0.009 17.32 8.1.6 0.004 0.004 17.49 8.1.5 0.003 0.006 17.33 8.1.4 0.000 0.008 17.27 8.1.3 0.008 0.000 17.57 8.1.2 0.000 0.009 17.42 8.1.1 0.004 0.004 17.50 8.1.0 0.004 0.004 17.24 8.0.30 0.003 0.003 19.82 8.0.29 0.004 0.004 16.63 8.0.28 0.003 0.003 18.32 8.0.27 0.000 0.007 16.88 8.0.26 0.003 0.003 18.61 8.0.25 0.004 0.004 16.89 8.0.24 0.000 0.007 16.86 8.0.23 0.006 0.003 16.85 8.0.22 0.005 0.003 16.73 8.0.21 0.003 0.003 16.79 8.0.20 0.000 0.007 16.81 8.0.19 0.000 0.007 16.82 8.0.18 0.005 0.003 16.82 8.0.17 0.006 0.003 16.82 8.0.16 0.000 0.008 16.78 8.0.15 0.006 0.003 16.79 8.0.14 0.000 0.007 16.77 8.0.13 0.003 0.003 13.47 8.0.12 0.004 0.004 16.75 8.0.11 0.000 0.007 16.79 8.0.10 0.002 0.005 16.74 8.0.9 0.007 0.000 16.79 8.0.8 0.013 0.003 16.69 8.0.7 0.004 0.004 16.69 8.0.6 0.000 0.007 16.73 8.0.5 0.000 0.007 16.74 8.0.3 0.007 0.012 17.13 8.0.2 0.012 0.008 17.40 8.0.1 0.000 0.007 16.70 8.0.0 0.012 0.008 16.72 7.4.33 0.002 0.002 13.43 7.4.32 0.000 0.006 16.38 7.4.30 0.000 0.006 16.32 7.4.29 0.003 0.005 16.41 7.4.28 0.006 0.003 16.50 7.4.27 0.003 0.003 16.47 7.4.26 0.006 0.000 13.18 7.4.25 0.007 0.000 16.49 7.4.24 0.003 0.006 16.39 7.4.23 0.000 0.007 16.46 7.4.22 0.011 0.011 16.37 7.4.21 0.003 0.013 16.40 7.4.20 0.007 0.000 16.39 7.4.19 0.000 0.007 16.65 7.4.16 0.007 0.010 16.27 7.4.15 0.007 0.011 17.40 7.4.14 0.014 0.006 17.16 7.4.13 0.013 0.007 16.55 7.4.12 0.006 0.010 16.54 7.4.11 0.009 0.009 16.47 7.4.10 0.013 0.004 16.57 7.4.9 0.007 0.011 16.41 7.4.8 0.006 0.011 19.03 7.4.7 0.014 0.006 16.40 7.4.6 0.004 0.011 16.49 7.4.5 0.002 0.002 16.26 7.4.4 0.006 0.008 22.27 7.4.3 0.003 0.013 16.17 7.3.33 0.000 0.005 13.07 7.3.32 0.003 0.003 13.03 7.3.31 0.003 0.003 16.15 7.3.30 0.003 0.003 16.16 7.3.29 0.008 0.007 16.19 7.3.28 0.009 0.006 16.13 7.3.27 0.008 0.012 17.40 7.3.26 0.007 0.011 18.24 7.3.25 0.011 0.007 16.41 7.3.24 0.012 0.009 16.20 7.3.23 0.006 0.011 16.39 7.3.21 0.013 0.003 16.13 7.3.20 0.010 0.010 19.39 7.3.19 0.012 0.009 16.19 7.3.18 0.008 0.008 16.32 7.3.17 0.009 0.009 16.34 7.3.16 0.012 0.003 16.45 7.2.33 0.014 0.009 16.19 7.2.32 0.012 0.009 16.37 7.2.31 0.011 0.012 16.35 7.2.30 0.009 0.009 16.59 7.2.29 0.012 0.004 16.50 5.5.9 0.012 0.000 13.61 5.5.8 0.009 0.004 13.61 5.5.7 0.008 0.005 13.61 5.5.6 0.005 0.005 13.61 5.5.5 0.008 0.003 13.61 5.5.4 0.003 0.007 13.61 5.5.3 0.000 0.011 13.61 5.5.2 0.003 0.008 13.61 5.5.1 0.003 0.007 13.61 5.5.0 0.009 0.002 13.61 5.4.25 0.006 0.007 13.61 5.4.24 0.003 0.008 13.61 5.4.23 0.008 0.003 13.61 5.4.22 0.007 0.002 13.61 5.4.21 0.005 0.005 13.61 5.4.20 0.006 0.003 13.61 5.4.19 0.009 0.000 13.61 5.4.18 0.010 0.000 13.61 5.4.17 0.007 0.004 13.61 5.4.16 0.003 0.007 13.61 5.4.15 0.006 0.006 13.61 5.4.14 0.005 0.005 13.61 5.4.13 0.005 0.005 13.61 5.4.12 0.006 0.003 13.61 5.4.11 0.006 0.003 13.61 5.4.10 0.006 0.006 13.61 5.4.9 0.009 0.003 13.61 5.4.8 0.004 0.008 13.61 5.4.7 0.000 0.012 13.61 5.4.6 0.003 0.008 13.61 5.4.5 0.004 0.007 13.61 5.4.4 0.000 0.008 13.61 5.4.3 0.003 0.006 13.61 5.4.2 0.011 0.000 13.61 5.4.1 0.010 0.000 13.61 5.4.0 0.006 0.006 13.61 5.3.28 0.000 0.008 13.61 5.3.27 0.004 0.004 13.61 5.3.26 0.007 0.004 13.61 5.3.25 0.004 0.004 13.61 5.3.24 0.002 0.005 13.61 5.3.23 0.009 0.000 13.61 5.3.22 0.006 0.003 13.61 5.3.21 0.000 0.009 13.61 5.3.20 0.007 0.000 13.61 5.3.19 0.005 0.005 13.61 5.3.18 0.000 0.009 13.61 5.3.17 0.005 0.005 13.61 5.3.16 0.000 0.010 13.61 5.3.15 0.000 0.012 13.61 5.3.14 0.008 0.000 13.61 5.3.13 0.003 0.008 13.61 5.3.12 0.005 0.005 13.61 5.3.11 0.008 0.000 13.61 5.3.10 0.005 0.003 13.61 5.3.9 0.006 0.003 13.61 5.3.8 0.003 0.006 13.61 5.3.7 0.003 0.006 13.61 5.3.6 0.003 0.006 13.61 5.3.5 0.003 0.006 13.61 5.3.4 0.006 0.006 13.61 5.3.3 0.004 0.007 13.61 5.3.2 0.004 0.004 13.61 5.3.1 0.006 0.003 13.61 5.3.0 0.005 0.003 13.61
preferences:dark mode live preview
48.46 ms | 401 KiB | 5 Q