Wednesday, November 5, 2014
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'];
?>
<?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;
?>
<?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);
?>
<?php
$redirect_page='http://google.com';
$redirect=true;
header('Location: '.$redirect_page);
?>
SERVER Script Variable
SERVER Script Variable:
=>$_SERVER['SCRIPT_NAME'];
=>$_SERVER['HTTP_HOST'];
=>$_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();
?>
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.
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";
}?>
Subscribe to:
Posts (Atom)