what is difference between die and exit in php

Many PHP developers are been asked this question in interview. But many times they are not sure about answer.

There is no difference between die() and exit() function. They both are same and worked same.
Again question is why php keep the both functions if they are same. Both functions are alias of each other function.

Due to API and keeping the backward compatibility both functions are kept.

what is difference between die and exit in php
what is difference between die and exit in php

Here is one more example:

is_int() and is_integer() are also same.

There are quite a few functions in PHP which you can call with more than one name. In some cases there is no preferred name among the multiple ones, is_int() and is_integer() are equally good for example. However there are functions which changed names because of an API cleanup or some other reason and the old names are only kept as aliases for backward compatibility. It is usually a bad idea to use these kind of aliases, as they may be bound to obsolescence or renaming, which will lead to unportable script. This list is provided to help those who want to upgrade their old scripts to newer syntax.

Full list of Aliases function you will find on following URL:
http://php.net/manual/en/aliases.php

How to use sleep and usleep function in PHP

PHP tutorial, explained to use sleep and usleep function in PHP. Sleep is very common method in every language. How sleep function works we need to understand.

use sleep and usleep function in PHP

Sleep function delays the program execution for the given number of seconds.
Usleep delays program execution for the given number of micro seconds.

Following is the php example with sleep function

<?php
echo date('h:i:s') . "<br />";

//stop execution for 30 seconds
sleep(30);

//start again
echo date('h:i:s');

?>

Following is the php example with usleep function

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
echo date('h:i:s') . &quot;&lt;br /&gt;&quot;;

//stop execution for 30 seconds
usleep(30000000);

//start again
echo date('h:i:s');
?>
How to use sleep and usleep function in PHP
How to use sleep and usleep function in PHP

how to add text in footer wordpress

You can add your text before footer area. Using our code you can easily achieve this. In this article I will show you how to add text in footer wordpress. In this article I will show you how to add the text before footer area in wordpress.

how to add text in footer wordpress

how to add text in footer wordpress
how to add text in footer wordpress

First Open your functions.php file from your wordpress theme and use following code in the functions.php


function custom_footer() {
 $content = '</pre>
<div id="custom_footer">this is your custom function or text</div>
<pre>';
 echo $content;
}
add_action('wp_footer', 'custom_footer');

Then open your footer.php file from wordpress theme folder and put following code in footer where you want to show your custom text or function.


<?php wp_footer(); ?>

how detect ie7 or ie8 with php and every language

In daily development we face lot of cross browser issues and sometimes conditional css will never work as excepted. We can detect I7 and I8 browser using every language. Using PHP language I need to use the browser So I written following code.

How to detect ie7 or ie8 with php

We can detect ie7 or ie8 with php and every language. Using PHP language I need to use browser So I written code snippet which is useful for PHP developer.

In this article I will show how to detect IE browser and IE 7 and IE8 using php language.

Following function you can use for detecting the IE browsers.


function detect_ie($navigator_user_agent)
{
 if (stristr($navigator_user_agent, "MSIE"))
 {
 return true;
 } else return false;
}

detect_ie($_SERVER['HTTP_USER_AGENT']);

//detect IE7 browser

function detect_ie7($navigator_user_agent)
{
 if (stristr($navigator_user_agent, "msie 7"))
 {
 return true;
 } else return false;
}

detect_ie7($_SERVER['HTTP_USER_AGENT']);

function detect_ie8($navigator_user_agent)
 {
 if (stristr($navigator_user_agent, "msie 7"))
 {
 return true;
 } else return false;
 }

detect_ie8($_SERVER['HTTP_USER_AGENT']);

How to detect ie7 or ie8 with php
How to detect ie7 or ie8 with php

Solved forgot password is not working with drupal

If your website created in drupal cms the you click on forgot password link. you got the email from your website to reset the password.

When I used drupal functionality I got weird issue with durpal cms. I got the email from website but when I tried to login with url. We solved forgot password is not working with drupal issue.

Solved forgot password is not working with drupal

the email notification doesn’t work for me at all. I did google around for this issue but did not get any solution for this issue.

Then I tired to solve this issue my own and I found the hack to solve this issue.

