You can download the PDO for sql server here. Next you would want to add the dll or so into your php.ini. ;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; extension=php_pdo_sqlsrv_74_ts_x64.dll extension=php_sqlsrv_74_ts_x64.dll
Nested for loop break ( multi-level up to 4 layer)
In below example will have 4 arrays and will be nested. Below example will break 2 which means that it will go back to Loop B. In order to go back to Loop A , will be break 3. break 4 will stop the everything, which means it won’t loop anymore $array1 = array(‘1′,’2′,’3′,’4’); $array2 […]
Rerun an array even if the loop will change the array elements
I have this problem where i will need to loop an array but while looping it , i will add elements into array and i need to loop that data as well. Below are an example that you can do so:- $array = array(‘1′,’1.5′,’3′,’5′,’7’); $count = count($array); for($i=0; $i
Netbeans PHP Xdebugger
https://www.codewall.co.uk/debug-php-with-xdebug-on-netbeans/ Highlight all of the information on the page and copy it. Go to the XDebug Wizard tool. Paste the information into the Text Box input on the wizard tool page. Locate and click the ‘Analyse my phpinfo() output’ button. Download the provided module under Instructions Before pasting the below part make sure the ext downloaded is compatible […]
PHP config for max_input_vars
Today i’ve encounter a problem where there are too many inputs and it failed silently. It did not update the database. If you see this in your error log PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini Update your max_input_vars in php.ini . Take note that this will […]
PHP Forking with child process limit
function runProcessor() { $max_fork = 2; $tasks = [ “test1” => “process1”, “test2” => “process2”, “test3” => “process3”, “test4” => “process4”, “test5” => “process5”, “test6” => “process6”, “test7” => “process7”, “test8” => “process8”, “test9” => “process9”, “test10” => “process10”, ]; $pids = array(); $pid_count = 0; foreach ( $tasks as $seq => $task ) { […]
PHP Curl with attachment ( CurlFile)
Sender PHP Code <form method=”post” action=”<?=$_SERVER[“PHP_SELF”] ?>” enctype=”multipart/form-data”> <input name=”file” type=”file” /> <input type=”submit” value=”Upload” /> </form> <?php if(!empty($_FILES)){ $target=”https://juliusgoh.life/tut/attachment-receiver.php”; echo “<pre>”; print_r($_FILES); echo “</pre>”; # http://php.net/manual/en/curlfile.construct.php // Create a CURLFile object / procedural method $cfile = curl_file_create($_FILES[“file”][“tmp_name”],$_FILES[“file”][“type”],$_FILES[“file”][“name”]); // try adding // Create a CURLFile object / oop method #$cfile = new CURLFile(“resource/test.png”,”image/png”,”testpic”); // uncomment […]
PHP Script uses bash command to find file created within mins ago
$dir = “/home/ec2-user/julius/tmp/”; $file_type = “json”; $min = “5”; #Created How Many Min Ago $output = shell_exec(“find $dir -cmin -$min -type f -name ‘*.$file_type'”); $json_file = explode(“\n”,$output); array_pop($json_file); # To remove last \n if(empty($json_file)){exit();} print_r($json_file);
Prevent Direct Calling for PHP scripts, Only Allow Ajax Calling
The Code below is useful to prevent direct calling. #Only Allow Ajax Call if(!($_SERVER[‘HTTP_X_REQUESTED_WITH’] == ‘XMLHttpRequest’ && $_SERVER[‘HTTP_X_REQUESTED_WITH’])) { echo “Access Denied”; exit(); }
PHP Code Injection Prevention
Hi, this would be great if you place @ the very first line of your script. if(isset($_GET)){ foreach ($_GET as $key => $value) { $_GET[$key] = cleanInput(strip_tags(rawurldecode(rawurldecode($value)))); } } if(isset($_POST)){ foreach ($_POST as $key => $value) { $_POST[$key] = cleanInput(strip_tags(rawurldecode(rawurldecode($value)))); } } function cleanInput($input) { $search = array( ‘@@si’, ‘@@si’, ‘@@siU’, ‘@@’ ); $output = […]