difference between cookie and session in php

difference between cookie and session in php


cookies are stored in the user's browser,but and sessions are stored in server machine. This difference determines what each is best used for.

A cookie can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie. The trouble is that a user can block cookies or delete them at any time. If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.  

md5 function in php

md5 function in php


 md5() calculates the MD5 hash of a string


syntax of md5


md5(string,raw)


example of md5 function in php


<?php
$str = "Hello";
echo md5($str);
?>



results will be


8b1a9953c4611296a827abf8c47804d7

php substring

php substring

substr() function returns a part of a string.


substr syntax

substr(string,start,length)

example substr

<?php
echo substr("php simple qa",3);


?> 

result will be:php

difference between php explode and implode

difference between php explode and implode

Explode() function breaks a string into an array,but implode function returns a string from the elements of an array.

explode example

<?php
$str = "test explode in php";
print_r (explode(" ",$str));
?>
output will be:
Array
(
[0] => test
[1] => explode
[2] => in
[3] => php
 )
implode example


<?php
$arr = array('hi','hello');
echo implode(" ",$arr);
?>
output will be:
hi hello

array_search() in php

array_search() in php

array_search() search an array for a value and returns the key.

array_slice syntax in php

array_slice syntax in php


array_slice(array,start,length,preserve);



Example of array_slice in php

<?php
$array=array(0=>"hi",1=>"di",2=>"si",3=>"vi");
print_r(array_slice($a,1,2));
?>

Result will be:
Array ( [0] =>hi [1] => di )



difference between array_slice() and array_splice() in php

difference between array_slice() and  array_splice() in php


array_slice returns selected parts of an array but,array_splice removes selected elements from an array and replaces it with new elements.

how can possible change key in php array

how can possible change key in php array


array_change_key_case()

syntax of php array

syntax of php array


array(key => value)


<?php
$a=array("a"=>"Ma","b"=>"ba","c"=>"Ca");
print_r($a);

?>
Results will be 


Array ( [a] => Ma [b] => ba [c] => Ca)

definition of array in php

definition of array in php

array() creates an array, with keys and values. If you skip the keys when you specify an array, an integer key is generated, starting at 0 and increases by 1 for each value.

difference bitween inner join and outer join in mysql

difference in  inner join and outer join in mysql

The INNER JOIN takes data from both tables returns the
specified data exists in both tables. But the OUTER JOIN check both
tables and returns values from the outer table when the criteria mets.
Other major join are LEFT OUTER JOIN, RIGHT OUTER JOIN.

how can initialize the variable in php

how can initialize the variable in php

Actually, Its not mandatory in php. But its recommended to
initialize variable before its usage. In most of the servers the the
error reporting for display notices are disabled. In the case of
servers which enabled error reporting on for notices, its highly
recommended to initialize variable before its usage.

list of mysql tables

list of tables in mysql
Total 5 types of tables we can create

1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM

list of sorting function in php

list of sorting functions in php

asort()
arsort()
ksort()
krsort()
uksort()
sort()
natsort()
rsort()

use of unset in php

use of unset in php


Unset is used for destroys the specified variables.
example:
<?php

function destroy() 
{
global $test;
unset($test);
}

$test = 'hai';
destroy();
echo $test ;
?> 

how can delete image in php

how  can delete image in php


unlink() is a function used for file handling in php,
it will delete the file content.
example:
<?php

$files = "image/log.jpeg";

if (!unlink($files))

{

echo ("Error deleting $files");

}

else

{

echo ("Deleted $files");

}

?>

php function url validity

php function url  validity


function validUrl($url)
{
if(preg_match(“/^((http:|https:)\/\/)[A_Za-z0-9_]*(\.)[a-zA-Z]*[?|&|[a-zA-Z0-9]]*/”,$url))
return 1;
else
return 0;
}

left join in mysql

left join in mysql


select email_address from nem_emails_tbl left join nem_send_tbl on email_id=send_emailid where email_id not in(select send_emailid from nem_send_tbl where send_letter=17)

how can create thumbnail in php

how can create thumbnail in php

<?php

$imagefolder='.';
$thumbsfolder='.';
$pics=directory($imagefolder,"jpg,JPG,JPEG,jpeg,png,PNG");
$pics=ditchtn($pics,"tn_");
if ($pics[0]!="")
{
foreach ($pics as $p)
{
createthumb($p,"tn_".$p,150,150);
}
}

/*
Function ditchtn($arr,$thumbname)
filters out thumbnails
*/
function ditchtn($arr,$thumbname)
{
foreach ($arr as $item)
{
if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;}
}
return $tmparr;
}

/*
Function createthumb($name,$filename,$new_w,$new_h)
creates a resized image
variables:
$name Original filename
$filename Filename of the resized image
$new_w width of resized image
$new_h height of resized image
*/
function createthumb($name,$filename,$new_w,$new_h)
{
$system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}

/*
        Function directory($directory,$filters)
        reads the content of $directory, takes the files that apply to $filter
and returns an array of the filenames.
        You can specify which files to read, for example
        $files = directory(".","jpg,gif");
                gets all jpg and gif files in this directory.
        $files = directory(".","all");
                gets all files.
*/
function directory($dir,$filters)
{
$handle=opendir($dir);
$files=array();
if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
if ($filters != "all")
{
$filters=explode(",",$filters);
while (($file = readdir($handle))!==false)
{
for ($f=0;$f<sizeof($filters);$f++):
$system=explode(".",$file);
if ($system[1] == $filters[$f]){$files[] = $file;}
endfor;
}
}
closedir($handle);
return $files;
}
?>