PHP Truncate all words longer than and add ellipsis

function truncate_all_long_strings($string, $limit = 10) { return preg_replace("/(\\b\\w{".intval($limit)."})\\w+\\b/", "$1…", $string); } Example usage: echo truncate_all_long_strings("veryyyyyyyyyyyyyyyyyyyyyyyyy long strinnnnnnnnnnnnnnnnnnnnnnngs to testtttttttttttttttttt"); Example output: veryyyyyyy… long strinnnnnn… to testtttttt…

Adsense high CTR attack (click bombing) April 20 2015

From yesterday I noticed a high CTR on Google Adsense dashboard: That is too good to be true and infact it is a click-bombing attack as referred by other sites. Basically, some bad users are using automated spam bots to visit your website to automatically click on Adsense banners, most probably with the intent to […]

Find .PHP files inside a folder and subfolders

Command to find all PHP files inside a folder and subfolders: find uploads/ -type d -exec find {} -name "*.php" \; Command to delete all PHP files found inside a folder and subfolders: find uploads/ -type d -exec find {} -name "*.php" -delete \; Useful when you need to clean a hacked server.

Disable /SILENT and /VERYSILENT uninstall in Inno Setup

Disable the option to silently uninstall your application: function InitializeUninstall(): Boolean; begin // Default to OK result := true;   // If it’s in silent mode, exit if UninstallSilent() then begin MsgBox(‘This setup doesn”t support silent uninstallation.’, mbInformation, MB_OK); result := false; end; end; References: Inno Setup Pascal Scripting: UninstallSilent Disable silent and verysilent uninstall […]

Set directory permissions using Inno Setup

Add this in your Inno Setup script: [Dirs] Name: "{commonappdata}\YourProgramName\LogsFolder\"; Permissions: users-modify; Flags: uninsneveruninstall The desired folder will have write and modify permissions for all users: Standard User Accounts will be able to modify/write to files inside that folder. Other useful links:

Disable USB Autorun in Windows XP Vista 7 8

Create a .reg file with this content: Windows Registry Editor Version 5.00   [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoDriveTypeAutoRun"=dword:000000ff "NoAutorun"=dword:00000001 Save the file somewhere and run it. The reg file will disable autorun on all kinds of drives and for all users. This line disables Autorun on all kinds of drives: "NoDriveTypeAutoRun"=dword:000000ff This line disables the Autorun functionality completely: […]

Grant remote root access to MySQL

Connect via SSH to the MySQL server, login as root to MySQL and type: GRANT ALL ON *.* to root@’%’ IDENTIFIED BY ‘your-root-password’; The above command allows any IP address to connect as root to the MySQL server. To grant root access to a specific IP address (better in terms of security): GRANT ALL ON […]

Access remote MySQL server with local phpMyAdmin

Edit the phpMyAdmin file as this: $cfg[‘Servers’][$i][‘host’] = ‘DB.SERVER.IP.ADDRESS’; $cfg[‘Servers’][$i][‘port’] = ‘3306’; $cfg[‘Servers’][$i][‘socket’] = ”; $cfg[‘Servers’][$i][‘connect_type’] = ‘tcp’; $cfg[‘Servers’][$i][‘extension’] = ‘mysql’; $cfg[‘Servers’][$i][‘compress’] = FALSE; $cfg[‘Servers’][$i][‘auth_type’] = ‘cookie’; Make sure phpMyAdmin’s IP address is allowed to connect to MySQL: Grant remote root access to MySQL

Disable CTRL+ALT+DEL options on Microsoft Windows

You can disable all options in the CTRL+ALT+DEL menu on Microsoft Windows: So the above CTRL+ALT+DEL menu looks like this: To do that, you need to create a .reg file with this content: Windows Registry Editor Version 5.00   [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoLogOff"=dword:00000001   [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableTaskMgr"=dword:00000001 "DisableLockWorkstation"=dword:00000001 "DisableChangePassword"=dword:00000001   [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System] "HideFastUserSwitching"=dword:00000001 "DisableLockWorkstation"=- Save the file as DisableCAD.reg […]

Block user-agents and referrers with Nginx map

The code below must be included inside the http{} block: ## Add here all user agents that are to be blocked. map $http_user_agent $bad_bot { default 0; libwww-perl 1; ~(?i)(httrack|htmlparser|libwww) 1; }   ## Add here all referrers that are to blocked. map $http_referer $bad_referer { default 0; ~(?i)(babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|webcam|zippo|casino|replica) 1; } Then inside the server{} […]