How to encrypt/change the name of file when uploading in CI to avoid overwriting

When you are creating a page where the file is uploaded in the form and these files are saved on your server. Sometimes it happens that same name files overwrites the files. To avoid this just add the below line of code.

$config['encrypt_name'] = TRUE;


How to get the full URL of page using PHP

Here is the block of code which will give the full url of the page:

$page_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Using more than one array in loop in PHP

Usually we use foreach loop when there is a need to use only one array. But what if there are more than one array…

Foreach loop works only with a single array. To step through multiple arrays it’s better to use the each() function in a while loop. Have a look at it..

while(($code = each($codes)) && ($name = each($names))) {
echo '<option value="' . $code['value'] . '">' . $name['value'] . '</option>';

each() returns information about the current key and value of the array and increments the internal pointer by one, or returns false if it has reached the end of the array. This code would not be dependent upon the two arrays having identical keys or having the same sort of elements. The loop terminates when one of the two arrays is finished.

Difference between == and === operator in PHP

When you want to compare values in PHP then you can use either == or === operator. But these both operator are not same. It’s good to know the difference between them.

These both operators fall under the category of Comparison Operators. The first operator ‘==’ is known as Equal Operator in PHP and checks for the equal values and the second operator ‘===’ is known as Identical Operator and checks for equal values and it also checks that if both the values are of same variable type or not.

How to remove index.php from url in CodeIgniter

Yes, you can remove the index.php from your url in your CodeIgniter web application.

You just need to add a .htaccess file in your web application folder.

Create a file and give it name .htaccess and save it in the root folder, and then copy the below block of code and paste it in the .htaccess file.

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]


One more change you have to do in your config.php file.

Go to :


and remove index.php from $config[‘index_page’]

All Done. Enjoy!

How to add a line break in SMS Message

Sometimes while sending a SMS, we need to add a new line or a link break in our sms. There are many ways to add a line break. But now every method will work in your case because it depends on how you are sending your SMS.

I Method : 

Add “\r\n” in your SMS.

II Method : 

Add “%0a” in your SMS.

Note : Encode your message with ” ” (double quotes) not ‘ ‘ (single quotes).

Using PHP Array in Javascript

If you have a PHP Array and want to perform some javascript operations by looping the PHP Array, then I recommend you to use PHP foreach loop instead of Javascript forEach loop.

function myfunction() {

<?php foreach($myArray as $val) { ?>


<?php } ?>