Tuesday, November 25, 2014

md5 function in php

<?php
$string="123";
echo md5($string);
?>

htmlentities function in php

<!DOCTYPE html>
<html>
<body>

<?php
$str = "<© W3Sçh°°¦§>";
echo htmlentities($str);
?>

<p>Converting characters into entities are often used to prevent browsers from using it as an HTML element. This can be especially useful to prevent code from running when users have access to display input on your homepage.</p>

</body>
</html>

Sunday, November 23, 2014

You can altime live cricket

Saturday, November 8, 2014

How to setting time in php

<?php
//format 12 hours time jone
echo date("h: i:s");
//formate 24 hours jone
echo date("H: i:s");
//increase time form present time
$timeset=strtotime("+50 hours");
echo date("H:i:s",$timeset);
?>

How to upper string from lower

<?php
$string_ano="joynob";
$string_to_upper=strtoupper("$string_ano");
echo $string_to_upper;
?>

How to lower string from upper.

<?php
$string="FARIDUL";
$string_to_upper=strtoupper("$string");
echo $string_to_upper;
?>

How to reverse string in php

<?php
$string="FARIDUL";
$string_rev=strrev("$string");
echo $string_rev;
?>

How to use date() function in php

<?php
//backdate
$backdate= strtotime("-1 week");
echo date("d-m-y\n",$backdate);
//next date
$backdate= strtotime("+1 week");
echo date("d-m-y\n",$backdate);
//back 1 year
$backdate= strtotime("-1 year");
echo date("d-m-y\n",$backdate);
//next two week
$backdate= strtotime("+3 years");
echo date("d-m-y\n",$backdate);
?>

How to use explode and implode function


//explode function 

<?php
$string="WWW rootitech com";
$explode=explode(" ",$string);
$mini=2-2;
echo $explode[$mini];
 ?>

//explode and implode function

<?php
$string="www.rootitech.com";
$explode=explode(".",$string);
$implode=implode($explode,"@");
echo $implode;*/
?>

How to show limited content in php

<?php
$string="finch data software";

$mb_substr=mb_substr($string,0,8);
echo $mb_substr;
?>

Thursday, November 6, 2014

How to setting PHP Sessions

Firstly   type this code and save set.php


<?php
session_start();
$_SESSION['username']='faridul';
?>

Secondly type this code and save view.php:

<?php
    session_start();
   
    if(isset($_SESSION['username'])){
        $seevariavle= $_SESSION['username'];
        echo 'Welcome,' .$seevariavle;
   
    }
    else{
        echo "Please log in.";
   
    }
?>

 Result: browsers show ----Welcome faridul.

Thirdly type this code and save unset.php :

<?php
    session_start();   
    unset($_SESSION['username']);
?>

You see result such step: 1.visit view.php then visit unset.php.
finally visit view.php see result "Please log in"

How to use $_GET variable

<?php
    if(isset($_GET['day']) && isset($_GET['date']) && isset($_GET['year'])){
       
        $day=$_GET['day'];
        $date=$_GET['date'];
        $year=$_GET['year'];
   
        if(!empty($day) && !empty ($date) && !empty ($year)){
            echo "ok";
        }
       
        else{
            echo "please fill the field";
        }
    }


?>

<form action ="get_variable.php" method="GET">
    Day: <br /><input type="text" name="day"><br />
    Date: <br /><input type="text" name="date"><br />
    Year: <br /><input type="text" name="year"><br /><br />
    <input type="submit" value="submit">
</form>

Wednesday, November 5, 2014

Top Oldest sports in the World ~ Come First Take News

Top Oldest sports in the World ~ Come First Take News

How to detect visitor's browsers

part 1:
<?php
    $browser= get_browser(null,true);
    print_r ($browser);

?> 

 part2:

<?php
    $browser= get_browser(null,true);
    echo $browser['browser'];

?>

How to get visitor ip address

How to get visitor ip address:

<?php
    $ip_address=$_SERVER['REMOTE_ADDR'];
    echo $ip_address;

?>

Better way to get visitor ip address:

<?php
    $http_client_ip= $_SERVER['HTTP_CLIENT_IP'];
    $http_x_forwared_for=$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote_addr= $_SERVER ['REMOTE_ADDR'];
   
   
    if(! empty ($http_client_ip)){
   
        $ip_address=$http_client_ip;
    }
   
    else if(!empty ($http_x_forwared_for)){
   
        $ip_address=$http_x_forwared_for;
   
    }
   
    else {
        $ip_address=$remote_addr;
    }
   
    echo $ip_address;


?>

Using the Header to force page direct

How to use Header to force page direct:

<?php
    $redirect_page='http://google.com';
    $redirect=true;
   
    header('Location: '.$redirect_page);

?>

SERVER Script Variable

SERVER Script Variable:
=>$_SERVER['SCRIPT_NAME'];
=>$_SERVER['HTTP_HOST'];

Useful function of php

Most useful function of php:

=> rand()   ---------    that is except value randomly not from user.
      Exam:  code
                  <?php
                  $rand= rand();
                   echo $rand;
                     ?>
        output: 21417
=> getrandmax() ------------   that is except maximum value.
<?php ob_start(); ?>
<h1> my page</h1>
<?php
    $redirect_page='http://google.com';
    $redirect=false;
    if($redirect==true){
        header('Location: '.$redirect_page);
    }
  
    ob_end_flush();
?>

strpos function

mixed strpos (string $haystack,mixed $needle [, int $offset = 0])

find the numeric position of the first occurrence of needle in the haystack string.

Parameters:

=> haystack: The string that is searched
=> needle :it is not a string.it is converted to an integer and applied as the ordinal value of a character.
=>offset: if specified,search will start this number of characters counted from the beginning of the string.offset is not negative.   
 

<?php
$string
'abc';$find   'a';$pos strpos($
string$find  );
// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo 
"The string '$find' was not found in the string '$
string'";
} else {
    echo 
"The string '$find' was found in the string '$
string'";
    echo 
" and exists at position $pos";
}
?>