Thursday, August 15, 2013

Redirect URL with out changing the url in address bar using htaccess

Hi. This is a small trick to redirect the URL to another url with out changing the address bar url. We should write the below code in htaccess file.
RewriteEngine on

RewriteRule (.*)\.com$ $1.php [PT]
RewriteRule (.*)\.in$ $1.php [PT]

This will show an URL to user in the address bar,  but internally it will redirect and execute the code of other URL which we configure here.
After adding this to .htaccess file. check this. 

For example if you want to show url as

to user and internally we want to call and execute the code of another page like

then use this sample code in your htaccess file. while executing this, the URL will remain same as in address bar, but redirect and executes the content of mypage.php. 
For applying this transfers only to a folder follow this. Then we should write the below code in htaccess file.

RewriteEngine on

RewriteRule ^pages/(.*)\.com /pages/$1.php [PT]
RewriteRule ^pages/(.*)\.in /pages/$1.php [PT]

You can change the pages to your folder. The above code works only when the user requests a page from pages folder. other wise it will ignore this. is redirected to the page of mypage.php and will execute the content of the mypage.php when user type this url in address bar

Thank you

Monday, July 29, 2013

How to know if the browser is IE in PHP

Hi. This is a small code to check the browser is Internet explorer or not using the PHP.
if(preg_match('/(?i)msie [1-8]/', $_SERVER['HTTP_USER_AGENT']))
   // The browser is IE 
   // write your code here
   // The browser is other than IE
   // write your code here

If you are executing the above code in Internet explorer browser then if condition will execute. and if you are executing the code in other than Internet explorer then else condition will be executed.

Thank you

Friday, July 12, 2013

How to display the previous days date using PHP

Hi to every one. Today am going to give a small code to show the previous day date using the PHP. Just copy and paste the below code into your editor and change the static number to your number.
date('Y/m/d', strtotime('-N days',strtotime(date('Y/m/d'))));

date('Y/m/d') will gives current date.
strtotime(date('Y/m/d')) will convert the current date to UNIX Timestamp.
Here '-' represents the previous days to show. 
Here 'N' is the number to show 'Nth' days ago date from the current date.
'-N days' will gives the previous 'Nth' day date.
strtotime('-N days',strtotime(date('Y/m/d')) will gives the UNIX Timestamp string of previous 'Nth' day date.
date('Y/m/d', strtotime('-N days',strtotime(date('Y/m/d')))) will display the UNIX Timestamp to date format of YYYY/MM/DD.

For example:
Assume that current date is 2013/07/12. and if we want to display 7 days ago date then write the following code.
date('Y/m/d', strtotime('-7 days',strtotime(date('Y/m/d'))));
It will show the last 7 days ago date in the format of 2013/07/05.

Thursday, June 13, 2013

How to navigate forward and back to the pages using JavaScript

Follow the steps to navigate forward and back to the pages using JavaScript.
<script language='JavaScript' type='text/javascript'>
function goBack() {
<input type='button' name='back' value='Go Back' title='Click here to go back' onClick='goBack()'>
When the user click on the button it will go back to last visited page which means previous page.
We can write this code in another way.
<script language='JavaScript' type='text/javascript'>
function goBack() {
This script is also works same as the above script. This is the same as the back button functionality of the browser. Here '-1' represents the previous page.

And we can use this script to load the next URL in in the history list.
<script language='JavaScript' type='text/javascript'>
function goForward() {
<input type='button' name='forward' value='Go Forward' title='Click here to go Forward' onClick='goForward()'>
This is the same as the forward button functionality of the browser.

Thank you...

Wednesday, June 12, 2013

How to do HTTP redirect to a URL using JavaScript

Follow the simple steps to do HTTP redirect to a URL using JavaScript.
<script type='text/javascript'>
forwardUrl(); // calling the function to redirect
function forwardUrl() {
     window.location.href = '';
Change the URL to your url to forward. And call the function to forward.

And we can send the parameters along with the url using this script also.
<script type='text/javascript'>
var value1 = 10;
var value2 = 'testing';
     window.location.href = ''+value1+'&param2='+value2;
This script will forward from current page to requested URL location along with the 2 GET parameters param1 and param2. we can use this 2 parameters where ever we need.
Use $param1 = $_GET['param1'] and $param2 = $_GET['param2'] to get the values in the page1.php.

Thank you...

Friday, April 19, 2013

Navigation menu to show current page link as active - jquery

Hi, now am going to share a small article here, that is how to show current page link as active in navigation  menu using JQuery.
First we need to include JQuery library into the page.
<script src="//"></script>
before that we need to maintain the left menu in separate page and include it the required pages.
assume take a left menu page leftmenu.php
<div id="left_menu_div">
<li id="menuitem1" title="menu item 1"><a href="http://localhost/activemenu/page1.php">Page One</a></li>
<li id="menuitem2" title="menu item 2"><a href="http://localhost/activemenu/page2.php">Page Two</a></li>
<li id="menuitem3" title="menu item 3"><a href="http://localhost/activemenu/page3.php">Page Three</a></li>
<li id="menuitem4" title="menu item 4"><a href="http://localhost/activemenu/page4.php">Page Four</a></li>
then add your css in the page
<style type="text/css">
#left_menu_div ul
 border:0px solid #ccc;

#left_menu_div ul li {
 outline: 0;
 padding: 3px 3px 3px 6px;
 display: block;
 font-weight: bold;
 border: 1px solid #1c252b;
 border-left:5px solid #ee6e28;
 border-radius: 4px;
 -moz-border-radius: 4px;
 -webkit-border-radius: 4px;
 box-shadow: 1px 1px 1px rgba(0,0,0,0.2); /* CSS3 */
 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.2); /* Firefox */
 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.2); /* Safari, Chrome */
#left_menu_div ul li a{

.active {
    background: #0186ba;
 background: -moz-linear-gradient(#04acec,  #0186ba); 
 background: -webkit-gradient(linear, left top, left bottom, from(#04acec), to(#0186ba));
 background: -webkit-linear-gradient(#04acec,  #0186ba);
 background: -o-linear-gradient(#04acec,  #0186ba);
 background: -ms-linear-gradient(#04acec,  #0186ba);
 background: linear-gradient(#04acec,  #0186ba);
 border-radius:0px 3px 3px 0px;
 padding: 3px 0px 3px 5px; 
 margin:-4px -4px -4px -7px;
and finally include this jquery code in the leftmenu page
<script type="text/javascript">
$(document).ready(function() {
  $currenturl = window.location.href;
  $("#left_menu_div ul li a").each(function() {
   $uurl = $(this).attr('href');
   if($(this).attr('href') == $currenturl){

its over... now you can see the active page link in different than all links.

Thank you...

Monday, April 1, 2013

Find the place name using latitude and longitude in PHP with google geocoder

We can find the place name using google geocoder by giving the Latitude and Longitude.

For example we want to get the place name of the latitude: '17.434545' and longitude: '82.124575' we need to pass this values to the google api to get the place details.

Following code explains how to work with that.

function getPlaceName($latitude, $longitude)
   //This below statement is used to send the data to google maps api and get the place
 name in different formats. we need to convert it as required. 

   $output= json_decode($geocode);

   //Here "formatted_address" is used to display the address in a user friendly format.
   echo $output->results[0]->formatted_address;

We can use this function in PHP. when we execute the above method the following output will be displayed.

call the function as
<?php getPlaceName(17.434545, 82.124575); ?>

Output : Andhra Pradesh 533436, India

Thank you.