Skip to main content

Programming & Scripting

Programming & Scripting

Password Protect CMS Page

Password Protect CMS Page

to protect any page with a password in an easy way you can add this script to the top of the page

 

<script type="text/javascript">
    var password = 'password123'
    var retVal = prompt("Enter your password : ", "your password here");
    if(retVal !== password)
    {
        location.assign('');
    }
</script>

Sort a multidimensional array in PHP?

the most challenge question in the past was soring a multidimensional arrays in PHP, now lets make it in an easy way

You have your array like this 

 

$array = [];
$array[] = array('name' => 'name1', 'age' => 85);
$array[] = array('name' => 'name2', 'age' => 15);
$array[] = array('name' => 'name3', 'age' => 10);
$array[] = array('name' => 'name4', 'age' => 59);

the easy way is to use these command 

 

Merge text files using PHP code

the easiest and best way is to use the below code

 

<?php

$txt1 = file_get_contents('1.txt');
$txt1 .= "\n" . file_get_contents('2.txt');
$txt1 .= "\n" . file_get_contents('3.txt');

$fp = fopen('newText.txt', 'w');
if(!$fp)
    die('Could not create / open text file for writing.');
if(fwrite($fp, $txt1) === false)
    die('Could not write to text file.');

echo 'Text files have been merged.';

?>

PhpStorm disable auto-save

How to disable auto-save:

  • Go to File > Settings (Ctrl+Alt+S).
  • Go to Appearance & Behavior > System Settings.
  • unchecked: the both fields
    • Save files on frame deactivation
    • Save files automatically if application is idle for x sec.
  • Go to Editor > General > Editor Tabs
  • Put a checkmark on
    • "Mark modified files with asterisk"

Click Apply > OK.

That's it.