3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<? // 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');
Output for 5.5.0 - 5.5.9
Fatal error: Call to undefined function mysql_connect() in /in/qqg8v on line 13
Process exited with code 255.
Output for 5.4.0 - 5.4.25
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /in/qqg8v on line 5 Fatal error: Call to undefined function mysql_connect() in /in/qqg8v on line 13
Process exited with code 255.
Output for 5.3.0 - 5.3.29
<? // 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');