Go to your drupal installation and open “user.pages.inc” file from following location

Solved forgot password is not working with drupal
Solved forgot password is not working with drupal

File : modules/user/user.pages.inc

Find function called  “user_pass_reset()” in file. You need to modify that function.

Put the following line :
$action = ‘login’;
before if ($action == ‘login’)  line. This code will solve the forgot password and authentication with url issue.

If you want more drupal tutorials than visit here

How to take mysql backup from file system

This method or trick is important when your database crash and you are not able connect to database. Still your will be able to take mysql backup from file system. Many times we fail to restore the mysql dump from command line.

How to take mysql backup from file system

If your mysql server crash. Follow my steps to take mysql backup from file system without database connection.

First go to your filesystem.
Here I am using the fedora OS for this example

In linux go to /var/lib/mysql path

In that folder each folder means separate database.

Copy that all folders to your local machine.
again go to your mysql local installation and paste that folder into your mysql folder.

For in each database folder file you will find following types of files in the folder
db.opt
test.frm
test.MYD
test.MYI

just copy and paste in your system

how to create multi level unique id in mysql

Multi level unique is very important feature in mysql. This feature is present all databases. Using composite unique key we can achieve multilevel uniqueness. In article for create multi level unique id in mysql. Using this composite unique key we can achieve multilevel uniqueness.

create multi level unique id in mysql

create multi level unique id in mysql
create multi level unique id in mysql

Here I am going to give you how to create the composite unique key in mysql.

mysql> alter table `user` add unique `DATE_uuid` (`date`, `uuid`)

how to check indexes on table
mysql> show index from user;
+—————-+————+————+————–+————-+———–+————-+———-+——–+——+————+———+
| Table          | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+—————-+————+————+————–+————-+———–+————-+———-+——–+——+————+———+
| user |          0 | PRIMARY    |            1 | user_id         | A         |           0 |     NULL | NULL   |      | BTREE      |         |
| user |          0 | DATE_uuid |            1 | date        | A         |        NULL |     NULL | NULL   |      | BTREE      |         |
| user |          0 | DATE_uuid |            2 | uuid       | A         |           0 |     NULL | NULL   |      | BTREE      |         |
+—————-+————+————+————–+————-+———–+————-+———-+——–+——+————+———+
3 rows in set (0.01 sec)

mysql>

find duplicate values in an array using php

Many times we need to find duplicate values in an array using php. Using php language this is very easy. For checking the duplicate array value array_unique function is very useful.

There too many array and string functions available in php. PHP itself gives very useful methods for finding the duplicate values from array element.

There are multiple ways to find the duplicate strings. you can use loop and strpos method but using following code snippet, it is very easy to find the duplicate values from an array.

find duplicate values in an array using php

find duplicate values in an array using php
find duplicate values in an array using php

Here I am giving you very simple php example:


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
 $array1 = array("banana","apple","pear","banana");

 if (count(array_unique($array1)) < count($array1))
 echo 'Duplicate entry found in array';
 else
 echo 'No Duplicate values found in array';
 ?>

Output:  Duplicate entry found in array

php check if file exists if not create

Many times we got requirement of check file from specific directory. PHP tutorial for, php check if file exists if not create. Following code will work in all the system like (Mac, Linux and Windows). we given code snippet for checking file exists or not.

php check if file exists if not create
php check if file exists if not create

Using following php code you can check file is present or not in specific directory.


<?php
 $filename = '/var/www/html/test/test.txt';

 if (file_exists($filename)) {
 echo "The file $filename exists";
 } else {
 echo "The file $filename does not exist";
 }

?>

How to check string in string variable using php

PHP tutorial, we will show you how to check string in php variable using php language. This easy very easy using php language. we given code snippet.

Use can use the strpos function for string to search in

<?php
$mystring = 'abc xyz';
$findme&nbsp;&nbsp; = 'abc';
$check_string = strpos($mystring, $findme);


// because the position of 'a' was the 0th (first) character.
if ($check_string === false) {
 echo "The string '$findme' was not found in the string '$mystring'";
} else {
 echo "The string '$findme' was found in the string '$mystring'";
 echo " and exists at position $pos";
}
?>